-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
397 lines (349 loc) · 13.5 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0057 NEW)
set(PACKAGE_VERSION "1.0.0")
project(rmw_microxrcedds
VERSION
${PACKAGE_VERSION}
LANGUAGES
C
)
find_package(ament_cmake_ros REQUIRED)
find_package(rcutils REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(microxrcedds_client REQUIRED)
find_package(microcdr REQUIRED)
find_package(rmw REQUIRED)
# Build options
option(BUILD_DOCUMENTATION "Use doxygen to create product documentation" OFF)
option(RMW_UXRCE_GRAPH "Allows to perform graph-related operations to the user" OFF)
if(RMW_UXRCE_GRAPH)
find_package(micro_ros_msgs REQUIRED)
endif()
# --- RMW CONFIGURATION ---
set(RMW_UXRCE_TRANSPORT "udp" CACHE STRING "Sets Micro XRCE-DDS transport to use. (udp | tcp | serial | custom)")
set(RMW_UXRCE_IPV "ipv4" CACHE STRING "Sets Micro XRCE-DDS IP version to use. (ipv4 | ipv6)")
set(RMW_UXRCE_CREATION_MODE "bin" CACHE STRING "Sets creation mode in Micro XRCE-DDS. (bin | refs)")
set(RMW_UXRCE_MAX_HISTORY "8" CACHE STRING
"This value sets the number of history slots available for RMW subscriptions, requests and replies")
set(RMW_UXRCE_MAX_SESSIONS "1" CACHE STRING "This value sets the maximum number of Micro XRCE-DDS sessions.")
set(RMW_UXRCE_MAX_NODES "4" CACHE STRING "This value sets the maximum number of nodes.")
set(RMW_UXRCE_MAX_PUBLISHERS "4" CACHE STRING "This value sets the maximum number of publishers for an application.")
set(RMW_UXRCE_MAX_SUBSCRIPTIONS "4" CACHE STRING "This value sets the maximum number of subscriptions for an application.")
set(RMW_UXRCE_MAX_SERVICES "4" CACHE STRING "This value sets the maximum number of services for an application.")
set(RMW_UXRCE_MAX_CLIENTS "4" CACHE STRING "This value sets the maximum number of clients for an application.")
set(RMW_UXRCE_MAX_WAIT_SETS "4" CACHE STRING "This value sets the maximum number of wait sets for an application.")
set(RMW_UXRCE_MAX_GUARD_CONDITION "4" CACHE STRING "This value sets the maximum number of guard conditions for an application.")
set(RMW_UXRCE_MAX_TOPICS "-1" CACHE STRING
"This value sets the maximum number of topics for an application.
If set to -1 RMW_UXRCE_MAX_TOPICS = RMW_UXRCE_MAX_PUBLISHERS + RMW_UXRCE_MAX_SUBSCRIPTIONS + RMW_UXRCE_MAX_NODES.")
option(RMW_UXRCE_ALLOW_DYNAMIC_ALLOCATIONS "Enables increasing static pools with dynamic allocation when needed." OFF)
set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "60" CACHE STRING "This value sets the maximum number of characters for a node name.")
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "60" CACHE STRING "This value sets the maximum number of characters for a topic name.")
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a type name.")
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING
"This value sets the default time to wait for a publication in a reliable mode in milliseconds.")
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING
"This value sets the default maximum time to wait for an XRCE entity creation and destroy in milliseconds.
If set to 0 best effort is used.")
set(RMW_UXRCE_ENTITY_CREATION_TIMEOUT "" CACHE STRING
"This value sets the maximum time to wait for an XRCE entity creation in milliseconds.
If set to 0 best effort is used.")
set(RMW_UXRCE_ENTITY_DESTROY_TIMEOUT "" CACHE STRING
"This value sets the maximum time to wait for an XRCE entity destroy in milliseconds.
If set to 0 best effort is used.")
if(RMW_UXRCE_ENTITY_CREATION_TIMEOUT STREQUAL "")
set(RMW_UXRCE_ENTITY_CREATION_TIMEOUT ${RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT})
endif()
if(RMW_UXRCE_ENTITY_DESTROY_TIMEOUT STREQUAL "")
set(RMW_UXRCE_ENTITY_DESTROY_TIMEOUT ${RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT})
endif()
set(RMW_UXRCE_STREAM_HISTORY "4" CACHE STRING "This value sets the number of MTUs to buffer, both input and output.")
set(RMW_UXRCE_STREAM_HISTORY_INPUT "" CACHE STRING
"This value sets the number of MTUs to input buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_OUTPUT is blank.")
set(RMW_UXRCE_STREAM_HISTORY_OUTPUT "" CACHE STRING
"This value sets the number of MTUs to output buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_INPUT is blank.")
if(RMW_UXRCE_STREAM_HISTORY_INPUT STREQUAL "" OR RMW_UXRCE_STREAM_HISTORY_OUTPUT STREQUAL "")
unset(RMW_UXRCE_STREAM_HISTORY_INPUT)
unset(RMW_UXRCE_STREAM_HISTORY_OUTPUT)
else()
unset(RMW_UXRCE_STREAM_HISTORY)
endif()
# Transport handle define macros.
set(RMW_UXRCE_TRANSPORT_SERIAL OFF)
set(RMW_UXRCE_TRANSPORT_UDP OFF)
set(RMW_UXRCE_TRANSPORT_TCP OFF)
set(RMW_UXRCE_TRANSPORT_IPV4 OFF)
set(RMW_UXRCE_TRANSPORT_IPV6 OFF)
set(RMW_UXRCE_TRANSPORT_CUSTOM OFF)
if(${RMW_UXRCE_TRANSPORT} STREQUAL "serial")
set(RMW_UXRCE_TRANSPORT_SERIAL ON)
set(RMW_UXRCE_DEFAULT_SERIAL_DEVICE "/dev/ttyAMA0" CACHE STRING "Sets the agent serial port.")
elseif(${RMW_UXRCE_TRANSPORT} STREQUAL "udp")
set(RMW_UXRCE_TRANSPORT_UDP ON)
if(${RMW_UXRCE_IPV} STREQUAL "ipv4")
set(RMW_UXRCE_TRANSPORT_IPV4 ON)
set(RMW_UXRCE_DEFAULT_UDP_IP "127.0.0.1" CACHE STRING "Sets the agent IP address.")
elseif(${RMW_UXRCE_IPV} STREQUAL "ipv6")
set(RMW_UXRCE_TRANSPORT_IPV6 ON)
set(RMW_UXRCE_DEFAULT_UDP_IP "::1" CACHE STRING "Sets the agent IP address.")
endif()
set(RMW_UXRCE_DEFAULT_UDP_PORT "8888" CACHE STRING "Sets the agent IP port.")
elseif(${RMW_UXRCE_TRANSPORT} STREQUAL "tcp")
set(RMW_UXRCE_TRANSPORT_TCP ON)
if(${RMW_UXRCE_IPV} STREQUAL "ipv4")
set(RMW_UXRCE_TRANSPORT_IPV4 ON)
set(RMW_UXRCE_DEFAULT_TCP_IP "127.0.0.1" CACHE STRING "Sets the agent IP address.")
elseif(${RMW_UXRCE_IPV} STREQUAL "ipv6")
set(RMW_UXRCE_TRANSPORT_IPV6 ON)
set(RMW_UXRCE_DEFAULT_TCP_IP "::1" CACHE STRING "Sets the agent IP address.")
endif()
set(RMW_UXRCE_DEFAULT_TCP_PORT "8888" CACHE STRING "Sets the agent IP port.")
elseif(${RMW_UXRCE_TRANSPORT} STREQUAL "custom")
set(RMW_UXRCE_TRANSPORT_CUSTOM ON)
else()
message(FATAL_ERROR "Transport not supported. Use \"serial\", \"udp\", \"custom\"")
endif()
# Create entities type define macros.
set(RMW_UXRCE_USE_REFS OFF)
if(${RMW_UXRCE_CREATION_MODE} STREQUAL "refs")
set(RMW_UXRCE_USE_REFS ON)
endif()
# Set install directories
if(WIN32)
set(DOC_DIR "doc")
else()
set(DOC_DIR "${DATA_INSTALL_DIR}/doc")
endif()
set(DOC_INSTALL_DIR ${DOC_DIR} CACHE PATH "Installation directory for documentation")
set(SRCS
src/identifiers.c
src/memory.c
src/rmw_client.c
src/rmw_compare_gids_equal.c
src/rmw_count.c
src/rmw_event.c
src/rmw_get_gid_for_publisher.c
src/rmw_get_implementation_identifier.c
src/rmw_get_serialization_format.c
src/rmw_get_topic_endpoint_info.c
src/rmw_get_endpoint_network_flow.c
src/rmw_qos_profile_check_compatible.c
src/rmw_guard_condition.c
src/rmw_init.c
src/rmw_logging.c
src/rmw_microxrcedds_topic.c
src/rmw_node.c
src/rmw_node_info_and_types.c
src/rmw_node_names.c
src/rmw_publish.c
src/rmw_publisher.c
src/rmw_request.c
src/rmw_response.c
src/rmw_serialize.c
src/rmw_service.c
src/rmw_service_names_and_types.c
src/rmw_service_server_is_available.c
src/rmw_subscription.c
src/rmw_take.c
src/rmw_topic_names_and_types.c
src/rmw_trigger_guard_condition.c
src/rmw_wait.c
src/rmw_wait_set.c
src/types.c
src/utils.c
src/callbacks.c
src/rmw_uxrce_transports.c
src/rmw_microros/continous_serialization.c
src/rmw_microros/init_options.c
src/rmw_microros/time_sync.c
src/rmw_microros/ping.c
src/rmw_microros/timing.c
$<$<OR:$<BOOL:${RMW_UXRCE_TRANSPORT_UDP}>,$<BOOL:${RMW_UXRCE_TRANSPORT_TCP}>>:src/rmw_microros/discovery.c>
$<$<BOOL:${RMW_UXRCE_TRANSPORT_CUSTOM}>:src/rmw_microros/custom_transport.c>
$<$<BOOL:${RMW_UXRCE_GRAPH}>:src/rmw_graph.c>
)
add_library(${PROJECT_NAME}
${SRCS})
if(RMW_UXRCE_GRAPH)
add_library(micro_ros_msgs_lib SHARED IMPORTED)
set_property(
TARGET
micro_ros_msgs_lib
PROPERTY
IMPORTED_LOCATION ${micro_ros_msgs_LIBRARIES__rosidl_typesupport_microxrcedds_c})
ament_target_dependencies(${PROJECT_NAME}
"micro_ros_msgs"
)
endif()
target_link_libraries(${PROJECT_NAME}
microcdr
microxrcedds_client
$<$<BOOL:${RMW_UXRCE_GRAPH}>:micro_ros_msgs_lib>
)
# Type support lock-up mechanism
find_package(rosidl_typesupport_microxrcedds_c)
if(rosidl_typesupport_microxrcedds_c_FOUND)
ament_target_dependencies(${PROJECT_NAME}
"rosidl_typesupport_microxrcedds_c"
)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_C_TYPESUPPORT
)
else()
find_package(rosidl_typesupport_microxrcedds_cpp REQUIRED)
endif()
if(rosidl_typesupport_microxrcedds_cpp_FOUND)
ament_target_dependencies(${PROJECT_NAME}
"rosidl_typesupport_microxrcedds_cpp"
)
target_compile_definitions(${PROJECT_NAME}
PUBLIC
HAVE_CPP_TYPESUPPORT
)
endif()
ament_target_dependencies(${PROJECT_NAME}
"rcutils"
"rmw"
"microxrcedds_client"
)
configure_rmw_library(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
)
set_target_properties(${PROJECT_NAME} PROPERTIES
C_STANDARD
99
C_STANDARD_REQUIRED
YES
)
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<C_COMPILER_ID:GNU>:-Wall>
$<$<C_COMPILER_ID:GNU>:-Wextra>
$<$<C_COMPILER_ID:GNU>:-pedantic>
$<$<C_COMPILER_ID:GNU>:-Werror-implicit-function-declaration>
$<$<C_COMPILER_ID:GNU>:$<$<VERSION_GREATER:$<C_COMPILER_VERSION>,8.1>:-Wcast-align=strict>>
$<$<C_COMPILER_ID:GNU>:-Wvla>
$<$<C_COMPILER_ID:MSVC>:/Wall>
)
file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/include)
ament_export_include_directories(${CMAKE_INSTALL_PREFIX}/include)
ament_export_include_directories(${microxrcedds_client_INCLUDE_DIR})
ament_export_include_directories(${microcdr_INCLUDE_DIR})
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(
rcutils
rmw
microxrcedds_client
)
if(rosidl_typesupport_microxrcedds_c_FOUND)
ament_export_dependencies(rosidl_typesupport_microxrcedds_c)
set(implementations "c:rosidl_typesupport_c:rosidl_typesupport_microxrcedds_c")
endif()
if(rosidl_typesupport_microxrcedds_cpp_FOUND)
ament_export_dependencies(rosidl_typesupport_microxrcedds_cpp)
set(implementations
${implementations}
"cpp:rosidl_typesupport_cpp:rosidl_typesupport_microxrcedds_cpp"
)
endif()
register_rmw_implementation(${implementations})
if(BUILD_TESTING)
# Pedantic in CI
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
if(RMW_UXRCE_MAX_SESSIONS STREQUAL "1")
set(RMW_UXRCE_MAX_SESSIONS "2")
endif()
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
add_subdirectory(test)
endif()
# Create source files with the define
configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in
${PROJECT_BINARY_DIR}/include/rmw_microxrcedds_c/config.h)
# Documentation
if(BUILD_DOCUMENTATION)
find_package(Doxygen)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "doxygen is needed to build the documentation. Please install it correctly")
endif()
if(UNIX)
find_program(DOXYFILE_MAKE make)
if(DOXYFILE_MAKE)
message(STATUS "Found Make: ${DOXYFILE_MAKE}")
else()
message(FATAL_ERROR "make is needed to build the documentation. Please install it correctly")
endif()
elseif(WIN32)
set(DOXYFILE_MAKE make.bat)
endif()
# Target to create documentation directories
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc)
add_custom_target(docdirs
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/doc/api_reference
COMMENT "Creating documentation directory" VERBATIM)
### Doxygen ########################3
# Configure the template doxyfile for or specific project
configure_file(doxyfile.in ${PROJECT_BINARY_DIR}/doxyfile @ONLY IMMEDIATE)
# Add custom target to run doxygen when ever the project is build
add_custom_target(doxygen
COMMAND "${DOXYGEN_EXECUTABLE}" "${PROJECT_BINARY_DIR}/doxyfile"
SOURCES "${PROJECT_BINARY_DIR}/doxyfile"
COMMENT "Generating API documentation with doxygen" VERBATIM)
add_dependencies(doxygen docdirs)
add_custom_target(doc ALL
COMMENT "Generated project documentation" VERBATIM)
add_dependencies(doc doxygen)
endif()
ament_package()
# Install includes.
install(
DIRECTORY
${PROJECT_SOURCE_DIR}/include/
DESTINATION
include
)
# Install config.h file.
install(
FILES
${PROJECT_BINARY_DIR}/include/rmw_microxrcedds_c/config.h
DESTINATION
include/rmw_microxrcedds_c
)
# Install library.
install(
TARGETS
${PROJECT_NAME}
ARCHIVE DESTINATION
lib
LIBRARY DESTINATION
lib
RUNTIME DESTINATION
bin
)
if(BUILD_DOCUMENTATION)
# Instalation of doxygen files
install(DIRECTORY ${PROJECT_BINARY_DIR}/doc/api_reference
DESTINATION ${DOC_INSTALL_DIR}
COMPONENT documentation)
endif()