Skip to content

Commit

Permalink
[thirdparty] support import brpc lib from cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
ehds committed Apr 9, 2024
1 parent 59c40e5 commit 7b6af8f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,10 @@ 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: |
cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DBUILD_UNIT_TESTS=ON
cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" -DWITH_TESTS=ON
cmake --build "${{ env.CMAKE_BUILD_DIR }}"
- name: Build with bazel
if: ${{ matrix.build_tool == 'bazel' }}
Expand Down
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions cmake/CMakeLists.download_brpc.in
Original file line number Diff line number Diff line change
@@ -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 ""
)

26 changes: 26 additions & 0 deletions cmake/SetupBrpc.cmake
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7b6af8f

Please sign in to comment.