-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
119 lines (101 loc) · 3.73 KB
/
CMakeLists.txt
File metadata and controls
119 lines (101 loc) · 3.73 KB
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
cmake_minimum_required(VERSION 3.8)
project(yolox_cpp)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()
option(YOLOX_USE_OPENVINO "Use OpenVINO" OFF)
option(YOLOX_USE_TENSORRT "Use TensorRT" OFF)
option(YOLOX_USE_ONNXRUNTIME "Use ONNXRuntime" OFF)
option(ONNXRUNTIME_CUDA "Use ONNXRuntime CUDA Execution Provider" OFF)
option(ONNXRUNTIME_MIGRAPHX "Use ONNXRuntime MIGraphX Execution Provider" OFF)
option(YOLOX_USE_TFLITE "Use tflite" OFF)
option(JETSON "Use Jetson" OFF)
if(JETSON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include/aarch64-linux-gnu/ -L/usr/lib/aarch64-linux-gnu/")
set(YOLOX_USE_TENSORRT ON)
endif()
if(NOT YOLOX_USE_OPENVINO AND NOT YOLOX_USE_TENSORRT AND NOT YOLOX_USE_ONNXRUNTIME AND NOT YOLOX_USE_TFLITE)
message(FATAL_ERROR "YOLOX_USE_OPENVINO, YOLOX_USE_TENSORRT, YOLOX_USE_ONNXRUNTIME, YOLOX_USE_TFLITE must be ON at least one")
return()
endif()
set(ENABLE_OPENVINO OFF)
set(ENABLE_TENSORRT OFF)
set(ENABLE_ONNXRUNTIME OFF)
set(ENABLE_ONNXRUNTIME_CUDA OFF)
set(ENABLE_ONNXRUNTIME_MIGRAPHX OFF)
set(ENABLE_TFLITE OFF)
if(YOLOX_USE_OPENVINO)
find_package(OpenVINO REQUIRED)
set(ENABLE_OPENVINO ON)
set(TARGET_SRC ${TARGET_SRC} src/yolox_openvino.cpp)
set(TARGET_LIBS ${TARGET_LIBS} openvino::runtime)
set(TARGET_DPENDENCIES ${TARGET_DPENDENCIES} OpenVINO)
endif()
if(YOLOX_USE_TENSORRT)
find_package(CUDA REQUIRED)
if (NOT CUDA_TOOLKIT_ROOT_DIR)
set(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda)
endif()
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES include)
set(ENABLE_TENSORRT ON)
set(TARGET_SRC ${TARGET_SRC} src/yolox_tensorrt.cpp)
set(TARGET_LIBS ${TARGET_LIBS} nvinfer nvinfer_plugin)
set(TARGET_DPENDENCIES ${TARGET_DPENDENCIES} CUDA)
endif()
# tflite
if(YOLOX_USE_TFLITE)
set(ENABLE_TFLITE ON)
set(TARGET_SRC ${TARGET_SRC} src/yolox_tflite.cpp)
set(TFLITE_INCLUDES
${TFLITE_INCLUDE_DIR}
${ABSEIL_CPP_ICLUDE_DIR}
${FLATBUFFERS_INCLUDE_DIR}
)
set(TARGET_LIBS ${TARGET_LIBS} ${TFLITE_LIB_PATH}/libtensorflow-lite.so)
endif()
# onnxruntime
if(YOLOX_USE_ONNXRUNTIME)
find_library(ONNXRUNTIME NAMES onnxruntime)
if(ONNXRUNTIME_CUDA AND ONNXRUNTIME_MIGRAPHX)
message(FATAL_ERROR "ONNXRUNTIME_CUDA and ONNXRUNTIME_MIGRAPHX cannot both be ON")
endif()
set(ENABLE_ONNXRUNTIME ON)
if(ONNXRUNTIME_CUDA)
set(ENABLE_ONNXRUNTIME_CUDA ON)
set(TARGET_DEFINITIONS ${TARGET_DEFINITIONS} ONNXRUNTIME_CUDA)
endif()
if(ONNXRUNTIME_MIGRAPHX)
set(ENABLE_ONNXRUNTIME_MIGRAPHX ON)
set(TARGET_DEFINITIONS ${TARGET_DEFINITIONS} ONNXRUNTIME_MIGRAPHX)
endif()
set(TARGET_SRC ${TARGET_SRC} src/yolox_onnxruntime.cpp)
set(TARGET_LIBS ${TARGET_LIBS} onnxruntime)
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h.in"
"${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h"
)
ament_auto_add_library(yolox_cpp SHARED ${TARGET_SRC})
ament_target_dependencies(yolox_cpp ${TARGET_DPENDENCIES})
ament_export_dependencies(${TARGET_DPENDENCIES})
target_link_libraries(yolox_cpp ${TARGET_LIBS})
target_compile_definitions(yolox_cpp PUBLIC ${TARGET_DEFINITIONS})
if (YOLOX_USE_TFLITE)
target_include_directories(yolox_cpp PUBLIC ${TFLITE_INCLUDES})
ament_export_include_directories(${TFLITE_INCLUDES})
install(DIRECTORY ${TFLITE_LIB_PATH}/ DESTINATION lib)
endif()
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()
ament_auto_package()