paddlepaddle.cmake 4.6 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright (c) 2019 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.

INCLUDE(ExternalProject)

W
wangguibao 已提交
17
SET(PADDLE_SOURCES_DIR ${THIRD_PARTY_PATH}/Paddle)
W
wangguibao 已提交
18
SET(PADDLE_DOWNLOAD_DIR ${PADDLE_SOURCES_DIR}/src/extern_paddle)
W
serving  
wangguibao 已提交
19
SET(PADDLE_INSTALL_DIR ${THIRD_PARTY_PATH}/install/Paddle/)
W
wangguibao 已提交
20 21 22
SET(PADDLE_INCLUDE_DIR "${PADDLE_INSTALL_DIR}/include" CACHE PATH "PaddlePaddle include directory." FORCE)
SET(PADDLE_LIBRARIES "${PADDLE_INSTALL_DIR}/lib/libpaddle_fluid.a" CACHE FILEPATH "Paddle library." FORCE)

G
guru4elephant 已提交
23
message("paddle install dir: " ${PADDLE_INSTALL_DIR})
W
wangguibao 已提交
24 25 26 27

# Reference https://stackoverflow.com/questions/45414507/pass-a-list-of-prefix-paths-to-externalproject-add-in-cmake-args
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")

W
Wang Guibao 已提交
28 29
message( "WITH_GPU = ${WITH_GPU}")

W
wangguibao 已提交
30 31 32 33

# Paddle Version should be one of:
# latest: latest develop build
# version number like 1.5.2
M
MRXLT 已提交
34
SET(PADDLE_VERSION "1.7.2")
W
wangguibao 已提交
35 36 37 38

if (WITH_GPU)
    SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-gpu-cuda${CUDA_VERSION_MAJOR}-cudnn7-avx-mkl")
else()
G
guru4elephant 已提交
39
    if (WITH_AVX)
W
wangguibao 已提交
40 41 42 43 44 45 46 47 48 49 50 51
        if (WITH_MKLML)
            SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-cpu-avx-mkl")
        else()
            SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-cpu-avx-openblas")
        endif()
    else()
        SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-cpu-noavx-openblas")
    endif()
endif()

SET(PADDLE_LIB_PATH "http://paddle-inference-lib.bj.bcebos.com/${PADDLE_LIB_VERSION}/fluid_inference.tgz")
MESSAGE(STATUS "PADDLE_LIB_PATH=${PADDLE_LIB_PATH}")
M
MRXLT 已提交
52
if (WITH_GPU OR WITH_MKLML)
W
wangguibao 已提交
53
ExternalProject_Add(
W
wangguibao 已提交
54
    "extern_paddle"
W
wangguibao 已提交
55
    ${EXTERNAL_PROJECT_LOG_ARGS}
W
wangguibao 已提交
56 57 58 59 60 61 62 63 64
    URL                 "${PADDLE_LIB_PATH}"
    PREFIX              "${PADDLE_SOURCES_DIR}"
    DOWNLOAD_DIR        "${PADDLE_DOWNLOAD_DIR}"
    CONFIGURE_COMMAND   ""
    BUILD_COMMAND       ""
    UPDATE_COMMAND      ""
    INSTALL_COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include &&
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib &&
M
MRXLT 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party &&
        ${CMAKE_COMMAND} -E copy ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so.0 ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so 
)
else()
ExternalProject_Add(
    "extern_paddle"
    ${EXTERNAL_PROJECT_LOG_ARGS}
    URL                 "${PADDLE_LIB_PATH}"
    PREFIX              "${PADDLE_SOURCES_DIR}"
    DOWNLOAD_DIR        "${PADDLE_DOWNLOAD_DIR}"
    CONFIGURE_COMMAND   ""
    BUILD_COMMAND       ""
    UPDATE_COMMAND      ""
    INSTALL_COMMAND
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include &&
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib &&
        ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party
W
wangguibao 已提交
82
)
G
guru4elephant 已提交
83 84
endif()

W
wangguibao 已提交
85
INCLUDE_DIRECTORIES(${PADDLE_INCLUDE_DIR})
W
wangguibao 已提交
86 87
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${PADDLE_INSTALL_DIR}/third_party/install/mklml/lib")
LINK_DIRECTORIES(${PADDLE_INSTALL_DIR}/third_party/install/mklml/lib)
W
wangguibao 已提交
88

W
wangguibao 已提交
89 90
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib")
LINK_DIRECTORIES(${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib)
W
wangguibao 已提交
91

G
guru4elephant 已提交
92 93 94
ADD_LIBRARY(openblas STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET openblas PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/openblas/lib/libopenblas.a)

W
wangguibao 已提交
95
ADD_LIBRARY(paddle_fluid STATIC IMPORTED GLOBAL)
W
wangguibao 已提交
96
SET_PROPERTY(TARGET paddle_fluid PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/lib/libpaddle_fluid.a)
W
wangguibao 已提交
97

W
serving  
wangguibao 已提交
98
ADD_LIBRARY(xxhash STATIC IMPORTED GLOBAL)
W
wangguibao 已提交
99
SET_PROPERTY(TARGET xxhash PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/xxhash/lib/libxxhash.a)
W
serving  
wangguibao 已提交
100

W
wangguibao 已提交
101
LIST(APPEND external_project_dependencies paddle)
W
wangguibao 已提交
102

W
serving  
wangguibao 已提交
103 104
LIST(APPEND paddle_depend_libs
        xxhash)