forked from ros-drivers/usb_cam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
176 lines (152 loc) · 4.45 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
cmake_minimum_required(VERSION 3.5)
project(usb_cam)
# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
# Find ROS and catkin dependencies
find_package(catkin REQUIRED COMPONENTS
cv_bridge
roscpp
std_msgs
std_srvs
sensor_msgs
camera_info_manager
image_transport
rosconsole
)
# Find OpenCV, Eigen, and CUDA
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
# Set CUDA toolkit root directory if not already defined
if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR)
set(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda-11.8")
endif()
message(STATUS "CUDA_TOOLKIT_ROOT_DIR: ${CUDA_TOOLKIT_ROOT_DIR}")
find_package(CUDA REQUIRED)
# Find FFmpeg libraries with PkgConfig
find_package(PkgConfig REQUIRED)
pkg_check_modules(avcodec REQUIRED libavcodec)
pkg_check_modules(avutil REQUIRED libavutil)
pkg_check_modules(swscale REQUIRED libswscale)
# Output messages if libraries are found
if(avcodec_FOUND)
message(STATUS "Found libavcodec: ${avcodec_LIBRARIES}")
endif()
if(avutil_FOUND)
message(STATUS "Found libavutil: ${avutil_LIBRARIES}")
endif()
if(swscale_FOUND)
message(STATUS "Found libswscale: ${swscale_LIBRARIES}")
endif()
# Find TensorRT libraries
set(TENSORRT_LIB_DIR /usr/lib/x86_64-linux-gnu CACHE PATH "Path to TensorRT libraries")
find_library(NVINFER nvinfer PATHS ${TENSORRT_LIB_DIR})
find_library(NVINFER_PLUGIN nvinfer_plugin PATHS ${TENSORRT_LIB_DIR})
find_library(NVONNXPARSER nvonnxparser PATHS ${TENSORRT_LIB_DIR})
message(STATUS "TensorRT NVINFER library found at: ${NVINFER}")
message(STATUS "TensorRT NVINFER_PLUGIN library found at: ${NVINFER_PLUGIN}")
message(STATUS "TensorRT NVONNXPARSER library found at: ${NVONNXPARSER}")
# Check if TensorRT libraries are found
if(NOT NVINFER OR NOT NVINFER_PLUGIN OR NOT NVONNXPARSER)
message(FATAL_ERROR "TensorRT libraries not found. Ensure TENSORRT_LIB_DIR is set correctly.")
endif()
## Build the USB camera library
add_library(${PROJECT_NAME} SHARED
src/usb_cam.cpp
src/interface.cpp
)
# Set include directories
target_include_directories(${PROJECT_NAME} PUBLIC
"include"
${OpenCV_INCLUDE_DIRS}
${Eigen3_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
${CUDA_INCLUDE_DIRS}
)
# Link libraries for the usb_cam library
target_link_libraries(${PROJECT_NAME}
PUBLIC
Eigen3::Eigen
${OpenCV_LIBRARIES}
${CUDA_LIBRARIES}
PRIVATE
${avcodec_LIBRARIES}
${avutil_LIBRARIES}
${swscale_LIBRARIES}
${NVINFER}
${NVINFER_PLUGIN}
${NVONNXPARSER}
)
# Define catkin package
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
)
# Build the USB camera node executable
add_executable(${PROJECT_NAME}_node src/usb_cam_node.cpp)
target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME}
${avcodec_LIBRARIES}
${avutil_LIBRARIES}
${catkin_LIBRARIES}
${CUDA_LIBRARIES}
${NVINFER_PLUGIN}
${NVINFER}
${NVONNXPARSER}
${swscale_LIBRARIES}
)
set_target_properties(${PROJECT_NAME}_node PROPERTIES LINK_FLAGS "-Wl,--no-as-needed")
# Ensure include directories are set
target_include_directories(${PROJECT_NAME}_node PUBLIC
${catkin_INCLUDE_DIRS})
# Testing
if(BUILD_TESTING)
# Find GTest package
set(CMAKE_BUILD_TYPE Debug)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
catkin_add_gtest(test_depth_anything_v2 test/test_depth_anything_v2.cpp)
target_link_libraries(test_depth_anything_v2
${PROJECT_NAME}
${catkin_LIBRARIES}
GTest::gtest_main
${NVINFER}
${NVINFER_PLUGIN}
${NVONNXPARSER}
${CUDA_LIBRARIES}
)
set_target_properties(test_depth_anything_v2 PROPERTIES LINK_FLAGS "-Wl,--no-as-needed")
endif()
# Installation rules
if($ENV{ROS_VERSION} EQUAL 1)
install(TARGETS ${PROJECT_NAME}_node ${PROJECT_NAME}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
# Copy launch files
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
FILES_MATCHING PATTERN "*.launch"
)
# Include header files
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)
else()
install(PROGRAMS scripts/show_image.py
DESTINATION lib/${PROJECT_NAME})
install(TARGETS
${PROJECT_NAME}
${PROJECT_NAME}_node
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib
)
ament_auto_package(
INSTALL_TO_SHARE
launch
config
)
endif()