Skip to content

Commit e1b432b

Browse files
committed
fix cmakes
1 parent fd592f3 commit e1b432b

5 files changed

Lines changed: 54 additions & 262 deletions

File tree

Lines changed: 37 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -1,215 +1,82 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.8)
22
project(yolox_cpp)
33

4-
# Default to C99
5-
if(NOT CMAKE_C_STANDARD)
6-
set(CMAKE_C_STANDARD 99)
7-
endif()
8-
9-
# Default to C++17
104
if(NOT CMAKE_CXX_STANDARD)
115
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
128
endif()
139

1410
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1511
add_compile_options(-Wall -Wextra -Wpedantic)
1612
endif()
1713

18-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14+
find_package(ament_cmake_auto REQUIRED)
15+
ament_auto_find_build_dependencies()
1916

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)
2420
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()
2926

3027
set(ENABLE_OPENVINO OFF)
3128
set(ENABLE_TENSORRT OFF)
3229
set(ENABLE_ONNXRUNTIME OFF)
3330
set(ENABLE_TFLITE OFF)
3431

35-
# find dependencies
36-
find_package(ament_cmake REQUIRED)
37-
find_package(OpenCV REQUIRED)
38-
3932
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)
10041
endif()
10142

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)
10649

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)
11054
endif()
11155

56+
11257
configure_file(
11358
"${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h.in"
11459
"${PROJECT_SOURCE_DIR}/include/yolox_cpp/config.h"
11560
)
11661

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})
11965

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)
12866

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)
14368
target_link_libraries(yolox_cpp
14469
nvinfer
14570
nvinfer_plugin
14671
nvparsers
14772
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
15773
)
15874
endif()
159-
if(ENABLE_TFLITE)
160-
target_link_libraries(yolox_cpp
161-
${TFLITE_LIB_PATH}
162-
)
163-
endif()
164-
165-
16675

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-
)
20376

20477
if(BUILD_TESTING)
20578
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)
21279
ament_lint_auto_find_test_dependencies()
21380
endif()
21481

215-
ament_package()
82+
ament_auto_package()

yolox_ros_cpp/yolox_cpp/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<license>Apache-2.0 License</license>
99
<author email="53618876+fateshelled@users.noreply.github.com">fateshelled</author>
1010

11-
<buildtool_depend>ament_cmake</buildtool_depend>
11+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
1212

1313
<depend>OpenCV</depend>
1414

Lines changed: 14 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,39 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.8)
22
project(yolox_ros_cpp)
33

4-
# Default to C99
5-
if(NOT CMAKE_C_STANDARD)
6-
set(CMAKE_C_STANDARD 99)
7-
endif()
8-
9-
# Default to C++17
104
if(NOT CMAKE_CXX_STANDARD)
115
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
128
endif()
139

1410
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1511
add_compile_options(-Wall -Wextra -Wpedantic)
1612
endif()
1713

18-
# find dependencies
19-
find_package(ament_cmake REQUIRED)
20-
find_package(rclcpp REQUIRED)
21-
find_package(rclcpp_components REQUIRED)
22-
find_package(std_msgs REQUIRED)
23-
find_package(sensor_msgs REQUIRED)
24-
find_package(cv_bridge REQUIRED)
25-
find_package(image_transport REQUIRED)
26-
find_package(OpenCV REQUIRED)
27-
find_package(bboxes_ex_msgs REQUIRED)
28-
find_package(yolox_cpp)
14+
find_package(ament_cmake_auto REQUIRED)
15+
ament_auto_find_build_dependencies()
2916

3017
if(NOT yolox_cpp_FOUND)
3118
message(WARNING "skipping yolox_ros_cpp, no yolox_cpp found")
3219
return()
3320
endif()
3421

35-
36-
# executable
37-
add_executable(yolox_ros_cpp
38-
src/yolox_ros_cpp.cpp
39-
)
40-
ament_target_dependencies(yolox_ros_cpp
41-
rclcpp
42-
rclcpp_components
43-
cv_bridge
44-
image_transport
45-
builtin_interfaces
46-
std_msgs
47-
sensor_msgs
48-
OpenCV
49-
yolox_cpp
50-
bboxes_ex_msgs
51-
)
52-
target_include_directories(yolox_ros_cpp PUBLIC
53-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
54-
$<INSTALL_INTERFACE:include>
55-
)
56-
install(TARGETS
57-
yolox_ros_cpp
58-
DESTINATION lib/${PROJECT_NAME}
59-
)
60-
61-
# components
62-
add_library(yolox_ros_cpp_components SHARED
22+
ament_auto_add_library(yolox_ros_cpp SHARED
6323
src/yolox_ros_cpp.cpp
6424
)
65-
rclcpp_components_register_nodes(yolox_ros_cpp_components
66-
"yolox_ros_cpp::YoloXNode")
67-
target_compile_definitions(yolox_ros_cpp_components
68-
PRIVATE "YOLOX_ROS_CPP_LIBRARY"
69-
)
70-
target_compile_options(yolox_ros_cpp_components PUBLIC -Wall)
71-
72-
target_include_directories(yolox_ros_cpp_components PUBLIC
73-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
74-
$<INSTALL_INTERFACE:include>
75-
)
76-
77-
ament_target_dependencies(yolox_ros_cpp_components
78-
rclcpp
79-
rclcpp_components
80-
cv_bridge
81-
image_transport
82-
builtin_interfaces
83-
std_msgs
84-
sensor_msgs
85-
OpenCV
86-
yolox_cpp
87-
bboxes_ex_msgs
88-
)
89-
90-
install(TARGETS yolox_ros_cpp_components
91-
EXPORT export_${PROJECT_NAME}
92-
DESTINATION lib
93-
)
94-
95-
96-
install(DIRECTORY
97-
launch
98-
labels
99-
../../weights
100-
DESTINATION share/${PROJECT_NAME}
25+
rclcpp_components_register_node(
26+
yolox_ros_cpp
27+
PLUGIN "yolox_ros_cpp::YoloXNode"
28+
EXECUTABLE yolox_ros_cpp_node
10129
)
10230

10331
if(BUILD_TESTING)
10432
find_package(ament_lint_auto REQUIRED)
105-
# the following line skips the linter which checks for copyrights
106-
# uncomment the line when a copyright and license is not present in all source files
107-
#set(ament_cmake_copyright_FOUND TRUE)
108-
# the following line skips cpplint (only works in a git repo)
109-
# uncomment the line when this package is not in a git repo
110-
#set(ament_cmake_cpplint_FOUND TRUE)
11133
ament_lint_auto_find_test_dependencies()
11234
endif()
11335

114-
ament_package()
36+
ament_auto_package(
37+
INSTALL_TO_SHARE
38+
launch
39+
)

yolox_ros_cpp/yolox_ros_cpp/launch/yolox_openvino.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def generate_launch_description():
1616
),
1717
DeclareLaunchArgument(
1818
"model_path",
19-
default_value="./install/yolox_ros_cpp/share/yolox_ros_cpp/weights/openvino/yolox_nano.xml",
19+
default_value="./src/YOLOX-ROS/weights/onnx/yolox_tiny.onnx",
2020
description="yolox model path."
2121
),
2222
DeclareLaunchArgument(

0 commit comments

Comments
 (0)