forked from ros-drivers/usb_cam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
113 lines (92 loc) · 2.81 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
cmake_minimum_required(VERSION 3.5)
project(usb_cam)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()
find_package(OpenCV REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(avcodec REQUIRED libavcodec)
pkg_check_modules(avutil REQUIRED libavutil)
pkg_check_modules(swscale REQUIRED libswscale)
if(EXISTS ${avcodec})
message(STATUS "Found libavcodec: ${avcodec}")
endif()
if(EXISTS ${avutil})
message(STATUS "Found libavutil: ${avutil}")
endif()
if(EXISTS ${swscale})
message(STATUS "Found libswscale: ${swscale}")
endif()
## Build the USB camera library
## Do not use ament_auto here so as to not link to rclcpp
add_library(${PROJECT_NAME} SHARED
src/usb_cam.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
"include"
)
target_link_libraries(${PROJECT_NAME}
${avcodec_LIBRARIES}
${avutil_LIBRARIES}
${swscale_LIBRARIES}
${OpenCV_LIBRARIES})
ament_export_libraries(${PROJECT_NAME})
## Declare a ROS 2 composible node as a library
ament_auto_add_library(${PROJECT_NAME}_node SHARED
src/usb_cam_node.cpp
)
target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME})
## Use node to generate an executable
rclcpp_components_register_node(${PROJECT_NAME}_node
PLUGIN "usb_cam::UsbCamNode"
EXECUTABLE ${PROJECT_NAME}_node_exe
)
if(SANITIZE)
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME} -fsanitize=address -fsanitize=leak)
target_compile_options(${PROJECT_NAME}_node PUBLIC -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME}_node -fsanitize=address -fsanitize=leak)
target_link_libraries(${PROJECT_NAME}_node_exe -fsanitize=address -fsanitize=leak)
endif()
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(ament_cmake_gtest)
# Unit tests
ament_add_gtest(test_usb_cam_utils
test/test_usb_cam_utils.cpp)
target_link_libraries(test_usb_cam_utils
${PROJECT_NAME})
ament_add_gtest(test_pixel_formats
test/test_pixel_formats.cpp)
target_link_libraries(test_pixel_formats
${PROJECT_NAME})
# TODO(flynneva): rewrite this test in another PR
# Integration tests
# ament_add_gtest(test_usb_cam_lib
# test/test_usb_cam_lib.cpp)
# target_link_libraries(test_usb_cam_lib
# ${PROJECT_NAME})
endif()
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
)