forked from ros2/demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
257 lines (227 loc) · 10.6 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
cmake_minimum_required(VERSION 3.12)
project(demo_nodes_cpp)
# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rcl REQUIRED)
find_package(rcl_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rcutils REQUIRED)
find_package(rmw REQUIRED)
find_package(std_msgs REQUIRED)
function(custom_executable subfolder target)
cmake_parse_arguments(ARG "" "" "DEPENDENCIES" ${ARGN})
add_executable(${target} src/${subfolder}/${target}.cpp)
target_include_directories(${target} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${target} PRIVATE
${ARG_DEPENDENCIES}
)
install(TARGETS ${target}
DESTINATION lib/${PROJECT_NAME})
endfunction()
custom_executable(topics allocator_tutorial
DEPENDENCIES rclcpp::rclcpp ${std_msgs_TARGETS})
custom_executable(services add_two_ints_client
DEPENDENCIES ${example_interfaces_TARGETS} rclcpp::rclcpp)
custom_executable(parameters list_parameters_async
DEPENDENCIES rclcpp::rclcpp)
custom_executable(parameters parameter_events
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp)
custom_executable(parameters parameter_event_handler
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp)
custom_executable(parameters set_and_get_parameters_async
DEPENDENCIES rclcpp::rclcpp)
custom_executable(events matched_event_detect
DEPENDENCIES rclcpp::rclcpp ${std_msgs_TARGETS})
custom_executable(logging use_logger_service
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp ${std_msgs_TARGETS})
function(create_demo_library plugin executable)
cmake_parse_arguments(ARG "" "" "FILES;DEPENDENCIES" ${ARGN})
set(library ${executable}_library)
add_library(${library} SHARED ${ARG_FILES})
target_compile_definitions(${library}
PRIVATE "DEMO_NODES_CPP_BUILDING_DLL")
target_include_directories(${library} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${library} PRIVATE
${ARG_DEPENDENCIES}
)
install(TARGETS ${library}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
rclcpp_components_register_node(${library}
PLUGIN ${plugin}
EXECUTABLE ${executable})
endfunction()
# Timers
create_demo_library("demo_nodes_cpp::OneOffTimerNode" one_off_timer
FILES src/timers/one_off_timer.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::ReuseTimerNode" reuse_timer
FILES src/timers/reuse_timer.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component)
# Parameters
create_demo_library("demo_nodes_cpp::ListParameters" list_parameters
FILES src/parameters/list_parameters.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::ParameterBlackboard" parameter_blackboard
FILES src/parameters/parameter_blackboard.cpp
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::SetAndGetParameters" set_and_get_parameters
FILES src/parameters/set_and_get_parameters.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::ParameterEventsAsyncNode" parameter_events_async
FILES src/parameters/parameter_events_async.cpp
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::EvenParameterNode" event_parameters_node
FILES src/parameters/even_parameters_node.cpp
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::SetParametersCallback" set_parameters_callback
FILES src/parameters/set_parameters_callback.cpp
DEPENDENCIES ${rcl_interfaces_TARGETS} rclcpp::rclcpp rclcpp_components::component)
# Services
create_demo_library("demo_nodes_cpp::ServerNode" add_two_ints_server
FILES src/services/add_two_ints_server.cpp
DEPENDENCIES ${example_interfaces_TARGETS} rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::ClientNode" add_two_ints_client_async
FILES src/services/add_two_ints_client_async.cpp
DEPENDENCIES ${example_interfaces_TARGETS} rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::IntrospectionServiceNode" introspection_service
FILES src/services/introspection_service.cpp
DEPENDENCIES ${example_interfaces_TARGETS} ${rcl_interfaces_TARGETS} rcl::rcl rclcpp::rclcpp rclcpp_components::component)
create_demo_library("demo_nodes_cpp::IntrospectionClientNode" introspection_client
FILES src/services/introspection_client.cpp
DEPENDENCIES ${example_interfaces_TARGETS} ${rcl_interfaces_TARGETS} rcl::rcl rclcpp::rclcpp rclcpp_components::component)
# Topics
create_demo_library("demo_nodes_cpp::ContentFilteringPublisher" content_filtering_publisher
FILES src/topics/content_filtering_publisher.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::ContentFilteringSubscriber" content_filtering_subscriber
FILES src/topics/content_filtering_subscriber.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component rcpputils::rcpputils ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::Talker" talker
FILES src/topics/talker.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::LoanedMessageTalker" talker_loaned_message
FILES src/topics/talker_loaned_message.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::SerializedMessageTalker" talker_serialized_message
FILES src/topics/talker_serialized_message.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::Listener" listener
FILES src/topics/listener.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::SerializedMessageListener" listener_serialized_message
FILES src/topics/listener_serialized_message.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
create_demo_library("demo_nodes_cpp::ListenerBestEffort" listener_best_effort
FILES src/topics/listener_best_effort.cpp
DEPENDENCIES rclcpp::rclcpp rclcpp_components::component ${std_msgs_TARGETS})
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(ament_cmake_pytest REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)
find_package(rmw_implementation_cmake REQUIRED)
# Add each test case. Multi-executable tests can be specified in
# semicolon-separated strings, like exe1;exe2.
set(tutorial_tests
"content_filtering_publisher@publish_ms=100:content_filtering_subscriber"
list_parameters_async
list_parameters
parameter_events_async
parameter_events
set_and_get_parameters_async
set_and_get_parameters
matched_event_detect
use_logger_service
"talker:listener"
)
set(service_tutorial_tests
"add_two_ints_server@one_shot=True:add_two_ints_client"
"add_two_ints_server@one_shot=True:add_two_ints_client_async"
)
macro(tests)
set(tutorial_tests_to_test ${tutorial_tests})
list(APPEND tutorial_tests_to_test ${service_tutorial_tests})
foreach(tutorial_test ${tutorial_tests_to_test})
set(DEMO_NODES_CPP_EXPECTED_OUTPUT "")
set(DEMO_NODES_CPP_EXECUTABLE "")
set(exe_list "")
# We're expecting each tutorial_test to be of the form:
#
# exe1[@param1=value1@param2=value2][:exe2[@param3=value3@param4=value4]]
#
# That is, you can have one or more executables, and each of those
# executables can be passed zero or more parameters.
#
# Unfortunately, we need to parse this list here in CMake since we need
# to know the executable name so we can generate an absolute path.
# Convert the colon-separated list we were given to a semi-colon
# separated one so we can iterate over it in CMake.
string(REPLACE ":" ";" exes_and_params "${tutorial_test}")
foreach(exe_and_params ${exes_and_params})
string(REPLACE "@" ";" params ${exe_and_params})
# It is expected that the first variable is the executable
list(GET params 0 executable)
list(APPEND DEMO_NODES_CPP_EXPECTED_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/test/${executable}")
list(APPEND exe_list ${executable})
set(target_file "$<TARGET_FILE:${executable}>")
# If there is anything left in the list at this time, assume they
# are parameters.
list(LENGTH params list_length)
if(${list_length} GREATER 1)
list(SUBLIST params 1 -1 params_only)
string(JOIN "@" target_file ${target_file} ${params_only})
endif()
# This is what will get substituted into test_executables_tutorial.py.in below.
# It looks exactly the same as exes_and_params, with the exception
# that the executable names have been substituted for the absolute paths.
list(APPEND DEMO_NODES_CPP_EXECUTABLE ${target_file})
endforeach()
string(REPLACE ";" "_" exe_list_underscore "${exe_list}")
configure_file(
test/test_executables_tutorial.py.in
test_${exe_list_underscore}${target_suffix}.py.configured
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_${exe_list_underscore}${target_suffix}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_${exe_list_underscore}${target_suffix}.py.configured"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_${exe_list_underscore}${target_suffix}_$<CONFIG>.py"
TARGET test_tutorial_${exe_list_underscore}${target_suffix}
TIMEOUT 60
ENV
RCL_ASSERT_RMW_ID_MATCHES=${rmw_implementation}
RMW_IMPLEMENTATION=${rmw_implementation}
)
foreach(executable ${exe_list})
set_property(
TEST test_tutorial_${exe_list_underscore}${target_suffix}
APPEND PROPERTY DEPENDS ${executable}${target_suffix})
endforeach()
endforeach()
endmacro()
call_for_each_rmw_implementation(tests)
endif()
# Install launch files.
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
ament_package()