-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathCMakeLists.txt
353 lines (304 loc) · 13.9 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.10)
project(InspireFace)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
# Current version
set(INSPIRE_FACE_VERSION_MAJOR 1)
set(INSPIRE_FACE_VERSION_MINOR 2)
set(INSPIRE_FACE_VERSION_PATCH 0)
# Converts the version number to a string
string(CONCAT INSPIRE_FACE_VERSION_MAJOR_STR ${INSPIRE_FACE_VERSION_MAJOR})
string(CONCAT INSPIRE_FACE_VERSION_MINOR_STR ${INSPIRE_FACE_VERSION_MINOR})
string(CONCAT INSPIRE_FACE_VERSION_PATCH_STR ${INSPIRE_FACE_VERSION_PATCH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/information.h.in ${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/information.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/version.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/cpp/inspireface/version.txt)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/version.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/python/version.txt)
# Check that the 3rdparty folder exists
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty")
message(STATUS "3rdparty directory not found, cloning from github...")
# Execute git clone and directly specify it in the current directory
execute_process(
COMMAND git clone --recurse-submodules https://github.com/tunmx/inspireface-3rdparty.git "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_RESULT
)
if(NOT GIT_RESULT EQUAL "0")
message(FATAL_ERROR "Failed to clone 3rdparty repository")
else()
message(STATUS "Successfully cloned 3rdparty repository")
endif()
else()
message(STATUS "3rdparty directory already exists")
endif()
# Set the ISF_THIRD_PARTY_DIR variable to allow it to be set externally from the command line, or use the default path if it is not set
set(ISF_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty" CACHE PATH "Path to the third-party libraries directory")
# Check that the SANITIZE compile option is enabled
set(ISF_SANITIZE_ADDRESS OFF CACHE BOOL "Enable AddressSanitizer")
set(ISF_SANITIZE_LEAK OFF CACHE BOOL "Enable LeakSanitizer")
if (ISF_SANITIZE_ADDRESS AND ISF_SANITIZE_LEAK)
message(FATAL_ERROR "Cannot enable both AddressSanitizer and LeakSanitizer.")
endif()
# Enable AddressSanitizer
if(ISF_SANITIZE_ADDRESS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
# Enable LeakSanitizer
if(ISF_SANITIZE_LEAK)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=leak")
endif()
set(TARGET_PLATFORM "drawin-x86" CACHE STRING "Target platform")
# TensorRT dependency configuration
set(ISF_ENABLE_TENSORRT OFF CACHE BOOL "Enable TensorRT Inference")
set(TENSORRT_ROOT "/usr/local/TensorRT" CACHE PATH "Path to TensorRT installation")
if(ISF_ENABLE_TENSORRT)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/toolchain)
include(FindTensorRT)
add_definitions("-DISF_ENABLE_TENSORRT")
add_definitions("-DINFERENCE_WRAPPER_ENABLE_TENSORRT")
endif()
# RKNN dependency configuration
option(ISF_ENABLE_RKNN "Use RKNPU." OFF)
set(ISF_RK_DEVICE_TYPE "RV1109RV1126" CACHE STRING "Type of the device")
set(ISF_RK_COMPILER_TYPE "armhf" CACHE STRING "Type of the compiler")
if (ISF_ENABLE_RKNN)
add_definitions("-DISF_ENABLE_RKNN")
# Device list
set(RKNPU1_DEVICES "RV1109RV1126")
set(RKNPU2_DEVICES "RK356X" "RK3588" "RV1106")
set(ISF_RKNPU_MAJOR "")
list(FIND RKNPU1_DEVICES "${ISF_RK_DEVICE_TYPE}" INDEX_RKNPU1)
list(FIND RKNPU2_DEVICES "${ISF_RK_DEVICE_TYPE}" INDEX_RKNPU2)
if(INDEX_RKNPU1 GREATER_EQUAL 0)
# match rknn1
set(ISF_RKNPU_MAJOR "rknpu1")
elseif(INDEX_RKNPU2 GREATER_EQUAL 0)
# match rknn2
set(ISF_RKNPU_MAJOR "rknpu2")
endif()
# Result
message(STATUS "Use ${ISF_RKNPU_MAJOR}")
if(ISF_RK_DEVICE_TYPE STREQUAL "RV1106")
set(ISF_RKNPU_RV1106 ON)
add_definitions("-DISF_RKNPU_RV1106")
endif()
endif ()
# Enable Rockchip RGA
option(ISF_ENABLE_RGA "Use Rockchip RGA." OFF)
if(ISF_ENABLE_RGA)
if(NOT ISF_ENABLE_RKNN)
message(FATAL_ERROR "RGA requires RKNN to be enabled. Please enable ISF_ENABLE_RKNN first.")
endif()
if(NOT ISF_RKNPU_MAJOR STREQUAL "rknpu2")
message(FATAL_ERROR "RGA requires RKNPU2. Please use a device that supports RKNPU2.")
endif()
add_definitions("-DISF_ENABLE_RGA")
if(ANDROID)
set(PLAT Android)
else()
set(PLAT Linux)
endif()
set(RGA_LIBS ${ISF_THIRD_PARTY_DIR}/inspireface-precompile-lite/librga/${PLAT}/${ISF_RK_COMPILER_TYPE}/librga.a)
set(RGA_INCLUDE_DIRS ${ISF_THIRD_PARTY_DIR}/inspireface-precompile-lite/librga/include)
endif()
option(ISF_ENABLE_COST_TIME "Enable cost time." OFF)
if(ISF_ENABLE_COST_TIME)
add_definitions("-DISF_ENABLE_COST_TIME")
endif()
# Apple device dedicated expansion services, support for some models coreml reasoning and so on
set(ISF_ENABLE_APPLE_EXTENSION OFF CACHE BOOL "Enable Apple device extension services, such as coreml, etc.")
if(ISF_ENABLE_APPLE_EXTENSION)
add_definitions("-DISF_ENABLE_APPLE_EXTENSION")
add_definitions("-DINFERENCE_WRAPPER_ENABLE_COREML")
endif()
# Platform configuration
option(ISF_BUILD_LINUX_ARM7 "Platform Armv7." OFF)
option(ISF_BUILD_LINUX_AARCH64 "Platform Armv8." OFF)
option(ISF_GLOBAL_INFERENCE_BACKEND_USE_MNN_CUDA "The global inference backend uses MNN CUDA." OFF)
if (ISF_BUILD_LINUX_ARM7)
set(CPU_ARCH "armhf")
endif()
if (ISF_BUILD_LINUX_AARCH64)
set(CPU_ARCH "aarch64")
endif()
# If you want to build the unit-test, you need to set this to ON
option(ISF_BUILD_WITH_TEST "Open Build Unit-Test." ON)
# If you want to build the sample, you need to set this to ON
option(ISF_BUILD_WITH_SAMPLE "Open Build Sample Exec." ON)
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp/)
option(ISF_NEVER_USE_OPENCV "Never use opencv." ON)
if(ISF_NEVER_USE_OPENCV)
set(INSPIRECV_BACKEND_OPENCV OFF)
set(INSPIRECV_BACKEND_OKCV_USE_OPENCV OFF)
set(INSPIRECV_BACKEND_OKCV_USE_OPENCV_IO OFF)
set(INSPIRECV_BACKEND_OKCV_USE_OPENCV_GUI OFF)
endif()
option(ISF_ENABLE_OPENCV "Depends on opencv." OFF)
if(INSPIRECV_BACKEND_OPENCV OR INSPIRECV_BACKEND_OKCV_USE_OPENCV OR INSPIRECV_BACKEND_OKCV_USE_OPENCV_IO OR INSPIRECV_BACKEND_OKCV_USE_OPENCV_GUI)
set(ISF_ENABLE_OPENCV ON)
endif()
include_directories(${ISF_THIRD_PARTY_DIR}/InspireCV/3rdparty/Eigen-3.4.0-Headers)
if(APPLE)
if(IOS)
add_definitions(-DTARGET_OS_IOS)
message(IOS_3RDPARTY=${IOS_3RDPARTY})
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO)
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO)
add_definitions(-DTARGET_OS_IOS)
message(IOS_3RDPARTY=${IOS_3RDPARTY})
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO)
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO)
set(MNN_FRAMEWORK_PATH "${IOS_3RDPARTY}/MNN.framework")
include_directories("${MNN_FRAMEWORK_PATH}/")
link_directories(${IOS_3RDPARTY})
else()
message("Use apple device")
set(PLAT darwin)
endif()
else()
message("Use linux device")
set(PLAT linux)
endif()
# OpenCV dependency configuration
if(ISF_ENABLE_OPENCV)
if (APPLE)
if (IOS)
link_directories(${IOS_3RDPARTY})
include_directories(${IOS_3RDPARTY}/opencv2.framework)
set(OpenCV_DIR "${IOS_3RDPARTY}/opencv2.framework")
else()
message("Use apple device")
set(PLAT darwin)
find_package(OpenCV REQUIRED)
endif ()
else()
if (ISF_BUILD_LINUX_ARM7 OR ISF_BUILD_LINUX_AARCH64)
set(DISABLE_GUI ON)
add_definitions("-DDISABLE_GUI")
# set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/opencv/opencv-linux-armhf/share/OpenCV)
# set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/opencv/opencv-linux-armhf/include/)
if (ISF_RK_DEVICE_TYPE STREQUAL "RV1109RV1126" AND ISF_ENABLE_RKNN)
# In special cases, specialize for that version
message("The OpenCV that builds the RV1109RV1126 version depends on is specialized!")
set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/share/OpenCV)
set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/include/)
set(PLAT linux-arm7)
else()
if (VERSION_MAJOR STREQUAL "3")
set(CV_CMAKE_FOLDER share/OpenCV)
elseif(VERSION_MAJOR STREQUAL "4")
set(CV_CMAKE_FOLDER lib/cmake/opencv4)
endif ()
if(ISF_BUILD_LINUX_ARM7)
set(PLAT linux-arm7)
message("The OpenCV that builds the gnueabihf version depends on is specialized!")
set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/share/OpenCV)
set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/include/)
elseif(ISF_BUILD_LINUX_AARCH64)
set(PLAT linux-aarch64)
message("The OpenCV that builds the aarch64 version depends on is specialized!")
set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/opencv/3.4.5/opencv-linux-aarch64/share/OpenCV)
set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/inspireface-precompile/opencv/3.4.5/opencv-linux-aarch64/include/)
endif()
endif()
else ()
set(PLAT linux)
endif ()
find_package(OpenCV REQUIRED)
endif ()
endif ()
# InspireCV dependency configuration
set(INSPIRECV_BUILD_OBJECT_LIBS OFF CACHE BOOL "Build InspireCV as object library")
add_subdirectory(${ISF_THIRD_PARTY_DIR}/InspireCV EXCLUDE_FROM_ALL)
set(INSPIRECV_INCLUDE_PATH "${ISF_THIRD_PARTY_DIR}/InspireCV/include")
set(INSPIRECV_LIBS InspireCV)
# If you need using CUDA-enabled MNN, you need to manually configure the pre-compiled CUDA-enabled MNN library path
set(ISF_LINUX_MNN_CUDA "" CACHE STRING "Path to CUDA directory")
if (ISF_GLOBAL_INFERENCE_BACKEND_USE_MNN_CUDA)
message("Global MNN CUDA device inference")
add_definitions("-DISF_GLOBAL_INFERENCE_BACKEND_USE_MNN_CUDA")
# Use MNN Cuda
if (NOT DEFINED ISF_LINUX_MNN_CUDA)
# MNN Options
set(MNN_CUDA ON)
add_subdirectory(${ISF_THIRD_PARTY_DIR}/MNN EXCLUDE_FROM_ALL)
set(MNN_INCLUDE_DIRS "${ISF_THIRD_PARTY_DIR}/MNN/include")
set(MNN_LIBS MNN)
else()
message(ISF_LINUX_MNN_CUDA=${ISF_LINUX_MNN_CUDA})
set(MNN_INCLUDE_DIRS ${ISF_LINUX_MNN_CUDA}/include)
link_directories(${ISF_LINUX_MNN_CUDA}/)
set(MNN_LIBS MNN)
endif()
elseif(DEFINED MNN_STATIC_PATH)
message("Using static MNN from specified path: ${MNN_STATIC_PATH}")
set(MNN_INCLUDE_DIRS "${MNN_STATIC_PATH}/include")
set(MNN_LIBS "${MNN_STATIC_PATH}/lib/libMNN.a")
elseif(IOS)
message(Build iOS)
elseif(DEFINED ISF_MNN_CUSTOM_SOURCE)
message("Using custom external MNN source path: ${ISF_MNN_CUSTOM_SOURCE}")
# In particular, rknpu2 uses a lower version of mnn
set(MNN_BUILD_SHARED_LIBS OFF CACHE BOOL "Build MNN as a shared library")
add_subdirectory(${ISF_MNN_CUSTOM_SOURCE} EXCLUDE_FROM_ALL)
set(MNN_INCLUDE_DIRS "${ISF_MNN_CUSTOM_SOURCE}/include")
set(MNN_LIBS MNN)
else ()
# Default or fallback case for MNN setup
message("Default or fallback case for MNN setup")
# MNN Options
set(MNN_BUILD_SHARED_LIBS OFF CACHE BOOL "Build MNN as a shared library")
add_subdirectory(${ISF_THIRD_PARTY_DIR}/MNN EXCLUDE_FROM_ALL)
set(MNN_INCLUDE_DIRS "${ISF_THIRD_PARTY_DIR}/MNN/include")
set(MNN_LIBS MNN)
endif ()
# Set the installation directory to the build directory
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")
# Add a child project: InspireFace Source
add_subdirectory(cpp/inspireface)
get_property(InspireFace TARGET InspireFace PROPERTY InspireFace)
# Add a child project: Samples
if (ISF_BUILD_WITH_SAMPLE)
add_subdirectory(cpp/sample) # Add a child project: Samples
endif ()
# Add a child project: Unit-Test
if (ISF_BUILD_WITH_TEST)
add_subdirectory(cpp/test) # Add a child project: Unit-Test
endif ()
# Print Message
message(STATUS ">>>>>>>>>>>>>")
message(STATUS "InspireFace Project Global:")
message(STATUS "\t CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message(STATUS "\t CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "\t ISF_THIRD_PARTY_DIR: ${ISF_THIRD_PARTY_DIR}")
message(STATUS "\t ISF_SANITIZE_ADDRESS: ${ISF_SANITIZE_ADDRESS}")
message(STATUS "\t ISF_SANITIZE_LEAK: ${ISF_SANITIZE_LEAK}")
message(STATUS "\t ISF_ENABLE_RKNN: ${ISF_ENABLE_RKNN}")
if (ISF_ENABLE_RKNN)
message(STATUS "\t ISF_RKNPU_MAJOR: ${ISF_RKNPU_MAJOR}")
message(STATUS "\t ISF_RK_DEVICE_TYPE: ${ISF_RK_DEVICE_TYPE}")
message(STATUS "\t ISF_RK_COMPILER_TYPE: ${ISF_RK_COMPILER_TYPE}")
if(ISF_RKNPU_RV1106)
message(STATUS "\t ISF_RKNPU_RV1106: ${ISF_RKNPU_RV1106}")
endif()
endif ()
message(STATUS "\t ISF_BUILD_LINUX_ARM7: ${ISF_BUILD_LINUX_ARM7}")
message(STATUS "\t ISF_BUILD_LINUX_AARCH64: ${ISF_BUILD_LINUX_AARCH64}")
message(STATUS "\t ISF_BUILD_WITH_TEST: ${ISF_BUILD_WITH_TEST}")
message(STATUS "\t ISF_BUILD_WITH_SAMPLE: ${ISF_BUILD_WITH_SAMPLE}")
message(STATUS "\t OpenCV_DIR: ${OpenCV_DIR}")
if(ISF_ENABLE_OPENCV)
message(STATUS "\t OpenCV: Enabled")
else()
message(STATUS "\t OpenCV: Disabled")
endif()
if(ISF_ENABLE_APPLE_EXTENSION)
message(STATUS "\t ISF_ENABLE_APPLE_EXTENSION: ${ISF_ENABLE_APPLE_EXTENSION}")
endif()
message(STATUS "\t CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")