forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FastDeploy.cmake.in
223 lines (205 loc) · 9.33 KB
/
FastDeploy.cmake.in
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
CMAKE_MINIMUM_REQUIRED (VERSION 3.12)
set(WITH_GPU @WITH_GPU@)
set(ENABLE_ORT_BACKEND @ENABLE_ORT_BACKEND@)
set(ENABLE_LITE_BACKEND @ENABLE_LITE_BACKEND@)
set(ENABLE_PADDLE_BACKEND @ENABLE_PADDLE_BACKEND@)
set(ENABLE_OPENVINO_BACKEND @ENABLE_OPENVINO_BACKEND@)
set(ENABLE_TRT_BACKEND @ENABLE_TRT_BACKEND@)
set(ENABLE_PADDLE_FRONTEND @ENABLE_PADDLE_FRONTEND@)
set(ENABLE_VISION @ENABLE_VISION@)
set(ENABLE_TEXT @ENABLE_TEXT@)
set(BUILD_ON_JETON @BUILD_ON_JETSON@)
set(PADDLEINFERENCE_VERSION @PADDLEINFERENCE_VERSION@)
set(OPENVINO_VERSION @OPENVINO_VERSION@)
set(WITH_LITE_STATIC @WITH_LITE_STATIC@)
set(WITH_OPENCV_STATIC @WITH_OPENCV_STATIC@)
# set(ENABLE_OPENCV_CUDA @ENABLE_OPENCV_CUDA@)
set(OPENCV_FILENAME "@OPENCV_FILENAME@")
set(LIBRARY_NAME @LIBRARY_NAME@)
set(OPENCV_DIRECTORY "@OPENCV_DIRECTORY@")
set(ORT_DIRECTORY "@ORT_DIRECTORY@")
set(OPENVINO_DIRECTORY "@OPENVINO_DIRECTORY@")
set(FASTDEPLOY_LIBS "")
set(FASTDEPLOY_INCS "")
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/include)
# Note(zhoushunjie): include some useful utils function
include(${CMAKE_CURRENT_LIST_DIR}/utils.cmake)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
find_library(FDLIB ${LIBRARY_NAME} ${CMAKE_CURRENT_LIST_DIR}/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${FDLIB})
if(ENABLE_ORT_BACKEND)
if (ORT_DIRECTORY)
set(ORT_LIB_PATH ${ORT_DIRECTORY}/lib)
else()
set(ORT_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/onnxruntime/lib)
endif()
message(STATUS "The path of ONNXRuntime is ${ORT_LIB_PATH}.")
find_library(ORT_LIB onnxruntime ${ORT_LIB_PATH} NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${ORT_LIB})
endif()
if(ENABLE_PADDLE_BACKEND)
find_library(PADDLE_LIB paddle_inference ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/paddle/lib NO_DEFAULT_PATH)
if(WIN32)
set(DNNL_LIB "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/third_party/install/mkldnn/lib/mkldnn.lib")
set(IOMP_LIB "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/third_party/install/mklml/lib/libiomp5md.lib")
elseif(APPLE)
message(STATUS "No third parties libs(mkldnn and omp) need to link into paddle_inference on MacOS OSX.")
else()
set(DNNL_LIB "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/third_party/install/mkldnn/lib/libmkldnn.so.0")
set(IOMP_LIB "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/third_party/install/mklml/lib/libiomp5.so")
endif()
if(NOT APPLE)
list(APPEND FASTDEPLOY_LIBS ${PADDLE_LIB} ${DNNL_LIB} ${IOMP_LIB})
else()
list(APPEND FASTDEPLOY_LIBS ${PADDLE_LIB})
endif()
endif()
if(ENABLE_OPENVINO_BACKEND)
if (OPENVINO_DIRECTORY)
get_openvino_libs(${OPENVINO_DIRECTORY}/runtime)
else()
set(OPENVINO_FILENAME @OPENVINO_FILENAME@)
get_openvino_libs(${CMAKE_CURRENT_LIST_DIR}/third_libs/install/${OPENVINO_FILENAME}/runtime)
endif()
message(STATUS "OPENVINO_LIBS = ${OPENVINO_LIBS}")
list(APPEND FASTDEPLOY_LIBS ${OPENVINO_LIBS})
endif()
if(WITH_GPU)
if (NOT CUDA_DIRECTORY)
set(CUDA_DIRECTORY "/usr/local/cuda")
endif()
if(WIN32)
find_library(CUDA_LIB cudart ${CUDA_DIRECTORY}/lib/x64)
else()
find_library(CUDA_LIB cudart ${CUDA_DIRECTORY}/lib64)
endif()
if(NOT CUDA_LIB)
message(FATAL_ERROR "[FastDeploy] Cannot find library cudart in ${CUDA_DIRECTORY}, Please define CUDA_DIRECTORY, e.g -DCUDA_DIRECTORY=/path/to/cuda")
endif()
list(APPEND FASTDEPLOY_LIBS ${CUDA_LIB})
if (ENABLE_TRT_BACKEND)
find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
list(APPEND FASTDEPLOY_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB})
endif()
endif()
if(ENABLE_VISION)
if (OPENCV_DIRECTORY)
set(OpenCV_DIR ${OPENCV_DIRECTORY})
else()
if (ANDROID)
set(OpenCV_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/opencv-android-4.6.0/sdk/native/jni)
else()
set(OpenCV_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/${OPENCV_FILENAME})
if (WIN32)
set(OpenCV_DIR ${OpenCV_DIR}/build/)
endif()
endif()
endif()
message(STATUS "The path of OpenCV is ${OpenCV_DIR}.")
find_package(OpenCV REQUIRED PATHS ${OpenCV_DIR})
list(APPEND FASTDEPLOY_INCS ${OpenCV_INCLUDE_DIRS})
list(APPEND FASTDEPLOY_LIBS ${OpenCV_LIBS})
endif()
if (ENABLE_TEXT)
# Add dependency libs later
find_library(FASTER_TOKENIZER_LIB core_tokenizers ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/faster_tokenizer/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${FASTER_TOKENIZER_LIB})
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/faster_tokenizer/include)
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/faster_tokenizer/third_party/include)
endif()
if(ENABLE_PADDLE_FRONTEND)
find_library(PADDLE2ONNX_LIB paddle2onnx ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle2onnx/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${PADDLE2ONNX_LIB})
endif()
remove_duplicate_libraries(FASTDEPLOY_LIBS)
# Print compiler information
message(STATUS "")
message(STATUS "*************FastDeploy Building Summary**********")
message(STATUS " CMake version : ${CMAKE_VERSION}")
message(STATUS " CMake command : ${CMAKE_COMMAND}")
message(STATUS " System : ${CMAKE_SYSTEM_NAME}")
message(STATUS " C++ compiler : ${CMAKE_CXX_COMPILER}")
message(STATUS " C++ compiler version : ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS " CXX flags : ${CMAKE_CXX_FLAGS}")
message(STATUS " WITH_GPU : ${WITH_GPU}")
message(STATUS " ENABLE_ORT_BACKEND : ${ENABLE_ORT_BACKEND}")
message(STATUS " ENABLE_PADDLE_BACKEND : ${ENABLE_PADDLE_BACKEND}")
message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}")
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_LITE_BACKEND : ${ENABLE_LITE_BACKEND}")
if(ENABLE_PADDLE_BACKEND)
message(STATUS " Paddle Inference version : ${PADDLEINFERENCE_VERSION}")
endif()
if(ENABLE_OPENVINO_BACKEND)
message(STATUS " OpenVINO version : ${OPENVINO_VERSION}")
endif()
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_VISION : ${ENABLE_VISION}")
message(STATUS " ENABLE_TEXT : ${ENABLE_TEXT}")
if(WITH_GPU)
message(STATUS " CUDA_DIRECTORY : ${CUDA_DIRECTORY}")
endif()
if(OPENCV_DIRECTORY)
message(STATUS " OPENCV_DIRECTORY : ${OPENCV_DIRECTORY}")
endif()
if(ORT_DIRECTORY)
message(STATUS " ORT_DIRECTORY : ${ORT_DIRECTORY}")
endif()
if (OPENVINO_DIRECTORY)
message(STATUS " OPENVINO_DIRECTORY : ${OPENVINO_DIRECTORY}")
endif()
if(ANDROID)
message(STATUS " ANDROID_ABI : ${ANDROID_ABI}")
message(STATUS " ANDROID_PLATFORM : ${ANDROID_PLATFORM}")
message(STATUS " ANDROID_NDK : ${ANDROID_NDK}")
message(STATUS " WITH_OPENCV_STATIC: : ${WITH_OPENCV_STATIC}")
if(ENABLE_LITE_BACKEND)
message(STATUS " WITH_LITE_STATIC : ${WITH_LITE_STATIC}")
endif()
endif()
message(STATUS " DEPENDENCY_LIBS : ${FASTDEPLOY_LIBS}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.4.0")
string(STRIP "${CMAKE_CXX_COMPILER_VERSION}" CMAKE_CXX_COMPILER_VERSION)
message(FATAL_ERROR "[ERROR] FastDeploy require g++ version >= 5.4.0, but now your g++ version is ${CMAKE_CXX_COMPILER_VERSION}, this may cause failure! Use -DCMAKE_CXX_COMPILER to define path of your compiler.")
endif()
endif()
# ------------------------------------------------------------------------------- #
# Utils for FastDeploy users. Install all dynamic libs #
# to a specific location, such as exe or dll dir. Usage: #
# install_fastdeploy_libraries(${CMAKE_CURRENT_BINARY_DIR}/Release) #
# ------------------------------------------------------------------------------- #
function(install_fastdeploy_libraries DESTINATION_DIR)
set(DYN_LIB_SUFFIX "*.so*")
if(WIN32)
set(DYN_LIB_SUFFIX "*.dll")
elseif(APPLE)
set(DYN_LIB_SUFFIX "*.dylib*")
endif()
if(FastDeploy_DIR)
file(GLOB_RECURSE ALL_NEED_DYN_LIBS ${FastDeploy_DIR}/${DYN_LIB_SUFFIX})
elseif(FASTDEPLOY_INSTALL_DIR)
file(GLOB_RECURSE ALL_NEED_DYN_LIBS ${FASTDEPLOY_INSTALL_DIR}/${DYN_LIB_SUFFIX})
else()
message(FATAL_ERROR "Please set FastDeploy_DIR/FASTDEPLOY_INSTALL_DIR before call install_fastdeploy_libraries.")
endif()
if(ENABLE_VISION)
file(GLOB_RECURSE ALL_OPENCV_DYN_LIBS ${OpenCV_DIR}/${DYN_LIB_SUFFIX})
list(REMOVE_ITEM ALL_NEED_DYN_LIBS ${ALL_OPENCV_DYN_LIBS})
# Only Install the necessary libraries
if(WIN32)
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/x64/vc15/bin/${DYN_LIB_SUFFIX})
elseif(ANDROID)
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/libs/${ANDROID_ABI}/${DYN_LIB_SUFFIX})
else() # linux/mac
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/lib/${DYN_LIB_SUFFIX})
endif()
file(INSTALL ${OPENCV_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
endif()
# Install other libraries
file(INSTALL ${ALL_NEED_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
endfunction()