inference_lib.cmake 8.0 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.

L
Luo Tao 已提交
15
# make package for paddle fluid shared and static library
L
Luo Tao 已提交
16 17 18 19 20
function(copy TARGET)
    set(options "")
    set(oneValueArgs "")
    set(multiValueArgs SRCS DSTS DEPS)
    cmake_parse_arguments(copy_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
21
    set(inference_lib_dist_dep ${TARGET} ${inference_lib_dist_dep} PARENT_SCOPE)
L
Luo Tao 已提交
22 23 24 25 26 27 28

    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")
29

L
Luo Tao 已提交
30 31 32 33
    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)
D
dzhwinter 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        
        if (WIN32) 
        # windows cmd shell will not expand wildcard automatically.
        # below expand the files,libs and copy them by rules.
        file(GLOB header_files ${src} "*.h")
        file(GLOB static_lib_files ${src} "*.lib")
        file(GLOB dll_lib_files ${src} "*.dll")
        set(src_files ${header_files} ${static_lib_files} ${dll_lib_files})

        if (NOT "${src_files}" STREQUAL "")
        list(REMOVE_DUPLICATES src_files)
        endif()
        add_custom_command(TARGET ${TARGET} PRE_BUILD 
          COMMAND ${CMAKE_COMMAND} -E make_directory  "${dst}"
          )
        foreach(src_file ${src_files}) 
          add_custom_command(TARGET ${TARGET} PRE_BUILD 
          COMMAND ${CMAKE_COMMAND} -E copy "${src_file}" "${dst}"
          COMMENT "copying ${src_file} -> ${dst}")
        endforeach()
W
wanghaoshuang 已提交
54 55 56 57
        else(WIN32) # not windows
	add_custom_command(TARGET ${TARGET} PRE_BUILD 
          COMMAND mkdir -p "${dst}"
          COMMAND cp -r "${src}" "${dst}"
58
          COMMENT "copying ${src} -> ${dst}")
W
wanghaoshuang 已提交
59 60 61 62 63 64 65
        #add_custom_command(TARGET ${TARGET} PRE_BUILD 
        #  COMMAND ${CMAKE_COMMAND} -E make_directory  "${dst}")
	#message("mkdir " ${TARGET})
        #add_custom_command(TARGET ${TARGET} PRE_BUILD 
        #  COMMAND ${CMAKE_COMMAND} -E make_directory  "${dst}"
        #  COMMAND ${CMAKE_COMMAND} -E copy_directory "${src_files}" "${dst}"
        #  COMMENT "copying ${src} -> ${dst}")
D
dzhwinter 已提交
66
        endif(WIN32)
L
Luo Tao 已提交
67 68 69
    endforeach()
endfunction()

L
Luo Tao 已提交
70
# third party
71
set(dst_dir "${FLUID_INSTALL_DIR}/third_party/eigen3")
L
Luo Tao 已提交
72 73 74
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
T
tensor-tang 已提交
75
  DEPS eigen3
L
Luo Tao 已提交
76 77
)

78
set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/gflags")
L
Luo Tao 已提交
79 80 81
copy(gflags_lib
  SRCS ${GFLAGS_INCLUDE_DIR} ${GFLAGS_LIBRARIES}
  DSTS ${dst_dir} ${dst_dir}/lib
T
tensor-tang 已提交
82
  DEPS gflags
L
Luo Tao 已提交
83 84
)

85
set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/glog")
L
Luo Tao 已提交
86 87 88
copy(glog_lib
  SRCS ${GLOG_INCLUDE_DIR} ${GLOG_LIBRARIES}
  DSTS ${dst_dir} ${dst_dir}/lib
T
tensor-tang 已提交
89
  DEPS glog
L
Luo Tao 已提交
90 91
)

92
set(dst_dir "${FLUID_INSTALL_DIR}/third_party/boost/")
Q
qiaolongfei 已提交
93
copy(boost_lib
Q
qiaolongfei 已提交
94
  SRCS ${BOOST_INCLUDE_DIR}/boost
Q
qiaolongfei 已提交
95
  DSTS ${dst_dir}
T
tensor-tang 已提交
96
  DEPS boost
Q
qiaolongfei 已提交
97 98
)

99
if(NOT PROTOBUF_FOUND)
100
    set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/protobuf")
L
Luo Tao 已提交
101
    copy(protobuf_lib
102
      SRCS ${PROTOBUF_INCLUDE_DIR} ${PROTOBUF_LIBRARY}
L
Luo Tao 已提交
103
      DSTS ${dst_dir} ${dst_dir}/lib
T
tensor-tang 已提交
104
      DEPS extern_protobuf
L
Luo Tao 已提交
105
    )
106 107 108
endif()

if(NOT CBLAS_FOUND)
109
    set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/openblas")
110 111 112
    copy(openblas_lib
      SRCS ${CBLAS_INSTALL_DIR}/lib ${CBLAS_INSTALL_DIR}/include
      DSTS ${dst_dir} ${dst_dir}
T
tensor-tang 已提交
113
      DEPS extern_openblas
114
    )
L
Luo Tao 已提交
115
elseif (WITH_MKLML)
116
    set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/mklml")
117
    copy(mklml_lib
L
Luo Tao 已提交
118 119
      SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR}
      DSTS ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}
T
tensor-tang 已提交
120
      DEPS mklml
121
    )
122
endif()
L
Luo Tao 已提交
123

Q
qiaolongfei 已提交
124
if(WITH_MKLDNN)
125
  set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/mkldnn")
