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
cmake_minimum_required(VERSION 2.8.10)
project(brpc C CXX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# require at least gcc 4.8
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "GCC is too old, please install a newer version supporting C++11")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# require at least clang 3.3
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
message(FATAL_ERROR "Clang is too old, please install a newer version supporting C++11")
endif()
else()
message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif()
option(WITH_GLOG "With glog" OFF)
option(DEBUG "Print debug logs" OFF)
option(WITH_DEBUG_SYMBOLS "With debug symbols" OFF)
option(BUILD_EXAMPLE "Whether to build examples" OFF)
option(BUILD_UNIT_TESTS "Whether to build 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")
endif()
if(WITH_DEBUG_SYMBOLS)
set(DEBUG_SYMBOL "-g")
endif()
configure_file(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_SOURCE_DIR}/src/butil/config.h @ONLY)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(GFLAGS REQUIRED)
execute_process(
COMMAND bash -c "grep \"namespace [_A-Za-z0-9]\\+ {\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $2}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
if(${GFLAGS_NS} STREQUAL "GFLAGS_NAMESPACE")
execute_process(
COMMAND bash -c "grep \"#define GFLAGS_NAMESPACE [_A-Za-z0-9]\\+\" ${GFLAGS_INCLUDE_PATH}/gflags/gflags_declare.h | head -1 | awk '{print $3}' | tr -d '\n'"
OUTPUT_VARIABLE GFLAGS_NS
)
endif()
include_directories(
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/example
${CMAKE_CURRENT_BINARY_DIR}
)
execute_process(
COMMAND bash -c "git rev-parse --short HEAD | tr -d '\n'"
OUTPUT_VARIABLE BRPC_REVISION
)
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 -DBRPC_REVISION=\\\"${BRPC_REVISION}\\\" -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")
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()
include(FindProtobuf)
find_path(LEVELDB_HEADER NAMES leveldb/db.h)
find_library(LEVELDB_LIB NAMES leveldb)
if(WITH_GLOG)
find_path(GLOG_HEADER NAMES glog/logging.h)
find_library(GLOG_LIB NAMES glog)
include_directories(${GLOG_HEADER})
endif()
find_library(PROTOC_LIB NAMES protoc)
include_directories(
${GFLAGS_INCLUDE_PATH}
${PROTOBUF_INCLUDE_DIRS}
${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
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
file(GLOB PROTOS "${CMAKE_SOURCE_DIR}/src/*.proto")
list(APPEND PROTO_FLAGS -I${CMAKE_CURRENT_BINARY_DIR})
foreach(PROTO ${PROTOS})
get_filename_component(PROTO_WE ${PROTO} NAME_WE)
list(APPEND 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}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach()
file(GLOB BRPC_PROTOS "${CMAKE_SOURCE_DIR}/src/brpc/*.proto")
file(GLOB BRPC_POLICY_PROTOS "${CMAKE_SOURCE_DIR}/src/brpc/policy/*.proto")
# list all source files
set(BUTIL_SOURCES
${CMAKE_SOURCE_DIR}/src/butil/third_party/dmg_fp/g_fmt.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/dmg_fp/dtoa_wrapper.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/dynamic_annotations/dynamic_annotations.c
${CMAKE_SOURCE_DIR}/src/butil/third_party/icu/icu_utf.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/superfasthash/superfasthash.c
${CMAKE_SOURCE_DIR}/src/butil/third_party/modp_b64/modp_b64.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/nspr/prtime.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/symbolize/demangle.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/symbolize/symbolize.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/snappy/snappy-sinksource.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/snappy/snappy-stubs-internal.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/snappy/snappy.cc
${CMAKE_SOURCE_DIR}/src/butil/third_party/murmurhash3/murmurhash3.cpp
${CMAKE_SOURCE_DIR}/src/butil/arena.cpp
${CMAKE_SOURCE_DIR}/src/butil/at_exit.cc
${CMAKE_SOURCE_DIR}/src/butil/atomicops_internals_x86_gcc.cc
${CMAKE_SOURCE_DIR}/src/butil/base64.cc
${CMAKE_SOURCE_DIR}/src/butil/big_endian.cc
${CMAKE_SOURCE_DIR}/src/butil/cpu.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/alias.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/asan_invalid_access.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/crash_logging.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/debugger.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/debugger_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/dump_without_crashing.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/proc_maps_linux.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/stack_trace.cc
${CMAKE_SOURCE_DIR}/src/butil/debug/stack_trace_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/environment.cc
${CMAKE_SOURCE_DIR}/src/butil/files/file.cc
${CMAKE_SOURCE_DIR}/src/butil/files/file_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/files/file_enumerator.cc
${CMAKE_SOURCE_DIR}/src/butil/files/file_enumerator_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/files/file_path.cc
${CMAKE_SOURCE_DIR}/src/butil/files/file_path_constants.cc
${CMAKE_SOURCE_DIR}/src/butil/files/memory_mapped_file.cc
${CMAKE_SOURCE_DIR}/src/butil/files/memory_mapped_file_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/files/scoped_file.cc
${CMAKE_SOURCE_DIR}/src/butil/files/scoped_temp_dir.cc
${CMAKE_SOURCE_DIR}/src/butil/file_util.cc
${CMAKE_SOURCE_DIR}/src/butil/file_util_linux.cc
${CMAKE_SOURCE_DIR}/src/butil/file_util_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/guid.cc
${CMAKE_SOURCE_DIR}/src/butil/guid_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/hash.cc
${CMAKE_SOURCE_DIR}/src/butil/lazy_instance.cc
${CMAKE_SOURCE_DIR}/src/butil/location.cc
${CMAKE_SOURCE_DIR}/src/butil/md5.cc
${CMAKE_SOURCE_DIR}/src/butil/memory/aligned_memory.cc
${CMAKE_SOURCE_DIR}/src/butil/memory/ref_counted.cc
${CMAKE_SOURCE_DIR}/src/butil/memory/ref_counted_memory.cc
${CMAKE_SOURCE_DIR}/src/butil/memory/singleton.cc
${CMAKE_SOURCE_DIR}/src/butil/memory/weak_ptr.cc
${CMAKE_SOURCE_DIR}/src/butil/posix/file_descriptor_shuffle.cc
${CMAKE_SOURCE_DIR}/src/butil/posix/global_descriptors.cc
${CMAKE_SOURCE_DIR}/src/butil/rand_util.cc
${CMAKE_SOURCE_DIR}/src/butil/rand_util_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/fast_rand.cpp
${CMAKE_SOURCE_DIR}/src/butil/safe_strerror_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/sha1_portable.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/latin1_string_conversions.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/nullable_string16.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/safe_sprintf.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/string16.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/string_number_conversions.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/string_split.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/string_piece.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/string_util.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/string_util_constants.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/stringprintf.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/sys_string_conversions_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/utf_offset_string_conversions.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/utf_string_conversion_utils.cc
${CMAKE_SOURCE_DIR}/src/butil/strings/utf_string_conversions.cc
${CMAKE_SOURCE_DIR}/src/butil/synchronization/cancellation_flag.cc
${CMAKE_SOURCE_DIR}/src/butil/synchronization/condition_variable_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/synchronization/waitable_event_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/non_thread_safe_impl.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/platform_thread_linux.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/platform_thread_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/simple_thread.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_checker_impl.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_collision_warner.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_id_name_manager.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_local_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_local_storage.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_local_storage_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/thread_restrictions.cc
${CMAKE_SOURCE_DIR}/src/butil/threading/watchdog.cc
${CMAKE_SOURCE_DIR}/src/butil/time/clock.cc
${CMAKE_SOURCE_DIR}/src/butil/time/default_clock.cc
${CMAKE_SOURCE_DIR}/src/butil/time/default_tick_clock.cc
${CMAKE_SOURCE_DIR}/src/butil/time/tick_clock.cc
${CMAKE_SOURCE_DIR}/src/butil/time/time.cc
${CMAKE_SOURCE_DIR}/src/butil/time/time_posix.cc
${CMAKE_SOURCE_DIR}/src/butil/version.cc
${CMAKE_SOURCE_DIR}/src/butil/logging.cc
${CMAKE_SOURCE_DIR}/src/butil/class_name.cpp
${CMAKE_SOURCE_DIR}/src/butil/errno.cpp
${CMAKE_SOURCE_DIR}/src/butil/find_cstr.cpp
${CMAKE_SOURCE_DIR}/src/butil/status.cpp
${CMAKE_SOURCE_DIR}/src/butil/string_printf.cpp
${CMAKE_SOURCE_DIR}/src/butil/thread_local.cpp
${CMAKE_SOURCE_DIR}/src/butil/unix_socket.cpp
${CMAKE_SOURCE_DIR}/src/butil/endpoint.cpp
${CMAKE_SOURCE_DIR}/src/butil/fd_utility.cpp
${CMAKE_SOURCE_DIR}/src/butil/files/temp_file.cpp
${CMAKE_SOURCE_DIR}/src/butil/files/file_watcher.cpp
${CMAKE_SOURCE_DIR}/src/butil/time.cpp
${CMAKE_SOURCE_DIR}/src/butil/zero_copy_stream_as_streambuf.cpp
${CMAKE_SOURCE_DIR}/src/butil/crc32c.cc
${CMAKE_SOURCE_DIR}/src/butil/containers/case_ignored_flat_map.cpp
${CMAKE_SOURCE_DIR}/src/butil/iobuf.cpp
${CMAKE_SOURCE_DIR}/src/butil/popen.cpp
)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/bvar BVAR_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/bvar/detail BVAR_DETAIL_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/bthread BTHREAD_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/json2pb JSON2PB_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/brpc BRPC_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/brpc/details BRPC_DETAILS_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/brpc/builtin BRPC_BUILTIN_SOURCES)
aux_source_directory(${CMAKE_SOURCE_DIR}/src/brpc/policy BRPC_POLICY_SOURCES)
set(MCPACK2PB_SOURCES
${CMAKE_SOURCE_DIR}/src/mcpack2pb/field_type.cpp
${CMAKE_SOURCE_DIR}/src/mcpack2pb/mcpack2pb.cpp
${CMAKE_SOURCE_DIR}/src/mcpack2pb/parser.cpp
${CMAKE_SOURCE_DIR}/src/mcpack2pb/serializer.cpp
)
set(SOURCES
${BVAR_SOURCES}
${BVAR_DETAIL_SOURCES}
${BTHREAD_SOURCES}
${JSON2PB_SOURCES}
${MCPACK2PB_SOURCES}
${BRPC_SOURCES}
${BRPC_DETAILS_SOURCES}
${BRPC_BUILTIN_SOURCES}
${BRPC_POLICY_SOURCES}
${PROTO_SRCS}
${BRPC_PROTOS}
${BRPC_POLICY_PROTOS}
)
add_subdirectory(src)
if(BUILD_EXAMPLE)
add_subdirectory(example)
endif()
if(BUILD_UNIT_TESTS)
add_subdirectory(test)
endif()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
......@@ -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