Commit 452c3c3b authored by zhujiashun's avatar zhujiashun

refine obj files

parent 16871a89
......@@ -16,18 +16,18 @@ else()
endif()
option(WITH_GLOG "With glog" OFF)
option(BRPC_DEBUG "With debug symbol" ON)
option(DEBUG "Print debug logs" OFF)
option(WITH_DEBUG_SYMBOLS "With debug symbols" OFF)
option(BUILD_EXAMPLE "Whether building examples" OFF)
option(BUILD_UNIT_TESTS "Whether building unit tests" OFF)
option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)
set(WITH_GLOG_VAL "0")
if(WITH_GLOG)
set(WITH_GLOG_VAL "1")
else()
set(WITH_GLOG_VAL "0")
endif()
if(BRPC_DEBUG)
if(WITH_DEBUG_SYMBOLS)
set(DEBUG_SYMBOL "-g")
endif()
......@@ -272,7 +272,7 @@ set(SOURCES
${BRPC_SOURCES4}
${PROTO_SRCS}
)
ADD_SUBDIRECTORY(src)
if(BUILD_EXAMPLE)
ADD_SUBDIRECTORY(example)
......@@ -281,18 +281,9 @@ if(BUILD_UNIT_TESTS)
ADD_SUBDIRECTORY(test)
endif()
#install directory
# cmake -DCMAKE_INSTALL_PREFIX=/usr
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
if(BUILD_UNIT_TESTS)
return()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNIT_TEST -DBVAR_NOT_LINK_DEFAULT_VARIABLES")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNIT_TEST")
elseif(NOT DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src)
add_library(OBJ_LIB OBJECT ${BUTIL_SOURCES} ${SOURCES})
add_library(BUTIL_LIB OBJECT ${BUTIL_SOURCES})
add_library(OBJ_LIB OBJECT ${SOURCES})
# shared libraries need PIC
set_property(TARGET ${OBJ_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
set_property(TARGET ${BUTIL_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(brpc SHARED $<TARGET_OBJECTS:OBJ_LIB>)
add_library(brpc_static STATIC $<TARGET_OBJECTS:OBJ_LIB>)
add_library(brpc SHARED $<TARGET_OBJECTS:BUTIL_LIB> $<TARGET_OBJECTS:OBJ_LIB>)
add_library(brpc_static STATIC $<TARGET_OBJECTS:BUTIL_LIB> $<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(brpc ${DYNAMIC_LIB})
......
......@@ -141,31 +141,29 @@ SET(TEST_BUTIL_SOURCES
# -DBVAR_NOT_LINK_DEFAULT_VARIABLES not work for gcc >= 5.0, just remove the file to prevent linking into unit tests
set(BVAR_SOURCE ${BVAR_SOURCES1} ${BVAR_SOURCES2})
list(REMOVE_ITEM BVAR_SOURCE ${CMAKE_SOURCE_DIR}/src/bvar/default_variables.cpp)
add_library(BUTIL_DEBUG_LIB OBJECT ${BUTIL_SOURCES})
add_library(OBJ_DEBUG_LIB OBJECT ${SOURCES})
file(GLOB TEST_BVAR_SRCS "bvar_*_unittest.cpp")
add_executable(test_bvar $<TARGET_OBJECTS:BUTIL_DEBUG_LIB>
add_executable(test_bvar $<TARGET_OBJECTS:BUTIL_LIB>
${BVAR_SOURCE}
${TEST_BVAR_SRCS})
target_link_libraries(test_bvar ${GTEST_LIB}
${GPERFTOOLS_LIBRARIES}
${DYNAMIC_LIB})
add_library(PROTO_OBJ OBJECT ${TEST_PROTO_SRCS})
add_library(TEST_PROTO_OBJ OBJECT ${TEST_PROTO_SRCS})
add_executable(test_butil ${TEST_BUTIL_SOURCES}
$<TARGET_OBJECTS:PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_DEBUG_LIB>
$<TARGET_OBJECTS:OBJ_DEBUG_LIB>)
$<TARGET_OBJECTS:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(test_butil ${GTEST_LIB} ${GPERFTOOLS_LIBRARIES} ${DYNAMIC_LIB})
file(GLOB BTHREAD_UNITTESTS "bthread*unittest.cpp")
foreach(BTHREAD_UT ${BTHREAD_UNITTESTS})
get_filename_component(BTHREAD_UT_WE ${BTHREAD_UT} NAME_WE)
add_executable(${BTHREAD_UT_WE} ${BTHREAD_UT}
$<TARGET_OBJECTS:PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_DEBUG_LIB>
$<TARGET_OBJECTS:OBJ_DEBUG_LIB>)
$<TARGET_OBJECTS:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(${BTHREAD_UT_WE}
${GTEST_MAIN_LIB}
${GTEST_LIB}
......@@ -177,9 +175,9 @@ file(GLOB BRPC_UNITTESTS "brpc_*_unittest.cpp")
foreach(BRPC_UT ${BRPC_UNITTESTS})
get_filename_component(BRPC_UT_WE ${BRPC_UT} NAME_WE)
add_executable(${BRPC_UT_WE} ${BRPC_UT}
$<TARGET_OBJECTS:PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_DEBUG_LIB>
$<TARGET_OBJECTS:OBJ_DEBUG_LIB>)
$<TARGET_OBJECTS:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(${BRPC_UT_WE}
${GTEST_MAIN_LIB}
${GPERFTOOLS_LIBRARIES}
......
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