Commit d070457c authored by zhujiashun's avatar zhujiashun

separate_cmake_debug_and_release_obj: done

parent 14303060
cmake_minimum_required(VERSION 2.8.10) cmake_minimum_required(VERSION 2.8.10)
project(brpc C CXX) project(brpc C CXX)
option(WITH_GLOG "With glog" OFF)
option(DEBUG "Print debug logs" OFF)
option(WITH_DEBUG_SYMBOLS "With debug symbols" ON)
option(WITH_THRIFT "With thrift framed protocol supported" OFF)
option(BUILD_UNIT_TESTS "Whether to build unit tests" OFF)
option(DOWNLOAD_GTEST "Download and build a fresh copy of \
googletest. Requires Internet access." ON)
# Enable MACOSX_RPATH. Run "cmake --help-policy CMP0042" for policy details. # Enable MACOSX_RPATH. Run "cmake --help-policy CMP0042" for policy details.
if(POLICY CMP0042) if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0042 NEW)
...@@ -26,12 +34,6 @@ else() ...@@ -26,12 +34,6 @@ else()
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.") message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif() endif()
option(WITH_GLOG "With glog" OFF)
option(DEBUG "Print debug logs" OFF)
option(WITH_DEBUG_SYMBOLS "With debug symbols" ON)
option(WITH_THRIFT "With thrift framed protocol supported" OFF)
option(BUILD_UNIT_TESTS "Whether to build unit tests" OFF)
set(WITH_GLOG_VAL "0") set(WITH_GLOG_VAL "0")
if(WITH_GLOG) if(WITH_GLOG)
set(WITH_GLOG_VAL "1") set(WITH_GLOG_VAL "1")
...@@ -166,8 +168,7 @@ set(DYNAMIC_LIB ...@@ -166,8 +168,7 @@ set(DYNAMIC_LIB
${OPENSSL_LIBRARIES} ${OPENSSL_LIBRARIES}
${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}
dl dl
z z)
)
set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz") set(BRPC_PRIVATE_LIBS "-lgflags -lprotobuf -lleveldb -lprotoc -lssl -lcrypto -ldl -lz")
if(WITH_GLOG) if(WITH_GLOG)
...@@ -197,7 +198,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/lib) ...@@ -197,7 +198,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/lib)
# for *.a # for *.a
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/output/lib)
# list all source files # the reason why not using file(GLOB_RECURSE...) is that we want to
# include different files on different platforms.
set(BUTIL_SOURCES set(BUTIL_SOURCES
${PROJECT_SOURCE_DIR}/src/butil/third_party/dmg_fp/g_fmt.cc ${PROJECT_SOURCE_DIR}/src/butil/third_party/dmg_fp/g_fmt.cc
${PROJECT_SOURCE_DIR}/src/butil/third_party/dmg_fp/dtoa_wrapper.cc ${PROJECT_SOURCE_DIR}/src/butil/third_party/dmg_fp/dtoa_wrapper.cc
...@@ -351,8 +353,7 @@ set(MCPACK2PB_SOURCES ...@@ -351,8 +353,7 @@ set(MCPACK2PB_SOURCES
${PROJECT_SOURCE_DIR}/src/mcpack2pb/field_type.cpp ${PROJECT_SOURCE_DIR}/src/mcpack2pb/field_type.cpp
${PROJECT_SOURCE_DIR}/src/mcpack2pb/mcpack2pb.cpp ${PROJECT_SOURCE_DIR}/src/mcpack2pb/mcpack2pb.cpp
${PROJECT_SOURCE_DIR}/src/mcpack2pb/parser.cpp ${PROJECT_SOURCE_DIR}/src/mcpack2pb/parser.cpp
${PROJECT_SOURCE_DIR}/src/mcpack2pb/serializer.cpp ${PROJECT_SOURCE_DIR}/src/mcpack2pb/serializer.cpp)
)
include(CompileProto) include(CompileProto)
set(PROTO_FILES idl_options.proto set(PROTO_FILES idl_options.proto
......
...@@ -24,10 +24,9 @@ compile_proto(PROTO_HDRS PROTO_SRCS ${CMAKE_BINARY_DIR}/test ...@@ -24,10 +24,9 @@ compile_proto(PROTO_HDRS PROTO_SRCS ${CMAKE_BINARY_DIR}/test
"${TEST_PROTO_FILES}") "${TEST_PROTO_FILES}")
add_library(TEST_PROTO_LIB OBJECT ${PROTO_SRCS} ${PROTO_HDRS}) add_library(TEST_PROTO_LIB OBJECT ${PROTO_SRCS} ${PROTO_HDRS})
option(BRPC_DOWNLOAD_GTEST "Download and build a fresh copy of googletest. Requires Internet access." ON)
set(BRPC_SYSTEM_GTEST_SOURCE_DIR "" CACHE PATH "System googletest source directory.") set(BRPC_SYSTEM_GTEST_SOURCE_DIR "" CACHE PATH "System googletest source directory.")
if(BRPC_DOWNLOAD_GTEST) if(DOWNLOAD_GTEST)
include(SetupGtest) include(SetupGtest)
elseif(BRPC_SYSTEM_GTEST_SOURCE_DIR) elseif(BRPC_SYSTEM_GTEST_SOURCE_DIR)
add_subdirectory("${BRPC_SYSTEM_GTEST_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/system-googletest-build") add_subdirectory("${BRPC_SYSTEM_GTEST_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/system-googletest-build")
...@@ -172,52 +171,67 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") ...@@ -172,52 +171,67 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
"-Wl,-U,_bthread_key_create") "-Wl,-U,_bthread_key_create")
endif() endif()
# create executable add_library(BUTIL_DEBUG_LIB OBJECT ${BUTIL_SOURCES})
add_library(SOURCES_DEBUG_LIB OBJECT ${SOURCES})
# shared library needs POSITION_INDEPENDENT_CODE
set_property(TARGET ${BUTIL_DEBUG_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
set_property(TARGET ${SOURCES_DEBUG_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(brpc-shared-debug SHARED $<TARGET_OBJECTS:BUTIL_DEBUG_LIB>
$<TARGET_OBJECTS:SOURCES_DEBUG_LIB>
$<TARGET_OBJECTS:PROTO_LIB>)
# change the debug lib output dir to be different from the release output
set_target_properties(brpc-shared-debug PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/test)
target_link_libraries(brpc-shared-debug ${DYNAMIC_LIB})
if(BRPC_WITH_GLOG)
target_link_libraries(brpc-shared-debug ${GLOG_LIB})
endif()
# test_butil
add_executable(test_butil ${TEST_BUTIL_SOURCES} add_executable(test_butil ${TEST_BUTIL_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/iobuf.pb.cc) ${CMAKE_CURRENT_BINARY_DIR}/iobuf.pb.cc)
target_link_libraries(test_butil brpc-shared target_link_libraries(test_butil brpc-shared-debug
gtest gtest
${GPERFTOOLS_LIBRARIES} ${GPERFTOOLS_LIBRARIES})
${DYNAMIC_LIB})
add_test(NAME test_butil COMMAND test_butil) add_test(NAME test_butil COMMAND test_butil)
# test_bvar
# -DBVAR_NOT_LINK_DEFAULT_VARIABLES not work for gcc >= 5.0, just remove the file to prevent linking into unit tests # -DBVAR_NOT_LINK_DEFAULT_VARIABLES not work for gcc >= 5.0, just remove the file to prevent linking into unit tests
list(REMOVE_ITEM BVAR_SOURCES ${PROJECT_SOURCE_DIR}/src/bvar/default_variables.cpp) list(REMOVE_ITEM BVAR_SOURCES ${PROJECT_SOURCE_DIR}/src/bvar/default_variables.cpp)
add_library(BVAR_OBJ OBJECT ${BVAR_SOURCES}) add_library(BVAR_DEBUG_LIB OBJECT ${BVAR_SOURCES})
file(GLOB TEST_BVAR_SRCS "bvar_*_unittest.cpp") file(GLOB TEST_BVAR_SRCS "bvar_*_unittest.cpp")
add_executable(test_bvar ${TEST_BVAR_SRCS} $<TARGET_OBJECTS:BVAR_OBJ> $<TARGET_OBJECTS:BUTIL_LIB>) add_executable(test_bvar ${TEST_BVAR_SRCS}
$<TARGET_OBJECTS:BVAR_DEBUG_LIB>
$<TARGET_OBJECTS:BUTIL_DEBUG_LIB>)
target_link_libraries(test_bvar gtest target_link_libraries(test_bvar gtest
${GPERFTOOLS_LIBRARIES} ${GPERFTOOLS_LIBRARIES}
${DYNAMIC_LIB}) ${DYNAMIC_LIB})
add_test(NAME test_bvar COMMAND test_bvar) add_test(NAME test_bvar COMMAND test_bvar)
add_library(BTHREAD_OBJ OBJECT ${BTHREAD_SOURCES}) # bthread tests
add_library(PROTO_OBJ OBJECT ${PROTO_SRCS})
file(GLOB BTHREAD_UNITTESTS "bthread*unittest.cpp") file(GLOB BTHREAD_UNITTESTS "bthread*unittest.cpp")
foreach(BTHREAD_UT ${BTHREAD_UNITTESTS}) foreach(BTHREAD_UT ${BTHREAD_UNITTESTS})
get_filename_component(BTHREAD_UT_WE ${BTHREAD_UT} NAME_WE) get_filename_component(BTHREAD_UT_WE ${BTHREAD_UT} NAME_WE)
add_executable(${BTHREAD_UT_WE} ${BTHREAD_UT} add_executable(${BTHREAD_UT_WE} ${BTHREAD_UT}
$<TARGET_OBJECTS:BUTIL_LIB> $<TARGET_OBJECTS:TEST_PROTO_LIB>)
$<TARGET_OBJECTS:BVAR_OBJ>
$<TARGET_OBJECTS:BTHREAD_OBJ>
$<TARGET_OBJECTS:PROTO_LIB>
$<TARGET_OBJECTS:TEST_PROTO_LIB>
)
target_link_libraries(${BTHREAD_UT_WE} gtest_main target_link_libraries(${BTHREAD_UT_WE} gtest_main
${GPERFTOOLS_LIBRARIES} brpc-shared-debug
${DYNAMIC_LIB}) ${GPERFTOOLS_LIBRARIES})
add_test(NAME ${BTHREAD_UT_WE} COMMAND ${BTHREAD_UT_WE}) add_test(NAME ${BTHREAD_UT_WE} COMMAND ${BTHREAD_UT_WE})
endforeach() endforeach()
# brpc tests
file(GLOB BRPC_UNITTESTS "brpc_*_unittest.cpp") file(GLOB BRPC_UNITTESTS "brpc_*_unittest.cpp")
foreach(BRPC_UT ${BRPC_UNITTESTS}) foreach(BRPC_UT ${BRPC_UNITTESTS})
get_filename_component(BRPC_UT_WE ${BRPC_UT} NAME_WE) get_filename_component(BRPC_UT_WE ${BRPC_UT} NAME_WE)
add_executable(${BRPC_UT_WE} ${BRPC_UT} $<TARGET_OBJECTS:TEST_PROTO_LIB>) add_executable(${BRPC_UT_WE} ${BRPC_UT} $<TARGET_OBJECTS:TEST_PROTO_LIB>)
target_link_libraries(${BRPC_UT_WE} brpc-shared target_link_libraries(${BRPC_UT_WE} brpc-shared-debug
gtest_main gtest_main
${GPERFTOOLS_LIBRARIES} ${GPERFTOOLS_LIBRARIES})
${GTEST_LIB}
${DYNAMIC_LIB})
add_test(NAME ${BRPC_UT_WE} COMMAND ${BRPC_UT_WE}) add_test(NAME ${BRPC_UT_WE} COMMAND ${BRPC_UT_WE})
endforeach() endforeach()
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