Unverified Commit 7808b12c authored by Ge Jun's avatar Ge Jun Committed by GitHub

Merge pull request #154 from brpc/cmake_support

Cmake support
parents 3308d335 d71fb5e3
......@@ -21,3 +21,13 @@
# Ignore auto-generated files
config.mk
src/butil/config.h
# Ignore CMake files
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
This diff is collapsed.
......@@ -19,7 +19,25 @@ fi
if [ "$PURPOSE" = "compile" ]; then
make -j4 && sh tools/make_all_examples
elif [ "$PURPOSE" = "unittest" ]; then
cd test && sh ./run_tests.sh
cd test && make -j4 && sh ./run_tests.sh && cd ../
else
echo "Unknown purpose=\"$PURPOSE\""
fi
echo "start building by cmake"
rm -rf build && mkdir build && cd build
if [ "$PURPOSE" = "compile" ]; then
if ! cmake -DBRPC_DEBUG=OFF -DBUILD_EXAMPLE=OFF -DBUILD_UNIT_TESTS=OFF ..; then
echo "Fail to generate Makefile by cmake"
exit 1
fi
make -j4
elif [ "$PURPOSE" = "unittest" ]; then
if ! cmake -DBRPC_DEBUG=OFF -DBUILD_EXAMPLE=OFF -DBUILD_UNIT_TESTS=ON ..; then
echo "Fail to generate Makefile by cmake"
exit 1
fi
make -j4 && cd test && sh ./run_tests.sh && cd ../
else
echo "Unknown purpose=\"$PURPOSE\""
fi
set(_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
find_path(GFLAGS_INCLUDE_PATH gflags/gflags.h)
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)
message(FATAL_ERROR "Could not find gflags library.")
endif(GFLAGS_FIND_REQUIRED)
endif(GFLAGS_FOUND)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
# Tries to find Gperftools.
#
# Usage of this module as follows:
#
# find_package(Gperftools)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# Gperftools_ROOT_DIR Set this variable to the root installation of
# Gperftools if the module has problems finding
# the proper installation path.
#
# Variables defined by this module:
#
# GPERFTOOLS_FOUND System has Gperftools libs/headers
# GPERFTOOLS_LIBRARIES The Gperftools libraries (tcmalloc & profiler)
# GPERFTOOLS_INCLUDE_DIR The location of Gperftools headers
find_library(GPERFTOOLS_TCMALLOC
NAMES tcmalloc
HINTS ${Gperftools_ROOT_DIR}/lib)
find_library(GPERFTOOLS_PROFILER
NAMES profiler
HINTS ${Gperftools_ROOT_DIR}/lib)
find_library(GPERFTOOLS_TCMALLOC_AND_PROFILER
NAMES tcmalloc_and_profiler
HINTS ${Gperftools_ROOT_DIR}/lib)
find_path(GPERFTOOLS_INCLUDE_DIR
NAMES gperftools/heap-profiler.h
HINTS ${Gperftools_ROOT_DIR}/include)
set(GPERFTOOLS_LIBRARIES ${GPERFTOOLS_TCMALLOC_AND_PROFILER})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Gperftools
DEFAULT_MSG
GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)
mark_as_advanced(
Gperftools_ROOT_DIR
GPERFTOOLS_TCMALLOC
GPERFTOOLS_PROFILER
GPERFTOOLS_TCMALLOC_AND_PROFILER
GPERFTOOLS_LIBRARIES
GPERFTOOLS_INCLUDE_DIR)
#ifndef BUTIL_CONFIG_H
#define BUTIL_CONFIG_H
#cmakedefine BRPC_WITH_GLOG @WITH_GLOG_VAL@
#endif // BUTIL_CONFIG_H
if(BUILD_UNIT_TESTS)
return()
endif()
find_package(Gperftools)
include_directories(${GPERFTOOLS_INCLUDE_DIR})
add_subdirectory(http_c++)
add_subdirectory(asynchronous_echo_c++)
add_subdirectory(backup_request_c++)
add_subdirectory(cancel_c++)
add_subdirectory(cascade_echo_c++)
add_subdirectory(dynamic_partition_echo_c++)
add_subdirectory(echo_c++)
add_subdirectory(echo_c++_hulu_pbrpc)
add_subdirectory(echo_c++_sofa_pbrpc)
add_subdirectory(echo_c++_ubrpc_compack)
add_subdirectory(memcache_c++)
add_subdirectory(multi_threaded_echo_c++)
add_subdirectory(multi_threaded_echo_fns_c++)
add_subdirectory(multi_threaded_mcpack_c++)
add_subdirectory(nshead_extension_c++)
add_subdirectory(nshead_pb_extension_c++)
add_subdirectory(parallel_echo_c++)
add_subdirectory(partition_echo_c++)
# need readline library
# add_subdirectory(redis_c++)
add_subdirectory(selective_echo_c++)
add_subdirectory(session_data_and_thread_local)
add_subdirectory(streaming_echo_c++)
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(asynchronous_echo_client client.cpp ${PROTO_SRC})
add_executable(asynchronous_echo_server server.cpp ${PROTO_SRC})
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(backup_request_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(backup_request_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(cancel_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(cancel_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(cascade_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(cascade_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(dynamic_partition_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(dynamic_partition_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(dynamic_partition_echo_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(dynamic_partition_echo_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(dynamic_partition_echo_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(dynamic_partition_echo_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(echo_client brpc)
target_link_libraries(echo_server brpc)
else()
target_link_libraries(echo_client brpc_static ${DYNAMIC_LIB})
target_link_libraries(echo_server brpc_static ${DYNAMIC_LIB})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(echo_hulu_pbrpc_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(echo_hulu_pbrpc_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(echo_sofa_pbrpc_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(echo_sofa_pbrpc_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(
CUSTOM_PROTO ALL
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}/example/echo_c++_ubrpc_compack/ --plugin=protoc-gen-mcpack=${CMAKE_CURRENT_BINARY_DIR}/../../src/protoc-gen-mcpack --mcpack_out=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/example/echo_c++_ubrpc_compack/echo.proto
DEPENDS protoc-gen-mcpack
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc PROPERTIES GENERATED TRUE)
add_executable(echo_ubrpc_compack_client client.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
add_executable(echo_ubrpc_compack_server server.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
add_dependencies(echo_ubrpc_compack_client CUSTOM_PROTO)
add_dependencies(echo_ubrpc_compack_server CUSTOM_PROTO)
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER http.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(http_client http_client.cpp)
add_executable(http_server http_server.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(benchmark_http benchmark_http.cpp)
if(EXAMPLE_LINK_SO)
target_link_libraries(http_server brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(http_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(benchmark_http brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(http_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(http_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(benchmark_http brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
add_executable(memcache_client client.cpp)
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
if(EXAMPLE_LINK_SO)
target_link_libraries(memcache_client brpc)
else()
target_link_libraries(memcache_client brpc_static ${DYNAMIC_LIB})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(multi_threaded_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(multi_threaded_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(multi_threaded_echo_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(multi_threaded_echo_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(multi_threaded_echo_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(multi_threaded_echo_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(multi_threaded_echo_fns_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(multi_threaded_echo_fns_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(multi_threaded_echo_fns_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(multi_threaded_echo_fns_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(multi_threaded_echo_fns_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(multi_threaded_echo_fns_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(
CUSTOM_PROTO_MULTI_THREAD ALL
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}/example/multi_threaded_mcpack_c++ --plugin=protoc-gen-mcpack=${CMAKE_CURRENT_BINARY_DIR}/../../src/protoc-gen-mcpack --mcpack_out=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/example/multi_threaded_mcpack_c++/echo.proto
DEPENDS protoc-gen-mcpack
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc PROPERTIES GENERATED TRUE)
add_executable(multi_threaded_mcpack_client client.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
add_executable(multi_threaded_mcpack_server server.cpp ${CMAKE_CURRENT_BINARY_DIR}/echo.pb.cc)
add_dependencies(multi_threaded_mcpack_client CUSTOM_PROTO_MULTI_THREAD)
add_dependencies(multi_threaded_mcpack_server CUSTOM_PROTO_MULTI_THREAD)
if(EXAMPLE_LINK_SO)
target_link_libraries(multi_threaded_mcpack_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(multi_threaded_mcpack_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(multi_threaded_mcpack_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(multi_threaded_mcpack_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
add_executable(nshead_extension_client client.cpp)
add_executable(nshead_extension_server server.cpp)
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(nshead_pb_extension_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(nshead_pb_extension_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(parallel_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(parallel_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(parallel_echo_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(parallel_echo_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(parallel_echo_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(parallel_echo_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if (EXAMPLE_LINK_SO)
target_link_libraries(client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
add_executable(redis_cli redis_cli.cpp)
add_executable(redis_press redis_press.cpp)
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(AUX_LIB readline ncurses)
if(EXAMPLE_LINK_SO)
target_link_libraries(redis_cli brpc ${AUX_LIB})
target_link_libraries(redis_press brpc ${AUX_LIB})
else()
target_link_libraries(redis_cli brpc_static ${DYNAMIC_LIB} ${AUX_LIB})
target_link_libraries(redis_press brpc_static ${DYNAMIC_LIB} ${AUX_LIB})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(selective_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(selective_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(selective_echo_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(selective_echo_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(selective_echo_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(selective_echo_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBRPC_ENABLE_CPU_PROFILER")
add_executable(session_data_and_thread_local_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(session_data_and_thread_local_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
if(EXAMPLE_LINK_SO)
target_link_libraries(session_data_and_thread_local_client brpc ${GPERFTOOLS_LIBRARIES})
target_link_libraries(session_data_and_thread_local_server brpc ${GPERFTOOLS_LIBRARIES})
else()
target_link_libraries(session_data_and_thread_local_client brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
target_link_libraries(session_data_and_thread_local_server brpc_static ${DYNAMIC_LIB} ${GPERFTOOLS_LIBRARIES})
endif()
protobuf_generate_cpp(PROTO_SRC PROTO_HEADER echo.proto)
get_filename_component(HEADER_DIR ${PROTO_HEADER} DIRECTORY)
include_directories(${HEADER_DIR})
set(CMAKE_CPP_FLAGS "-DBRPC_WITH_GLOG=${WITH_GLOG_VAL} -DGFLAGS_NS=${GFLAGS_NS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer")
add_executable(streaming_echo_client client.cpp ${PROTO_SRC} ${PROTO_HEADER})
add_executable(streaming_echo_server server.cpp ${PROTO_SRC} ${PROTO_HEADER})
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()
if(BUILD_UNIT_TESTS)
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(BUTIL_LIB OBJECT ${BUTIL_SOURCES})
add_library(OBJ_LIB OBJECT ${SOURCES})
# shared library needs POSITION_INDEPENDENT_CODE
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: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})
if(WITH_GLOG)
target_link_libraries(brpc ${GLOG_LIB})
endif()
set(protoc_gen_mcpack_SOURCES
${CMAKE_SOURCE_DIR}/src/mcpack2pb/generator.cpp
)
add_executable(protoc-gen-mcpack ${protoc_gen_mcpack_SOURCES})
target_link_libraries(protoc-gen-mcpack brpc)
get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if ("${LIB64}" STREQUAL "TRUE")
set(LIBSUFFIX 64)
else()
set(LIBSUFFIX "")
endif()
#install directory
# cmake -DCMAKE_INSTALL_PREFIX=/usr
install(TARGETS brpc
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIBSUFFIX}
ARCHIVE DESTINATION lib${LIBSUFFIX}
)
install(TARGETS brpc_static
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIBSUFFIX}
ARCHIVE DESTINATION lib${LIBSUFFIX}
)
find_package(Gperftools)
include_directories(${GPERFTOOLS_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
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 TEST_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_path=${CMAKE_SOURCE_DIR}/test ${PROTO}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach()
find_path(GTEST_HEADER NAMES gtest/gtest.h)
find_library(GTEST_LIB NAMES gtest)
find_library(GTEST_MAIN_LIB NAMES gtest_main)
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 -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES -include ${CMAKE_SOURCE_DIR}/test/sstream_workaround.h")
set(CMAKE_CXX_FLAGS "${CMAKE_CPP_FLAGS} -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
#required by butil/crc32.cc to boost performance for 10x
if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4 -msse4.2")
endif()
if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aligned-new")
endif()
endif()
file(COPY ${CMAKE_SOURCE_DIR}/test/cert1.key DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/test/cert2.key DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/test/cert1.crt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/test/cert2.crt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/test/jsonout DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_SOURCE_DIR}/test/run_tests.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
SET(TEST_BUTIL_SOURCES
${CMAKE_SOURCE_DIR}/test/popen_unittest.cpp
${CMAKE_SOURCE_DIR}/test/at_exit_unittest.cc
${CMAKE_SOURCE_DIR}/test/atomicops_unittest.cc
${CMAKE_SOURCE_DIR}/test/base64_unittest.cc
${CMAKE_SOURCE_DIR}/test/big_endian_unittest.cc
${CMAKE_SOURCE_DIR}/test/bits_unittest.cc
${CMAKE_SOURCE_DIR}/test/hash_tables_unittest.cc
${CMAKE_SOURCE_DIR}/test/linked_list_unittest.cc
${CMAKE_SOURCE_DIR}/test/mru_cache_unittest.cc
${CMAKE_SOURCE_DIR}/test/small_map_unittest.cc
${CMAKE_SOURCE_DIR}/test/stack_container_unittest.cc
${CMAKE_SOURCE_DIR}/test/cpu_unittest.cc
${CMAKE_SOURCE_DIR}/test/crash_logging_unittest.cc
${CMAKE_SOURCE_DIR}/test/leak_tracker_unittest.cc
${CMAKE_SOURCE_DIR}/test/proc_maps_linux_unittest.cc
${CMAKE_SOURCE_DIR}/test/stack_trace_unittest.cc
${CMAKE_SOURCE_DIR}/test/environment_unittest.cc
${CMAKE_SOURCE_DIR}/test/file_util_unittest.cc
${CMAKE_SOURCE_DIR}/test/dir_reader_posix_unittest.cc
${CMAKE_SOURCE_DIR}/test/file_path_unittest.cc
${CMAKE_SOURCE_DIR}/test/file_unittest.cc
${CMAKE_SOURCE_DIR}/test/scoped_temp_dir_unittest.cc
${CMAKE_SOURCE_DIR}/test/guid_unittest.cc
${CMAKE_SOURCE_DIR}/test/hash_unittest.cc
${CMAKE_SOURCE_DIR}/test/lazy_instance_unittest.cc
${CMAKE_SOURCE_DIR}/test/md5_unittest.cc
${CMAKE_SOURCE_DIR}/test/aligned_memory_unittest.cc
${CMAKE_SOURCE_DIR}/test/linked_ptr_unittest.cc
${CMAKE_SOURCE_DIR}/test/ref_counted_memory_unittest.cc
${CMAKE_SOURCE_DIR}/test/ref_counted_unittest.cc
${CMAKE_SOURCE_DIR}/test/scoped_ptr_unittest.cc
${CMAKE_SOURCE_DIR}/test/scoped_vector_unittest.cc
${CMAKE_SOURCE_DIR}/test/singleton_unittest.cc
${CMAKE_SOURCE_DIR}/test/weak_ptr_unittest.cc
${CMAKE_SOURCE_DIR}/test/observer_list_unittest.cc
${CMAKE_SOURCE_DIR}/test/file_descriptor_shuffle_unittest.cc
${CMAKE_SOURCE_DIR}/test/rand_util_unittest.cc
${CMAKE_SOURCE_DIR}/test/safe_numerics_unittest.cc
${CMAKE_SOURCE_DIR}/test/scoped_clear_errno_unittest.cc
${CMAKE_SOURCE_DIR}/test/scoped_generic_unittest.cc
${CMAKE_SOURCE_DIR}/test/security_unittest.cc
${CMAKE_SOURCE_DIR}/test/sha1_unittest.cc
${CMAKE_SOURCE_DIR}/test/stl_util_unittest.cc
${CMAKE_SOURCE_DIR}/test/nullable_string16_unittest.cc
${CMAKE_SOURCE_DIR}/test/safe_sprintf_unittest.cc
${CMAKE_SOURCE_DIR}/test/string16_unittest.cc
${CMAKE_SOURCE_DIR}/test/stringprintf_unittest.cc
${CMAKE_SOURCE_DIR}/test/string_number_conversions_unittest.cc
${CMAKE_SOURCE_DIR}/test/string_piece_unittest.cc
${CMAKE_SOURCE_DIR}/test/string_split_unittest.cc
${CMAKE_SOURCE_DIR}/test/string_tokenizer_unittest.cc
${CMAKE_SOURCE_DIR}/test/string_util_unittest.cc
${CMAKE_SOURCE_DIR}/test/stringize_macros_unittest.cc
${CMAKE_SOURCE_DIR}/test/sys_string_conversions_unittest.cc
${CMAKE_SOURCE_DIR}/test/utf_offset_string_conversions_unittest.cc
${CMAKE_SOURCE_DIR}/test/utf_string_conversions_unittest.cc
${CMAKE_SOURCE_DIR}/test/cancellation_flag_unittest.cc
${CMAKE_SOURCE_DIR}/test/condition_variable_unittest.cc
${CMAKE_SOURCE_DIR}/test/lock_unittest.cc
${CMAKE_SOURCE_DIR}/test/waitable_event_unittest.cc
${CMAKE_SOURCE_DIR}/test/type_traits_unittest.cc
${CMAKE_SOURCE_DIR}/test/non_thread_safe_unittest.cc
${CMAKE_SOURCE_DIR}/test/platform_thread_unittest.cc
${CMAKE_SOURCE_DIR}/test/simple_thread_unittest.cc
${CMAKE_SOURCE_DIR}/test/thread_checker_unittest.cc
${CMAKE_SOURCE_DIR}/test/thread_collision_warner_unittest.cc
${CMAKE_SOURCE_DIR}/test/thread_id_name_manager_unittest.cc
${CMAKE_SOURCE_DIR}/test/thread_local_storage_unittest.cc
${CMAKE_SOURCE_DIR}/test/thread_local_unittest.cc
${CMAKE_SOURCE_DIR}/test/watchdog_unittest.cc
${CMAKE_SOURCE_DIR}/test/pr_time_unittest.cc
${CMAKE_SOURCE_DIR}/test/time_unittest.cc
${CMAKE_SOURCE_DIR}/test/version_unittest.cc
${CMAKE_SOURCE_DIR}/test/logging_unittest.cc
${CMAKE_SOURCE_DIR}/test/cacheline_unittest.cpp
${CMAKE_SOURCE_DIR}/test/class_name_unittest.cpp
${CMAKE_SOURCE_DIR}/test/endpoint_unittest.cpp
${CMAKE_SOURCE_DIR}/test/unique_ptr_unittest.cpp
${CMAKE_SOURCE_DIR}/test/errno_unittest.cpp
${CMAKE_SOURCE_DIR}/test/fd_guard_unittest.cpp
${CMAKE_SOURCE_DIR}/test/file_watcher_unittest.cpp
${CMAKE_SOURCE_DIR}/test/find_cstr_unittest.cpp
${CMAKE_SOURCE_DIR}/test/scoped_lock_unittest.cpp
${CMAKE_SOURCE_DIR}/test/status_unittest.cpp
${CMAKE_SOURCE_DIR}/test/string_printf_unittest.cpp
${CMAKE_SOURCE_DIR}/test/string_splitter_unittest.cpp
${CMAKE_SOURCE_DIR}/test/synchronous_event_unittest.cpp
${CMAKE_SOURCE_DIR}/test/temp_file_unittest.cpp
${CMAKE_SOURCE_DIR}/test/baidu_thread_local_unittest.cpp
${CMAKE_SOURCE_DIR}/test/baidu_time_unittest.cpp
${CMAKE_SOURCE_DIR}/test/flat_map_unittest.cpp
${CMAKE_SOURCE_DIR}/test/crc32c_unittest.cc
${CMAKE_SOURCE_DIR}/test/iobuf_unittest.cpp
${CMAKE_SOURCE_DIR}/test/test_switches.cc
${CMAKE_SOURCE_DIR}/test/scoped_locale.cc
${CMAKE_SOURCE_DIR}/test/test_file_util_linux.cc
${CMAKE_SOURCE_DIR}/test/butil_unittest_main.cpp
${CMAKE_SOURCE_DIR}/test/butil_unittest_main.cpp
)
# -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_SOURCES} ${BVAR_DETAIL_SOURCES})
list(REMOVE_ITEM BVAR_SOURCE ${CMAKE_SOURCE_DIR}/src/bvar/default_variables.cpp)
file(GLOB TEST_BVAR_SRCS "bvar_*_unittest.cpp")
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(TEST_PROTO_OBJ OBJECT ${TEST_PROTO_SRCS})
add_executable(test_butil ${TEST_BUTIL_SOURCES}
$<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:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(${BTHREAD_UT_WE}
${GTEST_MAIN_LIB}
${GTEST_LIB}
${GPERFTOOLS_LIBRARIES}
${DYNAMIC_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}
$<TARGET_OBJECTS:TEST_PROTO_OBJ>
$<TARGET_OBJECTS:BUTIL_LIB>
$<TARGET_OBJECTS:OBJ_LIB>)
target_link_libraries(${BRPC_UT_WE}
${GTEST_MAIN_LIB}
${GPERFTOOLS_LIBRARIES}
${GTEST_LIB}
${DYNAMIC_LIB})
endforeach()
......@@ -28,7 +28,7 @@ TEST(PopenTest, posix_popen) {
oss.str("");
rc = butil::read_command_output_through_popen(oss, "exit 1");
EXPECT_EQ(1, rc) << berror(errno);
ASSERT_TRUE(oss.str().empty()) << oss;
ASSERT_TRUE(oss.str().empty()) << oss.str();
oss.str("");
rc = butil::read_command_output_through_popen(oss, "kill -9 $$");
ASSERT_EQ(-1, rc);
......@@ -59,7 +59,7 @@ TEST(PopenTest, clone) {
oss.str("");
rc = butil::read_command_output_through_clone(oss, "exit 1");
ASSERT_EQ(1, rc) << berror(errno);
ASSERT_TRUE(oss.str().empty()) << oss;
ASSERT_TRUE(oss.str().empty()) << oss.str();
oss.str("");
rc = butil::read_command_output_through_clone(oss, "kill -9 $$");
ASSERT_EQ(-1, rc);
......
......@@ -2,7 +2,6 @@
test_num=0
failed_test=""
rc=0
make -j4
test_bins="test_butil test_bvar bthread*unittest brpc*unittest"
for test_bin in $test_bins; do
test_num=$((test_num + 1))
......
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