pslib_brpc.cmake 3.3 KB
Newer Older
H
heqiaozhi 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# Copyright (c) 2017 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.

IF(NOT ${WITH_PSLIB_BRPC})
  return()
ENDIF(NOT ${WITH_PSLIB_BRPC})

IF(WIN32 OR APPLE)
    MESSAGE(WARNING
        "Windows or Mac is not supported with PSLIB_BRPC in Paddle yet."
        "Force WITH_PSLIB_BRPC=OFF")
    SET(WITH_PSLIB_BRPC OFF CACHE STRING "Disable PSLIB_BRPC package in Windows and MacOS" FORCE)
    return()
ENDIF()

INCLUDE(ExternalProject)

SET(PSLIB_BRPC_PROJECT       "extern_pslib_brpc")
H
heqiaozhi 已提交
30
IF((NOT DEFINED PSLIB_BRPC_NAME) OR (NOT DEFINED PSLIB_BRPC_URL))
H
heqiaozhi 已提交
31
  MESSAGE(STATUS "use pre defined download url")
H
heqiaozhi 已提交
32 33 34
  SET(PSLIB_BRPC_VER "0.1.0" CACHE STRING "" FORCE)
  SET(PSLIB_BRPC_NAME "pslib_brpc" CACHE STRING "" FORCE)
  SET(PSLIB_BRPC_URL "https://raw.githubusercontent.com/PaddlePaddle/Fleet/release/${PSLIB_BRPC_VER}/${PSLIB_BRPC_NAME}.tar.gz" CACHE STRING "" FORCE)
H
heqiaozhi 已提交
35
ENDIF()
H
heqiaozhi 已提交
36
MESSAGE(STATUS "PSLIB_BRPC_NAME: ${PSLIB_BRPC_NAME}, PSLIB_BRPC_URL: ${PSLIB_BRPC_URL}")
H
heqiaozhi 已提交
37 38 39 40 41 42 43 44
SET(PSLIB_BRPC_SOURCE_DIR    "${THIRD_PARTY_PATH}/pslib_brpc")
SET(PSLIB_BRPC_DOWNLOAD_DIR  "${PSLIB_BRPC_SOURCE_DIR}/src/${PSLIB_BRPC_PROJECT}")
SET(PSLIB_BRPC_DST_DIR       "pslib_brpc")
SET(PSLIB_BRPC_INSTALL_ROOT  "${THIRD_PARTY_PATH}/install")
SET(PSLIB_BRPC_INSTALL_DIR   ${PSLIB_BRPC_INSTALL_ROOT}/${PSLIB_BRPC_DST_DIR})
SET(PSLIB_BRPC_ROOT          ${PSLIB_BRPC_INSTALL_DIR})
SET(PSLIB_BRPC_INC_DIR       ${PSLIB_BRPC_ROOT}/include)
SET(PSLIB_BRPC_LIB_DIR       ${PSLIB_BRPC_ROOT}/lib)
H
heqiaozhi 已提交
45
SET(PSLIB_BRPC_LIB           ${PSLIB_BRPC_LIB_DIR}/libbrpc.a)
H
heqiaozhi 已提交
46 47 48 49 50 51 52 53
SET(PSLIB_BRPC_IOMP_LIB      ${PSLIB_BRPC_LIB_DIR}/libiomp5.so) #todo what is this
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${PSLIB_BRPC_ROOT}/lib")

INCLUDE_DIRECTORIES(${PSLIB_BRPC_INC_DIR})

FILE(WRITE ${PSLIB_BRPC_DOWNLOAD_DIR}/CMakeLists.txt
  "PROJECT(PSLIB_BRPC)\n"
  "cmake_minimum_required(VERSION 3.0)\n"
H
heqiaozhi 已提交
54
  "install(DIRECTORY ${PSLIB_BRPC_NAME}/include ${PSLIB_BRPC_NAME}/lib \n"
H
heqiaozhi 已提交
55 56 57 58 59 60 61
  "        DESTINATION ${PSLIB_BRPC_DST_DIR})\n")

ExternalProject_Add(
    ${PSLIB_BRPC_PROJECT}
    ${EXTERNAL_PROJECT_LOG_ARGS}
    PREFIX                ${PSLIB_BRPC_SOURCE_DIR}
    DOWNLOAD_DIR          ${PSLIB_BRPC_DOWNLOAD_DIR}
H
heqiaozhi 已提交
62 63
    DOWNLOAD_COMMAND      wget --no-check-certificate ${PSLIB_BRPC_URL} -c -q -O ${PSLIB_BRPC_NAME}.tar.gz
                          && tar zxvf ${PSLIB_BRPC_NAME}.tar.gz
H
heqiaozhi 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77
    DOWNLOAD_NO_PROGRESS  1
    UPDATE_COMMAND        ""
    CMAKE_ARGS            -DCMAKE_INSTALL_PREFIX=${PSLIB_BRPC_INSTALL_ROOT}
    CMAKE_CACHE_ARGS      -DCMAKE_INSTALL_PREFIX:PATH=${PSLIB_BRPC_INSTALL_ROOT}
)

ADD_LIBRARY(pslib_brpc SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET pslib_brpc PROPERTY IMPORTED_LOCATION ${PSLIB_BRPC_LIB})
ADD_DEPENDENCIES(pslib_brpc ${PSLIB_BRPC_PROJECT})
LIST(APPEND external_project_dependencies pslib_brpc)

IF(WITH_C_API)
  INSTALL(FILES ${PSLIB_BRPC_LIB} ${PSLIB_BRPC_IOMP_LIB} DESTINATION lib)
ENDIF()