brpc.cmake 3.9 KB
Newer Older
G
gongweibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15
include(ExternalProject)
G
gongweibao 已提交
16

T
tangwei12 已提交
17
find_package(OpenSSL REQUIRED)
18 19 20 21

message(STATUS "ssl:" ${OPENSSL_SSL_LIBRARY})
message(STATUS "crypto:" ${OPENSSL_CRYPTO_LIBRARY})

22 23
add_library(ssl SHARED IMPORTED GLOBAL)
set_property(TARGET ssl PROPERTY IMPORTED_LOCATION ${OPENSSL_SSL_LIBRARY})
G
gongweibao 已提交
24

25 26
add_library(crypto SHARED IMPORTED GLOBAL)
set_property(TARGET crypto PROPERTY IMPORTED_LOCATION ${OPENSSL_CRYPTO_LIBRARY})
G
gongweibao 已提交
27

28 29 30 31 32 33 34 35
set(BRPC_PREFIX_DIR ${THIRD_PARTY_PATH}/brpc)
set(BRPC_INSTALL_DIR ${THIRD_PARTY_PATH}/install/brpc)
set(BRPC_INCLUDE_DIR
    "${BRPC_INSTALL_DIR}/include"
    CACHE PATH "brpc include directory." FORCE)
set(BRPC_LIBRARIES
    "${BRPC_INSTALL_DIR}/lib/libbrpc.a"
    CACHE FILEPATH "brpc library." FORCE)
G
gongweibao 已提交
36

37
include_directories(${BRPC_INCLUDE_DIR})
G
gongweibao 已提交
38

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
# clone brpc to Paddle/third_party
set(BRPC_SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/brpc)
set(BRPC_URL https://github.com/apache/brpc.git)
set(BRPC_TAG 1.4.0)

if(NOT EXISTS ${BRPC_SOURCE_DIR})
  execute_process(COMMAND ${GIT_EXECUTABLE} clone -b ${BRPC_TAG} ${BRPC_URL}
                          ${BRPC_SOURCE_DIR})
else()
  # check git tag
  execute_process(
    COMMAND ${GIT_EXECUTABLE} -C ${BRPC_SOURCE_DIR} describe --tags
    OUTPUT_VARIABLE CURRENT_TAG
    OUTPUT_STRIP_TRAILING_WHITESPACE)
  if(NOT ${CURRENT_TAG} STREQUAL ${BRPC_TAG})
    message(STATUS "Checkout brpc to ${BRPC_TAG}")
    execute_process(COMMAND ${GIT_EXECUTABLE} -C ${BRPC_SOURCE_DIR} checkout -q
                            ${BRPC_TAG})
  endif()
endif()

G
gongweibao 已提交
60
# Reference https://stackoverflow.com/questions/45414507/pass-a-list-of-prefix-paths-to-externalproject-add-in-cmake-args
61 62 63
set(prefix_path
    "${THIRD_PARTY_PATH}/install/gflags|${THIRD_PARTY_PATH}/install/leveldb|${THIRD_PARTY_PATH}/install/snappy|${THIRD_PARTY_PATH}/install/gtest|${THIRD_PARTY_PATH}/install/protobuf|${THIRD_PARTY_PATH}/install/zlib|${THIRD_PARTY_PATH}/install/glog"
)
G
gongweibao 已提交
64 65 66

# If minimal .a is need, you can set  WITH_DEBUG_SYMBOLS=OFF
ExternalProject_Add(
67 68
  extern_brpc
  ${EXTERNAL_PROJECT_LOG_ARGS}
69
  SOURCE_DIR ${BRPC_SOURCE_DIR}
70 71 72 73 74 75 76 77 78 79 80 81
  PREFIX ${BRPC_PREFIX_DIR}
  UPDATE_COMMAND ""
  CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
             -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
             -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
             -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
             -DCMAKE_INSTALL_PREFIX=${BRPC_INSTALL_DIR}
             -DCMAKE_INSTALL_LIBDIR=${BRPC_INSTALL_DIR}/lib
             -DCMAKE_POSITION_INDEPENDENT_CODE=ON
             -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
             -DCMAKE_PREFIX_PATH=${prefix_path}
             -DWITH_GLOG=ON
82 83
             -DBUILD_BRPC_TOOLS=ON
             -DBUILD_SHARED_LIBS=ON
84 85 86 87 88 89 90 91
             ${EXTERNAL_OPTIONAL_ARGS}
  LIST_SEPARATOR |
  CMAKE_CACHE_ARGS
    -DCMAKE_INSTALL_PREFIX:PATH=${BRPC_INSTALL_DIR}
    -DCMAKE_INSTALL_LIBDIR:PATH=${BRPC_INSTALL_DIR}/lib
    -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
    -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
  BUILD_BYPRODUCTS ${BRPC_LIBRARIES})
92

T
tangwei12 已提交
93
# ADD_DEPENDENCIES(extern_brpc protobuf ssl crypto leveldb gflags glog gtest snappy)
94 95 96 97 98 99 100 101 102 103 104 105
add_dependencies(
  extern_brpc
  protobuf
  ssl
  crypto
  leveldb
  gflags
  glog
  snappy)
add_library(brpc STATIC IMPORTED GLOBAL)
set_property(TARGET brpc PROPERTY IMPORTED_LOCATION ${BRPC_LIBRARIES})
add_dependencies(brpc extern_brpc)
G
gongweibao 已提交
106

107
add_definitions(-DBRPC_WITH_GLOG)
T
tangwei12 已提交
108

109
list(APPEND external_project_dependencies brpc)