Commit 9b6b004f authored by zhujiashun's avatar zhujiashun

make brpc sources compiled once

parent 6aa9661b
......@@ -56,7 +56,7 @@ include_directories(
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
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} -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 -D__STRICT_ANSI__")
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")
set(CMAKE_C_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-unused-parameter -fno-omit-frame-pointer")
......
......@@ -184,8 +184,13 @@ set(SOURCES
${PROTO_SRCS}
)
add_library(brpc SHARED ${SOURCES})
add_library(brpc_static STATIC ${SOURCES})
add_library(OBJ_LIB OBJECT ${SOURCES})
# shared libraries need PIC
set_property(TARGET ${OBJ_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(brpc SHARED $<TARGET_OBJECTS:OBJ_LIB>)
add_library(brpc_static STATIC $<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(brpc
${GFLAGS_LIBRARY}
......
......@@ -267,19 +267,20 @@ target_link_libraries(test_bvar
z
)
add_executable(test_butil ${TEST_BUTIL_SOURCES} ${PROTO_SRCS})
add_library(PROTO_OBJ OBJECT ${PROTO_SRCS})
add_executable(test_butil ${TEST_BUTIL_SOURCES} $<TARGET_OBJECTS:PROTO_OBJ>)
target_link_libraries(test_butil brpc ${GTEST_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} ${PROTO_SRCS})
add_executable(${BTHREAD_UT_WE} ${BTHREAD_UT} $<TARGET_OBJECTS:PROTO_OBJ>)
target_link_libraries(${BTHREAD_UT_WE} brpc ${GTEST_MAIN_LIB} ${GPERFTOOLS_LIBRARIES} ${GTEST_LIB})
endforeach()
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} ${PROTO_SRCS})
add_executable(${BRPC_UT_WE} ${BRPC_UT} $<TARGET_OBJECTS:PROTO_OBJ>)
target_link_libraries(${BRPC_UT_WE} brpc ${GTEST_MAIN_LIB} ${GPERFTOOLS_LIBRARIES} ${GTEST_LIB})
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