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 7cef916
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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)

set(WITH_GLOG_VAL "0")
if(BRPC_WITH_GLOG)
Expand All @@ -23,6 +26,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 +74,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
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 7cef916

Please sign in to comment.