Q
qiaolongfei 已提交
126
  copy(mkldnn_lib
Q
qiaolongfei 已提交
127
    SRCS ${MKLDNN_INC_DIR} ${MKLDNN_SHARED_LIB}
Q
qiaolongfei 已提交
128
    DSTS ${dst_dir} ${dst_dir}/lib
T
tensor-tang 已提交
129
    DEPS mkldnn
Q
qiaolongfei 已提交
130 131 132
  )
endif()

D
dzhwinter 已提交
133
if (NOT WIN32)
134
if(NOT MOBILE_INFERENCE AND NOT RPI)
135
  set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/snappy")
136 137
  copy(snappy_lib
    SRCS ${SNAPPY_INCLUDE_DIR} ${SNAPPY_LIBRARIES}
T
tensor-tang 已提交
138 139
    DSTS ${dst_dir} ${dst_dir}/lib
    DEPS snappy)
140

141
  set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/snappystream")
142 143
  copy(snappystream_lib
    SRCS ${SNAPPYSTREAM_INCLUDE_DIR} ${SNAPPYSTREAM_LIBRARIES}
T
tensor-tang 已提交
144 145
    DSTS ${dst_dir} ${dst_dir}/lib
    DEPS snappystream)
146

147
  set(dst_dir "${FLUID_INSTALL_DIR}/third_party/install/zlib")
148 149
  copy(zlib_lib
    SRCS ${ZLIB_INCLUDE_DIR} ${ZLIB_LIBRARIES}
T
tensor-tang 已提交
150 151
    DSTS ${dst_dir} ${dst_dir}/lib
    DEPS zlib)
152
endif()
D
dzhwinter 已提交
153
endif(NOT WIN32)
154

L
Luo Tao 已提交
155
# paddle fluid module
156
set(src_dir "${PADDLE_SOURCE_DIR}/paddle/fluid")
157
set(dst_dir "${FLUID_INSTALL_DIR}/paddle/fluid")
L
Luo Tao 已提交
158
set(module "framework")
D
dzhwinter 已提交
159
if (NOT WIN32)
L
Luo Tao 已提交
160
copy(framework_lib DEPS framework_py_proto 
161
  SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h
L
Luo Tao 已提交
162
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module}
L
Luo Tao 已提交
163
)
D
dzhwinter 已提交
164 165 166 167 168 169
else()
copy(framework_lib
  SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/framework/framework.pb.h
  DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module}
)
endif(NOT WIN32)
L
Luo Tao 已提交
170

L
Luo Tao 已提交
171 172 173 174
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 已提交
175 176
)

Y
Yan Chunwei 已提交
177
set(inference_deps paddle_fluid_shared paddle_fluid)
L
Luo Tao 已提交
178

179 180 181 182 183
set(module "inference/api")
if (WITH_ANAKIN AND WITH_GPU)
    copy(anakin_inference_lib DEPS paddle_inference_api inference_anakin_api
        SRCS
        ${PADDLE_BINARY_DIR}/paddle/fluid/inference/api/libinference_anakin_api* # compiled anakin api
L
Luo Tao 已提交
184
        ${ANAKIN_INSTALL_DIR} # anakin release
185 186
        DSTS ${dst_dir}/inference/anakin ${dst_dir}/inference/anakin)
     list(APPEND inference_deps anakin_inference_lib)
187 188
endif()

Y
Yan Chunwei 已提交
189 190 191
set(module "inference")
copy(inference_lib DEPS ${inference_deps}
  SRCS ${src_dir}/${module}/*.h ${PADDLE_BINARY_DIR}/paddle/fluid/inference/libpaddle_fluid.*
192 193
       ${src_dir}/${module}/api/paddle_inference_api.h ${src_dir}/${module}/api/demo_ci
  DSTS ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module} ${dst_dir}/${module}
Y
Yan Chunwei 已提交
194 195
)

L
Luo Tao 已提交
196
set(module "platform")
X
Xin Pan 已提交
197
copy(platform_lib DEPS profiler_py_proto
L
Luo Tao 已提交
198 199 200
  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 已提交
201

L
Luo Tao 已提交
202 203 204 205
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 已提交
206 207
)

208 209
set(module "pybind")
copy(pybind_lib
Q
qiaolongfei 已提交
210
  SRCS ${CMAKE_CURRENT_BINARY_DIR}/paddle/fluid/${module}/pybind.h
211 212 213
  DSTS ${dst_dir}/${module}
)

214 215 216
# CMakeCache Info
copy(cmake_cache
  SRCS ${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt
217
  DSTS ${FLUID_INSTALL_DIR})
218

219
add_custom_target(inference_lib_dist DEPENDS ${inference_lib_dist_dep}) 
220 221 222 223

# paddle fluid version
execute_process(
  COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -1
L
Luo Tao 已提交
224
  WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
225
  OUTPUT_VARIABLE PADDLE_GIT_COMMIT)
226
set(version_file ${FLUID_INSTALL_DIR}/version.txt)
227 228 229 230 231 232 233 234 235
file(WRITE ${version_file}
  "GIT COMMIT ID: ${PADDLE_GIT_COMMIT}\n"
  "WITH_MKL: ${WITH_MKL}\n"
  "WITH_GPU: ${WITH_GPU}\n")
if(WITH_GPU)
  file(APPEND ${version_file}
    "CUDA version: ${CUDA_VERSION}\n"
    "CUDNN version: v${CUDNN_MAJOR_VERSION}\n")
endif()