inference_lib.cmake 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2018 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 16 17 18
set_property(GLOBAL PROPERTY FLUID_MODULES "")
# find all fluid modules is used for paddle fluid static library
function(find_fluid_modules TARGET_NAME)
  get_filename_component(__target_path ${TARGET_NAME} ABSOLUTE)
19
  string(REGEX REPLACE "^${PADDLE_SOURCE_DIR}/" "" __target_path ${__target_path})
20 21 22 23 24 25 26 27
  string(FIND "${__target_path}" "fluid" pos)
  if(pos GREATER 1)
    get_property(fluid_modules GLOBAL PROPERTY FLUID_MODULES)
    set(fluid_modules ${fluid_modules} ${TARGET_NAME})
    set_property(GLOBAL PROPERTY FLUID_MODULES "${fluid_modules}")
  endif()
endfunction(find_fluid_modules)

L
Luo Tao 已提交
28
# make package for paddle fluid shared and static library
L
Luo Tao 已提交
29 30 31 32 33
function(copy TARGET)
    set(options "")
    set(oneValueArgs "")
    set(multiValueArgs SRCS DSTS DEPS)
    cmake_parse_arguments(copy_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
34
    set(inference_lib_dist_dep ${TARGET} ${inference_lib_dist_dep} PARENT_SCOPE)
L
Luo Tao 已提交
35 36 37 38 39 40 41 42 43 44 45 46

    list(LENGTH copy_lib_SRCS copy_lib_SRCS_len)
    list(LENGTH copy_lib_DSTS copy_lib_DSTS_len)
    if(NOT ${copy_lib_SRCS_len} EQUAL ${copy_lib_DSTS_len})
        message(FATAL_ERROR "${TARGET} source numbers are not equal to destination numbers")
    endif()
    math(EXPR len "${copy_lib_SRCS_len} - 1")
    
    add_custom_target(${TARGET} DEPENDS ${copy_lib_DEPS})
    foreach(index RANGE ${len})
        list(GET copy_lib_SRCS ${index} src)
        list(GET copy_lib_DSTS ${index} dst)
47 48 49 50
        add_custom_command(TARGET ${TARGET} PRE_BUILD 
          COMMAND mkdir -p "${dst}"
          COMMAND cp -r "${src}" "${dst}"
          COMMENT "copying ${src} -> ${dst}")
L
Luo Tao 已提交
51 52 53
    endforeach()
endfunction()

L
Luo Tao 已提交
54
# third party
L
Luo Tao 已提交
55 56 57 58
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/eigen3")
copy(eigen3_lib
  SRCS ${EIGEN_INCLUDE_DIR}/Eigen/Core ${EIGEN_INCLUDE_DIR}/Eigen/src ${EIGEN_INCLUDE_DIR}/unsupported/Eigen
  DSTS ${dst_dir}/Eigen ${dst_dir}/Eigen ${dst_dir}/unsupported
L
Luo Tao 已提交
59 60
)

L
Luo Tao 已提交
61 62 63 64
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/gflags")
copy(gflags_lib
  SRCS ${GFLAGS_INCLUDE_DIR} ${GFLAGS_LIBRARIES}
  DSTS ${dst_dir} ${dst_dir}/lib
L
Luo Tao 已提交
65 66
)

L
Luo Tao 已提交
67 68 69 70
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/glog")
copy(glog_lib
  SRCS ${GLOG_INCLUDE_DIR} ${GLOG_LIBRARIES}
  DSTS ${dst_dir} ${dst_dir}/lib
L
Luo Tao 已提交
71 72
)

Q
qiaolongfei 已提交
73
set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/boost/")
Q
qiaolongfei 已提交
74
copy(boost_lib
Q
qiaolongfei 已提交
75
  SRCS ${BOOST_INCLUDE_DIR}/boost
Q
qiaolongfei 已提交
76 77 78
  DSTS ${dst_dir}
)

79
if(NOT PROTOBUF_FOUND)
L
Luo Tao 已提交
80 81
    set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/protobuf")
    copy(protobuf_lib
82
      SRCS ${PROTOBUF_INCLUDE_DIR} ${PROTOBUF_LIBRARY}
L
Luo Tao 已提交
83
      DSTS ${dst_dir} ${dst_dir}/lib
L
Luo Tao 已提交
84
    )
85 86 87 88 89 90 91 92
endif()

if(NOT CBLAS_FOUND)
    set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/openblas")
    copy(openblas_lib
      SRCS ${CBLAS_INSTALL_DIR}/lib ${CBLAS_INSTALL_DIR}/include
      DSTS ${dst_dir} ${dst_dir}
    )
L
Luo Tao 已提交
93
elseif (WITH_MKLML)
94 95
    set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/mklml")
    copy(mklml_lib
L
Luo Tao 已提交
96 97
      SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR}
      DSTS ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}
98
    )
99
endif()
L
Luo Tao 已提交
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
if(NOT MOBILE_INFERENCE AND NOT RPI)
  set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/snappy")
  copy(snappy_lib
    SRCS ${SNAPPY_INCLUDE_DIR} ${SNAPPY_LIBRARIES}
    DSTS ${dst_dir} ${dst_dir}/lib)

  set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/snappystream")
  copy(snappystream_lib
    SRCS ${SNAPPYSTREAM_INCLUDE_DIR} ${SNAPPYSTREAM_LIBRARIES}
    DSTS ${dst_dir} ${dst_dir}/lib)

  set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/zlib")
  copy(zlib_lib
    SRCS ${ZLIB_INCLUDE_DIR} ${ZLIB_LIBRARIES}
    DSTS ${dst_dir} ${dst_dir}/lib)
endif()

L
Luo Tao 已提交
118
# paddle fluid module
119 120
set(src_dir "${PADDLE_SOURCE_DIR}/paddle/fluid")
set(dst_dir "${CMAKE_INSTALL_PREFIX}/paddle/fluid")
L
Luo Tao 已提交
121 122
set(module "framework")
copy(framework_lib DEPS framework_py_proto 
123
  SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h
L
Luo Tao 已提交
124
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module}
L
Luo Tao 已提交
125 126
)

L
Luo Tao 已提交
127 128 129 130
set(module "memory")
copy(memory_lib
  SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/detail/*.h
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}/detail
L
Luo Tao 已提交
131 132
)

L
Luo Tao 已提交
133
set(module "inference")
134 135
copy(inference_lib DEPS paddle_fluid_shared paddle_fluid
  SRCS ${src_dir}/${module}/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/inference/libpaddle_fluid.*
L
Luo Tao 已提交
136
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}
L
Luo Tao 已提交
137 138
)

L
Luo Tao 已提交
139
set(module "platform")
X
Xin Pan 已提交
140
copy(platform_lib DEPS profiler_py_proto
L
Luo Tao 已提交
141 142 143
  SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/dynload/*.h ${src_dir}/${module}/details/*.h
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}/dynload ${dst_dir}/${module}/details
)
L
Luo Tao 已提交
144

L
Luo Tao 已提交
145 146 147 148
set(module "string")
copy(string_lib
  SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/tinyformat/*.h
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}/tinyformat
L
Luo Tao 已提交
149 150
)

151
add_custom_target(inference_lib_dist DEPENDS ${inference_lib_dist_dep})