|
1 | | -cmake_minimum_required(VERSION 3.5) |
| 1 | +cmake_minimum_required(VERSION 3.8) |
2 | 2 | project(yolox_cpp) |
3 | 3 |
|
4 | | -# Default to C99 |
5 | | -if(NOT CMAKE_C_STANDARD) |
6 | | - set(CMAKE_C_STANDARD 99) |
7 | | -endif() |
8 | | - |
9 | | -# Default to C++17 |
10 | 4 | if(NOT CMAKE_CXX_STANDARD) |
11 | 5 | set(CMAKE_CXX_STANDARD 17) |
| 6 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 7 | + set(CMAKE_CXX_EXTENSIONS OFF) |
12 | 8 | endif() |
13 | 9 |
|
14 | 10 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
15 | 11 | add_compile_options(-Wall -Wextra -Wpedantic) |
16 | 12 | endif() |
17 | 13 |
|
18 | | -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 14 | +find_package(ament_cmake_auto REQUIRED) |
| 15 | +ament_auto_find_build_dependencies() |
19 | 16 |
|
20 | | -# build option |
21 | | -option(YOLOX_USE_OPENVINO "Use OpenVINO" ON) |
22 | | -option(YOLOX_USE_TENSORRT "Use TensorRT" ON) |
23 | | -option(YOLOX_USE_ONNXRUNTIME "Use ONNXRuntime" ON) |
| 17 | +option(YOLOX_USE_OPENVINO "Use OpenVINO" OFF) |
| 18 | +option(YOLOX_USE_TENSORRT "Use TensorRT" OFF) |
| 19 | +option(YOLOX_USE_ONNXRUNTIME "Use ONNXRuntime" OFF) |
24 | 20 | option(YOLOX_USE_TFLITE "Use tflite" OFF) |
25 | | -set(TFLITE_LIB_PATH "" CACHE PATH "Path to libtensorflow-lite.so") |
26 | | -set(TFLITE_INCLUDE_DIR "" CACHE PATH "Header directory of tflite") |
27 | | -set(ABSEIL_CPP_ICLUDE_DIR "" CACHE PATH "Header directory of abseil-cpp") |
28 | | -set(FLATBUFFERS_INCLUDE_DIR "" CACHE PATH "Header directory of flatbuffers") |
| 21 | + |
| 22 | +if(NOT YOLOX_USE_OPENVINO AND NOT YOLOX_USE_TENSORRT AND NOT YOLOX_USE_ONNXRUNTIME AND NOT YOLOX_USE_TFLITE) |
| 23 | + message(FATAL_ERROR "YOLOX_USE_OPENVINO, YOLOX_USE_TENSORRT, YOLOX_USE_ONNXRUNTIME, YOLOX_USE_TFLITE must be ON at least one") |
| 24 | + return() |
| 25 | +endif() |
29 | 26 |
|
30 | 27 | set(ENABLE_OPENVINO OFF) |
31 | 28 | set(ENABLE_TENSORRT OFF) |
32 | 29 | set(ENABLE_ONNXRUNTIME OFF) |
33 | 30 | set(ENABLE_TFLITE OFF) |
34 | 31 |
|
35 | | -# find dependencies |
36 | | -find_package(ament_cmake REQUIRED) |
37 | | -find_package(OpenCV REQUIRED) |
38 | | - |
39 | 32 | if(YOLOX_USE_OPENVINO) |
40 | | - find_package(InferenceEngine) |
41 | | - find_package(ngraph) |
42 | | - if( InferenceEngine_FOUND AND ngraph_FOUND ) |
43 | | - set(ENABLE_OPENVINO ON) |
44 | | - set(SRC ${SRC} src/yolox_openvino.cpp) |
45 | | - endif() |
46 | | -endif() |
47 | | -if(YOLOX_USE_TENSORRT) |
48 | | - find_package(CUDA) |
49 | | - find_library(NVINFER NAMES nvinfer) |
50 | | - find_library(NVINFERPLUGIN NAMES nvinfer_plugin) |
51 | | - find_library(NVPARSERS NAMES nvparsers) |
52 | | - find_library(NVONNXPARSER NAMES nvonnxparser) |
53 | | - find_library(NVONNXPARSERRUNTIME NAMES nvonnxparser_runtime) |
54 | | - if(NOT CUDA_FOUND) |
55 | | - message(WARNING " CUDA not found") |
56 | | - endif() |
57 | | - if(NOT NVINFER) |
58 | | - message(WARNING " NVINFER not found") |
59 | | - endif() |
60 | | - if(NOT NVINFERPLUGIN) |
61 | | - message(WARNING " NVINFERPLUGIN not found") |
62 | | - endif() |
63 | | - if(NOT NVPARSERS) |
64 | | - message(WARNING " NVPARSERS not found") |
65 | | - endif() |
66 | | - if(NOT NVONNXPARSER) |
67 | | - message(WARNING " NVONNXPARSER not found") |
68 | | - endif() |
69 | | - # message(WARNING " NVONNXPARSERRUNTIME ${NVONNXPARSERRUNTIME}") #not use |
70 | | - if( CUDA_FOUND AND NVINFER AND NVINFERPLUGIN AND NVPARSERS AND NVONNXPARSER ) |
71 | | - message(STATUS " CUDA ${CUDA_FOUND}") |
72 | | - message(STATUS " NVINFER ${NVINFER}") |
73 | | - message(STATUS " NVINFERPLUGIN ${NVINFERPLUGIN}") |
74 | | - message(STATUS " NVPARSERS ${NVPARSERS}") |
75 | | - message(STATUS " NVONNXPARSER ${NVONNXPARSER}") |
76 | | - set(ENABLE_TENSORRT ON) |
77 | | - set(SRC ${SRC} src/yolox_tensorrt.cpp) |
78 | | - endif() |
79 | | -endif() |
80 | | -if(YOLOX_USE_ONNXRUNTIME) |
81 | | - find_library(ONNXRUNTIME NAMES onnxruntime) |
82 | | - if(NOT ONNXRUNTIME) |
83 | | - message(WARNING " ONNXRUNTIME not found") |
84 | | - else() |
85 | | - message(STATUS " ONNXRUNTIME ${ONNXRUNTIME}") |
86 | | - set(ENABLE_ONNXRUNTIME ON) |
87 | | - set(SRC ${SRC} src/yolox_onnxruntime.cpp) |
88 | | - endif() |
89 | | -endif() |
90 | | -if(YOLOX_USE_TFLITE) |
91 | | - if(NOT ${TFLITE_LIB_PATH}) |
92 | | - set(ENABLE_TFLITE ON) |
93 | | - set(SRC ${SRC} src/yolox_tflite.cpp) |
94 | | - set(INCLUDES ${INCLUDES} ${TFLITE_INCLUDE_DIR}) |
95 | | - set(INCLUDES ${INCLUDES} ${ABSEIL_CPP_ICLUDE_DIR}) |
96 | | - set(INCLUDES ${INCLUDES} ${FLATBUFFERS_INCLUDE_DIR}) |
97 | | - else() |
98 | | - message(WARNING "TFLITE_LIB_PATH is not set") |
99 | | - endif() |
| 33 | + find_package(OpenVINO REQUIRED) |
| 34 | + find_package(InferenceEngine REQUIRED) |
| 35 | + find_package(ngraph REQUIRED) |
| 36 | + |
| 37 | + set(ENABLE_OPENVINO ON) |
| 38 | + set(TARGET_SRC src/yolox_openvino.cpp) |
| 39 | + set(TARGET_LIBS InferenceEngine ngraph) |
| 40 | + set(TARGET_DPENDENCIES OpenVINO InferenceEngine ngraph) |
100 | 41 | endif() |
101 | 42 |
|
102 | | -message(STATUS " ENABLE_OPENVINO: ${ENABLE_OPENVINO}") |
103 | | -message(STATUS " ENABLE_TENSORRT: ${ENABLE_TENSORRT}") |
104 | | -message(STATUS " ENABLE_ONNXRUNTIME: ${ENABLE_ONNXRUNTIME}") |
105 | | -message(STATUS " ENABLE_TFLITE: ${ENABLE_TFLITE}") |
| 43 | +if(YOLOX_USE_TENSORRT) |
| 44 | + find_package(CUDA REQUIRED) |
| 45 | + find_library(NVINFER NAMES nvinfer REQUIRED) |
| 46 | + find_library(NVINFERPLUGIN NAMES nvinfer_plugin REQUIRED) |
| 47 | + find_library(NVPARSERS NAMES nvparsers REQUIRED) |
| 48 | + find_library(NVONNXPARSER NAMES nvonnxparser REQUIRED) |
106 | 49 |
|
107 | | -if(NOT ENABLE_OPENVINO AND NOT ENABLE_TENSORRT AND NOT ENABLE_ONNXRUNTIME AND NOT ENABLE_TFLITE) |
108 | | - message(WARNING "skip building yolox_cpp, no OpenVINO, TensorRT, ONNXRuntime and tflite found") |
109 | | - return() |
| 50 | + set(ENABLE_TENSORRT ON) |
| 51 | + set(TARGET_SRC src/yolox_tensorrt.cpp) |
| 52 | + set(TARGET_LIBS nvinfer nvinfer_plugin nvparsers nvonnxparser) |
| 53 | + set(TARGET_DPENDENCIES CUDA) |
110 | 54 | endif() |
111 | 55 |
|
| 56 | + |
112 | 57 | configure_file( |
113 | 58 | "${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h.in" |
114 | 59 | "${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h" |
115 | 60 | ) |
116 | 61 |
|
117 | | -set(INCLUDES ${INCLUDES} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) |
118 | | -set(INCLUDES ${INCLUDES} $<INSTALL_INTERFACE:include>) |
| 62 | +ament_auto_add_library(yolox_cpp SHARED ${TARGET_SRC}) |
| 63 | +ament_target_dependencies(yolox_cpp ${TARGET_DPENDENCIES}) |
| 64 | +ament_export_dependencies(${TARGET_DPENDENCIES}) |
119 | 65 |
|
120 | | -add_library(yolox_cpp SHARED |
121 | | - ${SRC} |
122 | | -) |
123 | | - |
124 | | -target_compile_definitions(yolox_cpp |
125 | | - PRIVATE "MY_LIBRARY_BUILDING_LIBRARY" |
126 | | -) |
127 | | -target_compile_options(yolox_cpp PUBLIC -Wall) |
128 | 66 |
|
129 | | -target_include_directories(yolox_cpp PUBLIC |
130 | | - ${INCLUDES} |
131 | | -) |
132 | | - |
133 | | -ament_target_dependencies(yolox_cpp |
134 | | - OpenCV |
135 | | -) |
136 | | -if(ENABLE_OPENVINO) |
137 | | - ament_target_dependencies(yolox_cpp |
138 | | - InferenceEngine |
139 | | - ngraph |
140 | | - ) |
141 | | -endif() |
142 | | -if(ENABLE_TENSORRT) |
| 67 | +if (YOLOX_USE_TENSORRT) |
143 | 68 | target_link_libraries(yolox_cpp |
144 | 69 | nvinfer |
145 | 70 | nvinfer_plugin |
146 | 71 | nvparsers |
147 | 72 | nvonnxparser |
148 | | - # nvonnxparser_runtime |
149 | | - ) |
150 | | - ament_target_dependencies(yolox_cpp |
151 | | - CUDA |
152 | | - ) |
153 | | -endif() |
154 | | -if(ENABLE_ONNXRUNTIME) |
155 | | - target_link_libraries(yolox_cpp |
156 | | - onnxruntime |
157 | 73 | ) |
158 | 74 | endif() |
159 | | -if(ENABLE_TFLITE) |
160 | | - target_link_libraries(yolox_cpp |
161 | | - ${TFLITE_LIB_PATH} |
162 | | - ) |
163 | | -endif() |
164 | | - |
165 | | - |
166 | 75 |
|
167 | | -if(NOT WIN32) |
168 | | - ament_environment_hooks( |
169 | | - "${ament_cmake_package_templates_ENVIRONMENT_HOOK_LIBRARY_PATH}" |
170 | | - ) |
171 | | -endif() |
172 | | -ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) |
173 | | -ament_export_dependencies( |
174 | | - OpenCV |
175 | | -) |
176 | | -if(ENABLE_OPENVINO) |
177 | | - ament_export_dependencies( |
178 | | - InferenceEngine |
179 | | - ngraph |
180 | | - ) |
181 | | -endif() |
182 | | -if(ENABLE_TENSORRT) |
183 | | - ament_export_dependencies( |
184 | | - CUDA |
185 | | - ) |
186 | | -endif() |
187 | | - |
188 | | -install(TARGETS yolox_cpp |
189 | | - EXPORT export_${PROJECT_NAME} |
190 | | - ARCHIVE DESTINATION lib |
191 | | - LIBRARY DESTINATION lib |
192 | | - RUNTIME DESTINATION bin |
193 | | - INCLUDES DESTINATION include |
194 | | -) |
195 | | - |
196 | | -install(DIRECTORY |
197 | | - DESTINATION share/${PROJECT_NAME} |
198 | | -) |
199 | | -install( |
200 | | - DIRECTORY include/ |
201 | | - DESTINATION include |
202 | | -) |
203 | 76 |
|
204 | 77 | if(BUILD_TESTING) |
205 | 78 | find_package(ament_lint_auto REQUIRED) |
206 | | - # the following line skips the linter which checks for copyrights |
207 | | - # uncomment the line when a copyright and license is not present in all source files |
208 | | - #set(ament_cmake_copyright_FOUND TRUE) |
209 | | - # the following line skips cpplint (only works in a git repo) |
210 | | - # uncomment the line when this package is not in a git repo |
211 | | - #set(ament_cmake_cpplint_FOUND TRUE) |
212 | 79 | ament_lint_auto_find_test_dependencies() |
213 | 80 | endif() |
214 | 81 |
|
215 | | -ament_package() |
| 82 | +ament_auto_package() |
0 commit comments