diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 757a18e9..74070fcc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,12 +59,6 @@ jobs: chmod a+x bazel-0.25.2-installer-linux-x86_64.sh ./bazel-0.25.2-installer-linux-x86_64.sh --user export PATH="$PATH:$HOME/bin" - - name: Install brpc - working-directory: ${{ github.workspace }} - if: ${{ matrix.build_tool == 'cmake' }} - run: | - mkdir -p thirdparty - git clone https://github.com/brpc/brpc.git thirdparty/brpc && cd thirdparty/brpc && mkdir -p bld && cd bld && cmake .. && make -j4 && sudo make install - name: Build with cmake if: ${{ matrix.build_tool == 'cmake' }} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 110daa30..462f045f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,10 @@ INCLUDE(CPack) #option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF) option(BRPC_WITH_GLOG "With glog" OFF) option(WITH_DEBUG_SYMBOLS "With debug symbols" ON) +# https://cmake.org/cmake/help/latest/policy/CMP0058.html +# suppress this CMP0058 warning +cmake_policy(SET CMP0058 OLD) +option(WITH_TESTS "Whether to build unit tests" OFF) set(WITH_GLOG_VAL "0") if(BRPC_WITH_GLOG) @@ -23,6 +27,11 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(FindThreads) include(FindProtobuf) +include(SetupBrpc) + +if ((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB)) + message(FATAL_ERROR "Fail to find brpc") +endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # require at least gcc 4.8 @@ -66,12 +75,6 @@ if(LEVELDB_WITH_SNAPPY) find_library(SNAPPY_LIB NAMES snappy) endif() -find_path(BRPC_INCLUDE_PATH NAMES brpc/server.h) -find_library(BRPC_LIB NAMES libbrpc.a brpc) -if ((NOT BRPC_INCLUDE_PATH) OR (NOT BRPC_LIB)) - message(FATAL_ERROR "Fail to find brpc") -endif() - if (NOT PROTOBUF_PROTOC_EXECUTABLE) get_filename_component(PROTO_LIB_DIR ${PROTOBUF_LIBRARY} DIRECTORY) set (PROTOBUF_PROTOC_EXECUTABLE "${PROTO_LIB_DIR}/../bin/protoc") @@ -226,7 +229,7 @@ endmacro(use_cxx11) use_cxx11() add_subdirectory(src) -if(BUILD_UNIT_TESTS) +if(WITH_TESTS) add_subdirectory(test) endif() add_subdirectory(tools) diff --git a/cmake/CMakeLists.download_brpc.in b/cmake/CMakeLists.download_brpc.in new file mode 100644 index 00000000..91407827 --- /dev/null +++ b/cmake/CMakeLists.download_brpc.in @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(brpc-download NONE) + +include(ExternalProject) +ExternalProject_Add(brpc + GIT_REPOSITORY https://github.com/apache/brpc.git + GIT_TAG 1.8.0 + SOURCE_DIR "${CMAKE_BINARY_DIR}/_deps/brpc/src" + BINARY_DIR "${CMAKE_BINARY_DIR}/_deps/brpc/build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) + diff --git a/cmake/SetupBrpc.cmake b/cmake/SetupBrpc.cmake new file mode 100644 index 00000000..4d002aab --- /dev/null +++ b/cmake/SetupBrpc.cmake @@ -0,0 +1,26 @@ +# Setup brpc +configure_file("${PROJECT_SOURCE_DIR}/cmake/CMakeLists.download_brpc.in" ${PROJECT_BINARY_DIR}/_deps/brpc/CMakeLists.txt) + + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/_deps/brpc) + +if(result) + message(FATAL_ERROR "CMake step for brpc failed: ${result}") +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/_deps/brpc) + +if(result) + message(FATAL_ERROR "Build step for brpc failed: ${result}") +endif() + +add_subdirectory(${PROJECT_BINARY_DIR}/_deps/brpc/src + ${PROJECT_BINARY_DIR}/_deps/brpc/build + EXCLUDE_FROM_ALL) + +set(BRPC_LIB brpc-static) +set(BRPC_INCLUDE_PATH ${PROJECT_BINARY_DIR}/_deps/brpc/build/output/include)