Commit 5a170fe5 authored by zhujiashun's avatar zhujiashun

add flag EXAMPLE_LINK_SO

parent 5ee9c85b
......@@ -19,6 +19,7 @@ option(WITH_GLOG "With glog" OFF)
option(BRPC_DEBUG "With debug symbol" ON)
option(BUILD_EXAMPLE "Whether building examples" ON)
option(BUILD_UNIT_TESTS "Whether building unit tests" OFF)
option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)
if(WITH_GLOG)
set(WITH_GLOG_VAL "1")
......@@ -91,6 +92,18 @@ include_directories(
${LEVELDB_HEADER}
)
set(DYNAMIC_LIB
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${PROTOC_LIB}
rt
ssl
crypto
dl
z
)
# for *.so
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# for *.a
......
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(asynchronous_echo_client client.cpp ${PROTO_SRC})
target_link_libraries(asynchronous_echo_client brpc)
add_executable(asynchronous_echo_server server.cpp ${PROTO_SRC})
target_link_libraries(asynchronous_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(asynchronous_echo_client brpc)
target_link_libraries(asynchronous_echo_server brpc)
else()
target_link_libraries(asynchronous_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(asynchronous_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(backup_request_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(backup_request_client brpc)
add_executable(backup_request_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(backup_request_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(backup_request_client brpc)
target_link_libraries(backup_request_server brpc)
else()
target_link_libraries(backup_request_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(backup_request_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(cancel_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(cancel_client brpc)
add_executable(cancel_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(cancel_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(cancel_client brpc)
target_link_libraries(cancel_server brpc)
else()
target_link_libraries(cancel_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(cancel_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(cascade_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(cascade_echo_client brpc)
add_executable(cascade_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(cascade_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(cascade_echo_client brpc)
target_link_libraries(cascade_echo_server brpc)
else()
target_link_libraries(cascade_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(cascade_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(dynamic_partition_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(dynamic_partition_echo_client brpc)
add_executable(dynamic_partition_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(dynamic_partition_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(dynamic_partition_echo_client brpc)
target_link_libraries(dynamic_partition_echo_server brpc)
else()
target_link_libraries(dynamic_partition_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(dynamic_partition_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,14 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(echo_client brpc)
add_executable(echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(echo_server brpc)
if(EXAMPLE_LINK_SO)
message("EXAMPLE_LINK_SO")
target_link_libraries(echo_client brpc)
target_link_libraries(echo_server brpc)
else()
message("not EXAMPLE_LINK_SO")
target_link_libraries(echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(echo_hulu_pbrpc_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(echo_hulu_pbrpc_client brpc)
add_executable(echo_hulu_pbrpc_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(echo_hulu_pbrpc_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(echo_hulu_pbrpc_client brpc)
target_link_libraries(echo_hulu_pbrpc_server brpc)
else()
target_link_libraries(echo_hulu_pbrpc_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(echo_hulu_pbrpc_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(echo_sofa_pbrpc_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(echo_sofa_pbrpc_client brpc)
add_executable(echo_sofa_pbrpc_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(echo_sofa_pbrpc_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(echo_sofa_pbrpc_client brpc)
target_link_libraries(echo_sofa_pbrpc_server brpc)
else()
target_link_libraries(echo_sofa_pbrpc_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(echo_sofa_pbrpc_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -5,8 +5,13 @@ execute_process(
)
add_executable(echo_ubrpc_compack_client client.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
target_link_libraries(echo_ubrpc_compack_client brpc)
add_executable(echo_ubrpc_compack_server server.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
target_link_libraries(echo_ubrpc_compack_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(echo_ubrpc_compack_client brpc)
target_link_libraries(echo_ubrpc_compack_server brpc)
else()
target_link_libraries(echo_ubrpc_compack_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(echo_ubrpc_compack_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,10 +3,15 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(http_client http_client.cpp)
target_link_libraries(http_client brpc)
add_executable(http_server http_server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(http_server brpc)
add_executable(benchmark_http benchmark_http.cpp)
target_link_libraries(benchmark_http brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(http_server brpc)
target_link_libraries(http_client brpc)
target_link_libraries(benchmark_http brpc)
else()
target_link_libraries(http_server brpc_static ${DYNAMIC_LIB})
target_link_libraries(http_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(benchmark_http brpc_static ${DYNAMIC_LIB})
endif()
add_executable(memcache_client client.cpp)
target_link_libraries(memcache_client brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(memcache_client brpc)
else()
target_link_libraries(memcache_client brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(multi_threaded_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(multi_threaded_echo_client brpc)
add_executable(multi_threaded_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(multi_threaded_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(multi_threaded_echo_client brpc)
target_link_libraries(multi_threaded_echo_server brpc)
else()
target_link_libraries(multi_threaded_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(multi_threaded_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(multi_threaded_echo_fns_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(multi_threaded_echo_fns_client brpc)
add_executable(multi_threaded_echo_fns_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(multi_threaded_echo_fns_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(multi_threaded_echo_fns_client brpc)
target_link_libraries(multi_threaded_echo_fns_server brpc)
else()
target_link_libraries(multi_threaded_echo_fns_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(multi_threaded_echo_fns_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -5,7 +5,12 @@ execute_process(
)
add_executable(multi_threaded_mcpack_client client.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
target_link_libraries(multi_threaded_mcpack_client brpc)
add_executable(multi_threaded_mcpack_server server.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
target_link_libraries(multi_threaded_mcpack_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(multi_threaded_mcpack_client brpc)
target_link_libraries(multi_threaded_mcpack_server brpc)
else()
target_link_libraries(multi_threaded_mcpack_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(multi_threaded_mcpack_server brpc_static ${DYNAMIC_LIB})
endif()
add_executable(nshead_extension_client client.cpp)
target_link_libraries(nshead_extension_client brpc)
add_executable(nshead_extension_server server.cpp)
target_link_libraries(nshead_extension_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(nshead_extension_client brpc)
target_link_libraries(nshead_extension_server brpc)
else()
target_link_libraries(nshead_extension_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(nshead_extension_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(nshead_pb_extension_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(nshead_pb_extension_client brpc)
add_executable(nshead_pb_extension_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(nshead_pb_extension_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(nshead_pb_extension_client brpc)
target_link_libraries(nshead_pb_extension_server brpc)
else()
target_link_libraries(nshead_pb_extension_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(nshead_pb_extension_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(parallel_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(parallel_echo_client brpc)
add_executable(parallel_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(parallel_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(parallel_echo_client brpc)
target_link_libraries(parallel_echo_server brpc)
else()
target_link_libraries(parallel_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(parallel_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(client brpc)
add_executable(server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(server brpc)
if (EXAMPLE_LINK_SO)
target_link_libraries(client brpc)
target_link_libraries(server brpc)
else()
target_link_libraries(client brpc_static ${DYNAMIC_LIB})
target_link_libraries(server brpc_static ${DYNAMIC_LIB})
endif()
add_executable(redis_cli redis_cli.cpp)
target_link_libraries(redis_cli brpc)
add_executable(redis_press redis_press.cpp)
target_link_libraries(redis_press brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(redis_cli brpc)
target_link_libraries(redis_press brpc)
else()
target_link_libraries(redis_cli brpc_static ${DYNAMIC_LIB})
target_link_libraries(redis_press brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(selective_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(selective_echo_client brpc)
add_executable(selective_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(selective_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(selective_echo_client brpc)
target_link_libraries(selective_echo_server brpc)
else()
target_link_libraries(selective_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(selective_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(session_data_and_thread_local_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(session_data_and_thread_local_client brpc)
add_executable(session_data_and_thread_local_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(session_data_and_thread_local_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(session_data_and_thread_local_client brpc)
target_link_libraries(session_data_and_thread_local_server brpc)
else()
target_link_libraries(session_data_and_thread_local_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(session_data_and_thread_local_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -3,7 +3,12 @@ get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
add_executable(streaming_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(streaming_echo_client brpc)
add_executable(streaming_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
target_link_libraries(streaming_echo_server brpc)
if(EXAMPLE_LINK_SO)
target_link_libraries(streaming_echo_client brpc)
target_link_libraries(streaming_echo_server brpc)
else()
target_link_libraries(streaming_echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(streaming_echo_server brpc_static ${DYNAMIC_LIB})
endif()
......@@ -193,17 +193,7 @@ set_property(TARGET ${BUTIL_LIB} PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(brpc SHARED $<TARGET_OBJECTS:OBJ_LIB> $<TARGET_OBJECTS:BUTIL_LIB>)
add_library(brpc_static STATIC $<TARGET_OBJECTS:OBJ_LIB> $<TARGET_OBJECTS:BUTIL_LIB>)
target_link_libraries(brpc
${GFLAGS_LIBRARY}
${PROTOBUF_LIBRARIES}
${LEVELDB_LIB}
${PROTOC_LIB}
rt
ssl
crypto
dl
z
)
target_link_libraries(brpc ${DYNAMIC_LIB})
if(WITH_GLOG)
target_link_libraries(brpc ${GLOG_LIB})
......
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