forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FastDeploy.cmake.in
450 lines (410 loc) · 18.7 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
# FastDeploy basic infos
set(FASTDEPLOY_VERSION @FASTDEPLOY_VERSION@)
set(LIBRARY_NAME @LIBRARY_NAME@)
# If compile with GLIBC_CXX_ABI=0
set(NEED_ABI0 @NEED_ABI0@)
# Hardware and Language API
set(WITH_GPU @WITH_GPU@)
set(WITH_IPU @WITH_IPU@)
set(WITH_ASCEND @WITH_ASCEND@)
set(WITH_DIRECTML @WITH_DIRECTML@)
set(WITH_TIMVX @WITH_TIMVX@)
set(WITH_KUNLUNXIN @WITH_KUNLUNXIN@)
set(WITH_CAPI @WITH_CAPI@)
set(WITH_CSHARPAPI @WITH_CSHARPAPI@)
set(WITH_TESTING @WITH_TESTING@)
set(BUILD_ON_JETSON @BUILD_ON_JETSON@)
set(RKNN2_TARGET_SOC "@RKNN2_TARGET_SOC@")
# Inference backend and FastDeploy Moudle
set(ENABLE_ORT_BACKEND @ENABLE_ORT_BACKEND@)
set(ENABLE_RKNPU2_BACKEND @ENABLE_RKNPU2_BACKEND@)
set(ENABLE_SOPHGO_BACKEND @ENABLE_SOPHGO_BACKEND@)
set(ENABLE_LITE_BACKEND @ENABLE_LITE_BACKEND@)
set(ENABLE_PADDLE_BACKEND @ENABLE_PADDLE_BACKEND@)
set(ENABLE_OPENVINO_BACKEND @ENABLE_OPENVINO_BACKEND@)
set(ENABLE_POROS_BACKEND @ENABLE_POROS_BACKEND@)
set(ENABLE_TRT_BACKEND @ENABLE_TRT_BACKEND@)
set(ENABLE_PADDLE2ONNX @ENABLE_PADDLE2ONNX@)
set(BUILD_PADDLE2ONNX @BUILD_PADDLE2ONNX@)
set(ENABLE_VISION @ENABLE_VISION@)
set(ENABLE_FLYCV @ENABLE_FLYCV@)
set(ENABLE_CVCUDA @ENABLE_CVCUDA@)
set(ENABLE_TEXT @ENABLE_TEXT@)
set(ENABLE_ENCRYPTION @ENABLE_ENCRYPTION@)
set(ENABLE_BENCHMARK @ENABLE_BENCHMARK@)
# Version infos and custom settings for third libs
set(PADDLEINFERENCE_VERSION @PADDLEINFERENCE_VERSION@)
set(POROS_VERSION @POROS_VERSION@)
set(OPENVINO_VERSION @OPENVINO_VERSION@)
set(OPENCV_FILENAME @OPENCV_FILENAME@)
set(OPENVINO_FILENAME @OPENVINO_FILENAME@)
set(PADDLELITE_FILENAME @PADDLELITE_FILENAME@)
set(OPENCV_DIRECTORY "@OPENCV_DIRECTORY@")
set(ORT_DIRECTORY "@ORT_DIRECTORY@")
set(OPENVINO_DIRECTORY "@OPENVINO_DIRECTORY@")
# Android: specific option for Android OS
set(WITH_ANDROID_STATIC_LIB @WITH_ANDROID_STATIC_LIB@)
set(WITH_ANDROID_LITE_STATIC @WITH_ANDROID_LITE_STATIC@)
set(WITH_ANDROID_OPENCV_STATIC @WITH_ANDROID_OPENCV_STATIC@)
set(WITH_ANDROID_FLYCV_STATIC @WITH_ANDROID_FLYCV_STATIC@)
set(WITH_ANDROID_OPENMP @WITH_ANDROID_OPENMP@)
set(WITH_ANDROID_JAVA @WITH_ANDROID_JAVA@)
set(WITH_ANDROID_TENSOR_FUNCS @WITH_ANDROID_TENSOR_FUNCS@)
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)
# Set C++11 as standard for the whole project
if(NOT MSVC)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-Wno-format")
if(NEED_ABI0)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
else()
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
endif()
endif(NOT MSVC)
# Set FastDeploy static lib definitions
if(WITH_ANDROID_LITE_STATIC)
add_definitions(-DWITH_LITE_STATIC)
add_definitions(-DWITH_ANDROID_LITE_STATIC)
endif()
if(WITH_ANDROID_STATIC_LIB)
add_definitions(-DWITH_STATIC_LIB)
add_definitions(-DWITH_ANDROID_STATIC_LIB)
# add_definitions(-DWITH_STATIC_WARNING)
endif()
# Still need omp while using FastDeploy static lib.
# This is due to the use of openmp for Paddle Lite's
# static library.
if(ANDROID AND WITH_ANDROID_STATIC_LIB AND WITH_ANDROID_LITE_STATIC)
include(${CMAKE_CURRENT_LIST_DIR}/openmp.cmake)
endif()
if(ANDROID)
add_library(fastdeploy STATIC IMPORTED GLOBAL)
if(WITH_ANDROID_STATIC_LIB)
set_property(TARGET fastdeploy PROPERTY IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/lib/${ANDROID_ABI}/lib${LIBRARY_NAME}_static.a)
else()
set_property(TARGET fastdeploy PROPERTY IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/lib/${ANDROID_ABI}/lib${LIBRARY_NAME}.so)
endif()
list(APPEND FASTDEPLOY_LIBS fastdeploy)
if(WITH_ANDROID_OPENMP AND (NOT WITH_ANDROID_LITE_STATIC))
add_library(fastdeploy_omp STATIC IMPORTED GLOBAL)
set_property(TARGET fastdeploy_omp PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/lib/${ANDROID_ABI}/libomp.so)
list(APPEND FASTDEPLOY_LIBS fastdeploy_omp)
endif()
else()
find_library(FDLIB ${LIBRARY_NAME} ${CMAKE_CURRENT_LIST_DIR}/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${FDLIB})
endif()
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()
list(APPEND FASTDEPLOY_LIBS ${PADDLE_LIB})
if(EXISTS "${DNNL_LIB}")
list(APPEND FASTDEPLOY_LIBS ${DNNL_LIB} ${IOMP_LIB})
endif()
endif()
if(ENABLE_OPENVINO_BACKEND)
if (OPENVINO_DIRECTORY)
set(OPENVINO_DIR ${OPENVINO_DIRECTORY})
else()
set(OPENVINO_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/${OPENVINO_FILENAME}/runtime)
endif()
get_openvino_libs(${OPENVINO_DIR})
message(STATUS "OPENVINO_LIBS = ${OPENVINO_LIBS}")
list(APPEND FASTDEPLOY_LIBS ${OPENVINO_LIBS})
endif()
if(ENABLE_RKNPU2_BACKEND)
if(RKNN2_TARGET_SOC STREQUAL "RK356X")
set(RKNPU2_LIB ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/rknpu2_runtime/lib/librknnrt.so)
elseif (RKNN2_TARGET_SOC STREQUAL "RK3588")
set(RKNPU2_LIB ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/rknpu2_runtime/lib/librknnrt.so)
else ()
message(FATAL_ERROR "RKNN2_TARGET_SOC is not set, ref value: RK356X or RK3588")
endif()
message(STATUS "The path of RKNPU2 is ${RKNPU2_LIB}.")
list(APPEND FASTDEPLOY_LIBS ${RKNPU2_LIB})
endif()
if(ENABLE_LITE_BACKEND)
set(LITE_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/${PADDLELITE_FILENAME})
if(ANDROID)
if(WITH_ANDROID_LITE_STATIC)
if(WITH_ANDROID_STATIC_LIB)
list(APPEND FASTDEPLOY_INCS ${LITE_DIR}/include)
endif()
else()
add_library(paddle_full_api_shared STATIC IMPORTED GLOBAL)
set_property(TARGET paddle_full_api_shared PROPERTY IMPORTED_LOCATION ${LITE_DIR}/lib/${ANDROID_ABI}/libpaddle_full_api_shared.so)
list(APPEND FASTDEPLOY_LIBS paddle_full_api_shared)
endif()
else()
# Linux/Mac/Win/...
find_library(LITE_LIB paddle_full_api_shared ${LITE_DIR}/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${LITE_LIB})
endif()
endif()
if(ENABLE_POROS_BACKEND)
find_library(POROS_LIB poros ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/poros/lib NO_DEFAULT_PATH)
find_library(TORCH_LIB torch ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/torch/lib NO_DEFAULT_PATH)
set(TORCH_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/torch/include")
list(APPEND FASTDEPLOY_LIBS ${POROS_LIB} ${TORCH_LIB})
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/poros/include ${TORCH_INCLUDE})
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)
find_library(NVJPEG_LIB nvjpeg ${CUDA_DIRECTORY}/lib/x64)
else()
find_library(CUDA_LIB cudart ${CUDA_DIRECTORY}/lib64)
if(NOT BUILD_ON_JETSON)
find_library(NVJPEG_LIB nvjpeg ${CUDA_DIRECTORY}/lib64)
endif()
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} ${NVJPEG_LIB})
list(APPEND FASTDEPLOY_INCS ${CUDA_DIRECTORY}/include)
if(ENABLE_TRT_BACKEND)
if(BUILD_ON_JETSON)
find_library(TRT_INFER_LIB nvinfer /usr/lib/aarch64-linux-gnu/)
find_library(TRT_ONNX_LIB nvonnxparser /usr/lib/aarch64-linux-gnu/)
find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/lib/aarch64-linux-gnu/)
else()
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/)
find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib NO_DEFAULT_PATH)
else()
find_library(TRT_INFER_LIB nvinfer /usr/lib/x86_64-linux-gnu/)
find_library(TRT_ONNX_LIB nvonnxparser /usr/lib/x86_64-linux-gnu/)
find_library(TRT_PLUGIN_LIB nvinfer_plugin /usr/lib/x86_64-linux-gnu/)
endif()
endif()
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_FILENAME}/sdk/native/jni)
set(OpenCV_NATIVE_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/${OPENCV_FILENAME}/sdk/native)
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}.")
if(ANDROID)
if(WITH_ANDROID_OPENCV_STATIC)
if(WITH_ANDROID_STATIC_LIB)
# Only need the headers of opencv while using FastDeploy static lib.
list(APPEND FASTDEPLOY_INCS ${OpenCV_DIR}/include)
else()
find_package(OpenCV REQUIRED PATHS ${OpenCV_DIR})
list(APPEND FASTDEPLOY_INCS ${OpenCV_INCLUDE_DIRS})
# For now, we still need to link OpenCV static libs.
# Users may use some of opencv's apis, but they may
# not have been compiled into fastdeploy.
# list(APPEND FASTDEPLOY_LIBS ${OpenCV_LIBS})
list(APPEND FASTDEPLOY_LIBS opencv_core opencv_video opencv_highgui opencv_imgproc opencv_imgcodecs)
endif()
else()
set(OpenCV_INCLUDE_DIRS ${OpenCV_DIR}/include)
get_filename_component(OpenCV_NATIVE_DIR ${OpenCV_DIR} DIRECTORY)
set(OpenCV_LIBS_DIR ${OpenCV_NATIVE_DIR}/libs)
if(ANDROID_TOOLCHAIN MATCHES "clang") # use opencv 4.x
add_library(opencv_java4 STATIC IMPORTED GLOBAL)
set_property(TARGET opencv_java4 PROPERTY IMPORTED_LOCATION ${OpenCV_LIBS_DIR}/${ANDROID_ABI}/libopencv_java4.so)
list(APPEND FASTDEPLOY_LIBS opencv_java4)
elseif(ANDROID_TOOLCHAIN MATCHES "gcc") # use opencv 3.x
add_library(opencv_java3 STATIC IMPORTED GLOBAL)
set_property(TARGET opencv_java3 PROPERTY IMPORTED_LOCATION ${OpenCV_LIBS_DIR}/${ANDROID_ABI}/opencv_java3.so)
list(APPEND FASTDEPLOY_LIBS opencv_java3)
else()
message(FATAL_ERROR "Only support clang/gcc toolchain, but found ${ANDROID_TOOLCHAIN}.")
endif()
list(APPEND FASTDEPLOY_INCS ${OpenCV_INCLUDE_DIRS})
message(STATUS "FASTDEPLOY_INCS: ${FASTDEPLOY_INCS}")
endif()
# Win/Linux/Mac
else()
find_package(OpenCV REQUIRED PATHS ${OpenCV_DIR} NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_INCS ${OpenCV_INCLUDE_DIRS})
list(APPEND FASTDEPLOY_LIBS ${OpenCV_LIBS})
endif()
if(ENABLE_FLYCV)
include_directories(${CMAKE_CURRENT_LIST_DIR}/third_libs/install/flycv/include)
set(FLYCV_LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/flycv/lib)
if(ANDROID)
if(NOT WITH_ANDROID_FLYCV_STATIC)
add_library(flycv_shared STATIC IMPORTED GLOBAL)
set_property(TARGET flycv_shared PROPERTY IMPORTED_LOCATION ${FLYCV_LIB_DIR}/${ANDROID_ABI}/libflycv_shared.so)
list(APPEND FASTDEPLOY_LIBS flycv_shared)
else()
# This code may be needed later. Therefore, I choose to
# comment it rather than delete it. (TODO:qiuyanjun)
# add_library(flycv_static STATIC IMPORTED GLOBAL)
# add_library(flycv_png16 STATIC IMPORTED GLOBAL)
# add_library(flycv_turbojpeg STATIC IMPORTED GLOBAL)
# add_library(flycv_z STATIC IMPORTED GLOBAL)
# set_property(TARGET flycv_static PROPERTY IMPORTED_LOCATION ${FLYCV_LIB_DIR}/${ANDROID_ABI}/libflycv_static.a)
# set_property(TARGET flycv_png16 PROPERTY IMPORTED_LOCATION ${FLYCV_LIB_DIR}/${ANDROID_ABI}/libpng16.a)
# set_property(TARGET flycv_turbojpeg PROPERTY IMPORTED_LOCATION ${FLYCV_LIB_DIR}/${ANDROID_ABI}/libturbojpeg.a)
# set_property(TARGET flycv_z PROPERTY IMPORTED_LOCATION ${FLYCV_LIB_DIR}/${ANDROID_ABI}/libz.a)
# list(APPEND FASTDEPLOY_LIBS flycv_static)
# list(APPEND FASTDEPLOY_LIBS flycv_png16)
# list(APPEND FASTDEPLOY_LIBS flycv_turbojpeg)
# list(APPEND FASTDEPLOY_LIBS flycv_z)
endif()
else()
find_library(FLYCV_LIB flycv_shared ${FLYCV_LIB_DIR} NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${FLYCV_LIB})
endif()
endif()
if(ENABLE_CVCUDA)
find_library(CVCUDA_LIB cvcuda ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/cvcuda/lib NO_DEFAULT_PATH)
find_library(NVCV_TYPES_LIB nvcv_types ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/cvcuda/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${CVCUDA_LIB} ${NVCV_TYPES_LIB})
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/cvcuda/include NO_DEFAULT_PATH)
add_definitions(-DENABLE_CVCUDA)
endif()
endif()
if (ENABLE_TEXT)
if(ANDROID)
if(NOT ANDROID_TOOLCHAIN MATCHES "clang")
message(FATAL_ERROR "Currently, only support clang toolchain while cross compiling FastDeploy for Android with FastTokenizer, but found ${ANDROID_TOOLCHAIN}.")
endif()
add_library(core_tokenizers STATIC IMPORTED GLOBAL)
set_property(TARGET core_tokenizers PROPERTY IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/third_libs/install/fast_tokenizer/lib/${ANDROID_ABI}/libcore_tokenizers.so)
list(APPEND FASTDEPLOY_LIBS core_tokenizers)
else()
# Add dependency libs later: Linux/Mac/Win/...
find_library(FAST_TOKENIZER_LIB core_tokenizers ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/fast_tokenizer/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${FAST_TOKENIZER_LIB})
endif()
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/fast_tokenizer/include)
list(APPEND FASTDEPLOY_INCS ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/fast_tokenizer/third_party/include)
endif()
if(ENABLE_PADDLE2ONNX)
if(ANDROID)
message(FATAL_ERROR "Not support fastdeploy-paddle2onnx APIs with Android now!")
endif()
if(NOT BUILD_PADDLE2ONNX)
find_library(PADDLE2ONNX_LIB paddle2onnx ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle2onnx/lib NO_DEFAULT_PATH)
list(APPEND FASTDEPLOY_LIBS ${PADDLE2ONNX_LIB})
endif()
endif()
if(WITH_KUNLUNXIN)
list(APPEND FASTDEPLOY_LIBS -lpthread -lrt -ldl)
endif()
# log lib for Android
if(ANDROID)
find_library(log-lib log)
list(APPEND FASTDEPLOY_LIBS ${log-lib})
endif()
# Update CXX LINKER's FLAGS, reference: https://zhuanlan.zhihu.com/p/595527528
if(ANDROID AND (WITH_ANDROID_OPENCV_STATIC OR WITH_ANDROID_LITE_STATIC))
set(COMMON_LINK_FLAGS_REL "-Wl,-s,--gc-sections,-exclude-libs,ALL")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${COMMON_LINK_FLAGS_REL} -Wl,-allow-multiple-definition" CACHE INTERNAL "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COMMON_LINK_FLAGS_REL} -Wl,-allow-multiple-definition" CACHE INTERNAL "" FORCE)
endif()
remove_duplicate_libraries(FASTDEPLOY_LIBS)
include(${CMAKE_CURRENT_LIST_DIR}/summary.cmake)
fastdeploy_summary()
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()
function(install_fastdeploy_libraries DESTINATION_DIR)
# No dynamic libs need to install while using
# FastDeploy static lib.
if(ANDROID AND WITH_ANDROID_STATIC_LIB)
return()
endif()
set(DYN_LIB_SUFFIX "*.so*")
if(WIN32)
set(DYN_LIB_SUFFIX "*.dll")
elseif(APPLE)
set(DYN_LIB_SUFFIX "*.dylib*")
endif()
if(FastDeploy_DIR)
set(DYN_SEARCH_DIR ${FastDeploy_DIR})
elseif(FASTDEPLOY_INSTALL_DIR)
set(DYN_SEARCH_DIR ${FASTDEPLOY_INSTALL_DIR})
else()
message(FATAL_ERROR "Please set FastDeploy_DIR/FASTDEPLOY_INSTALL_DIR before call install_fastdeploy_libraries.")
endif()
file(GLOB_RECURSE ALL_NEED_DYN_LIBS ${DYN_SEARCH_DIR}/lib/${DYN_LIB_SUFFIX})
file(GLOB_RECURSE ALL_DEPS_DYN_LIBS ${DYN_SEARCH_DIR}/third_libs/${DYN_LIB_SUFFIX})
if(ENABLE_VISION)
# OpenCV
if(ANDROID)
file(GLOB_RECURSE ALL_OPENCV_DYN_LIBS ${OpenCV_NATIVE_DIR}/libs/${DYN_LIB_SUFFIX})
else()
file(GLOB_RECURSE ALL_OPENCV_DYN_LIBS ${OpenCV_DIR}/${DYN_LIB_SUFFIX})
endif()
list(REMOVE_ITEM ALL_DEPS_DYN_LIBS ${ALL_OPENCV_DYN_LIBS})
if(WIN32)
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/x64/vc15/bin/${DYN_LIB_SUFFIX})
file(INSTALL ${OPENCV_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
elseif(ANDROID AND (NOT WITH_ANDROID_OPENCV_STATIC))
file(GLOB OPENCV_DYN_LIBS ${OpenCV_NATIVE_DIR}/libs/${ANDROID_ABI}/${DYN_LIB_SUFFIX})
file(INSTALL ${OPENCV_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
else() # linux/mac
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/lib/${DYN_LIB_SUFFIX})
file(INSTALL ${OPENCV_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
endif()
# FlyCV
if(ENABLE_FLYCV)
file(GLOB_RECURSE ALL_FLYCV_DYN_LIBS ${FLYCV_LIB_DIR}/${DYN_LIB_SUFFIX})
list(REMOVE_ITEM ALL_DEPS_DYN_LIBS ${ALL_FLYCV_DYN_LIBS})
if(ANDROID AND (NOT WITH_ANDROID_FLYCV_STATIC))
file(INSTALL ${ALL_FLYCV_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
endif()
endif()
endif()
if(ENABLE_OPENVINO_BACKEND)
# need plugins.xml for openvino backend
set(OPENVINO_RUNTIME_BIN_DIR ${OPENVINO_DIR}/bin)
file(GLOB OPENVINO_PLUGIN_XML ${OPENVINO_RUNTIME_BIN_DIR}/*.xml)
file(INSTALL ${OPENVINO_PLUGIN_XML} DESTINATION ${DESTINATION_DIR})
endif()
# Install other libraries
file(INSTALL ${ALL_NEED_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
file(INSTALL ${ALL_DEPS_DYN_LIBS} DESTINATION ${DESTINATION_DIR})
endfunction()