Commit 3b167cb5 authored by zhujiashun's avatar zhujiashun

add some options & misc changes

parent 26e1625a
......@@ -6,26 +6,33 @@ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
endif()
option(WITH_GLOG "With glog" OFF)
option(BRPC_DEBUG "With debug symbol" ON)
option(BUILD_EXAMPLE "Whether building examples" OFF)
if(WITH_GLOG)
set(WITH_GLOG_VAL "1")
else()
set(WITH_GLOG_VAL "0")
endif()
if(BRPC_DEBUG)
set(DEBUG_SYMBOL "-g")
endif()
configure_file(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_SOURCE_DIR}/src/butil/config.h @ONLY)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(Gflags REQUIRED)
find_package(GFLAGS REQUIRED)
execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${Gflags_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}'"
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}'"
OUTPUT_VARIABLE GFLAGS_NS
)
# STREQUAL not works. Use MATCHES as workaround
if(${GFLAGS_NS} MATCHES ".*GFLAGS_NAMESPACE.*")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${Gflags_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d \"\\n\""
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d \"\\n\""
OUTPUT_VARIABLE GFLAGS_NS
)
endif()
......@@ -36,36 +43,33 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}/src
)
set(DEBUG_SYMBOLS "-g")
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEBUG_SYMBOLS}")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} ${DEBUG_SYMBOL}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -std=c++0x")
set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-unused-parameter -fno-omit-frame-pointer")
#required by butil/crc32.cc to boost performance for 10x
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4 -msse4.2")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aligned-new")
endif()
find_package(Threads REQUIRED)
find_path(GFLAGS_HEADER NAMES gflags/gflags.h PATHS $ENV{GFLAGS_HEADER_PATH})
find_library(GFLAGS_LIB NAMES gflags PATHS $ENV{GFLAGS_LIB_PATH})
#find_path(GFLAGS_HEADER NAMES gflags/gflags.h)
#find_library(GFLAGS_LIB NAMES gflags)
#find_package(gflags REQUIRED)
#protobuf 3.2
find_path(PROTOBUF_HEADER NAMES google/protobuf/stubs/common.h PATHS $ENV{PB_HEADER_PATH})
find_library(PROTOBUF_LIB NAMES protobuf PATHS $ENV{PB_LIB_PATH})
find_path(PROTOBUF_HEADER NAMES google/protobuf/stubs/common.h)
find_library(PROTOBUF_LIB NAMES protobuf)
find_path(LEVELDB_HEADER NAMES leveldb/db.h PATHS $ENV{LEVELDB_HEADER_PATH})
find_library(LEVELDB_LIB NAMES leveldb PATHS $ENV{LEVELDB_LIB_PATH})
find_path(LEVELDB_HEADER NAMES leveldb/db.h)
find_library(LEVELDB_LIB NAMES leveldb)
if(WITH_GLOG)
find_path(GLOG_HEADER NAMES glog/logging.h)
......@@ -73,11 +77,10 @@ if(WITH_GLOG)
include_directories(${GLOG_HEADER})
endif()
#protobuf 3.2
find_library(PROTOC_LIB NAMES protoc PATHS $ENV{PB_LIB_PATH})
find_library(PROTOC_LIB NAMES protoc)
include_directories(
${GFLAGS_HEADER}
${GFLAGS_INCLUDE_PATH}
${PROTOBUF_HEADER}
${LEVELDB_HEADER}
${THREAD_HEADER}
......@@ -89,4 +92,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(example)
if(BUILD_EXAMPLE)
ADD_SUBDIRECTORY(example)
endif()
......@@ -23,3 +23,13 @@ elif [ "$PURPOSE" = "unittest" ]; then
else
echo "Unknown purpose=\"$PURPOSE\""
fi
echo "start building by cmake"
rm -rf build && mkdir build && cd build
if ! cmake -DBRPC_DEBUG=OFF -BUILD_EXAMPLE=ON ..; then
echo "Fail to generate Makefile by cmake"
exit 1
fi
#todo: add test
set(_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_path(Gflags_INCLUDE_PATH gflags/gflags.h)
find_path(GFLAGS_INCLUDE_PATH gflags/gflags.h)
if (Gflags_STATIC)
if (GFLAGS_STATIC)
if (WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
else (WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif (WIN32)
endif (Gflags_STATIC)
find_library(Gflags_LIBRARY NAMES gflags libgflags)
if(Gflags_INCLUDE_PATH AND Gflags_LIBRARY)
set(Gflags_FOUND TRUE)
endif(Gflags_INCLUDE_PATH AND Gflags_LIBRARY)
if(Gflags_FOUND)
if(NOT Gflags_FIND_QUIETLY)
message(STATUS "Found gflags: ${Gflags_LIBRARY}")
endif(NOT Gflags_FIND_QUIETLY)
else(Gflags_FOUND)
if(Gflags_FIND_REQUIRED)
endif (GFLAGS_STATIC)
find_library(GFLAGS_LIBRARY NAMES gflags libgflags)
if(GFLAGS_INCLUDE_PATH AND GFLAGS_LIBRARY)
set(GFLAGS_FOUND TRUE)
endif(GFLAGS_INCLUDE_PATH AND GFLAGS_LIBRARY)
if(GFLAGS_FOUND)
if(NOT GFLAGS_FIND_QUIETLY)
message(STATUS "Found gflags: ${GFLAGS_LIBRARY}")
endif(NOT GFLAGS_FIND_QUIETLY)
else(GFLAGS_FOUND)
if(GFLAGS_FIND_REQUIRED)
message(FATAL_ERROR "Could not find gflags library.")
endif(Gflags_FIND_REQUIRED)
endif(Gflags_FOUND)
endif(GFLAGS_FIND_REQUIRED)
endif(GFLAGS_FOUND)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
project(lib)
include(FindProtobuf)
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIR})
......@@ -7,9 +5,7 @@ file(GLOB PROTOS "*.proto")
list(APPEND PROTO_FLAGS -I${CMAKE_CURRENT_BINARY_DIR})
foreach(PROTO ${PROTOS})
get_filename_component(PROTO_WE ${PROTO} NAME_WE)
list(APPEND PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/${PROTO_WE}.pb.cc")
execute_process(
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ${PROTO_FLAGS} --cpp_out=${CMAKE_CURRENT_BINARY_DIR} --proto_path=${PROTOBUF_INCLUDE_DIR} --proto_path=${CMAKE_SOURCE_DIR}/src ${PROTO}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
......@@ -19,9 +15,7 @@ endforeach()
file(GLOB brpc_PROTOS "brpc/*.proto")
foreach(PROTO ${brpc_PROTOS})
get_filename_component(PROTO_WE ${PROTO} NAME_WE)
list(APPEND PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/brpc/${PROTO_WE}.pb.cc")
execute_process(
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ${PROTO_FLAGS} --cpp_out=${CMAKE_CURRENT_BINARY_DIR} --proto_path=${PROTOBUF_INCLUDE_DIR} --proto_path=${CMAKE_SOURCE_DIR}/src --proto_path=${CMAKE_SOURCE_DIR}/src/brpc/ ${PROTO}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
......@@ -197,7 +191,8 @@ add_library(brpc_static STATIC ${SOURCES})
target_link_libraries(brpc
${CMAKE_THREAD_LIBS_INIT}
${GFLAGS_LIB}
#${GFLAGS_LIB}
${GFLAGS_LIBRARY}
${PROTOBUF_LIB}
${LEVELDB_LIB}
rt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment