|
| 1 | +# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +cmake_minimum_required(VERSION 3.5) |
| 16 | +cmake_policy(SET CMP0057 NEW) |
| 17 | + |
| 18 | +set(PACKAGE_VERSION "0.1.0") |
| 19 | +project(rmw_microxrcedds |
| 20 | + VERSION |
| 21 | + ${PACKAGE_VERSION} |
| 22 | + LANGUAGES |
| 23 | + C |
| 24 | + ) |
| 25 | + |
| 26 | +find_program(CLANG_TIDY clang-tidy) |
| 27 | +if(CLANG_TIDY) |
| 28 | + set(CMAKE_C_CLANG_TIDY clang-tidy -checks=* -extra-arg=-Wno-unknown-warning-option) |
| 29 | +endif() |
| 30 | + |
| 31 | +find_package(ament_cmake_ros REQUIRED) |
| 32 | +find_package(rcutils REQUIRED) |
| 33 | + |
| 34 | +find_package(microxrcedds_client REQUIRED) |
| 35 | +find_package(microcdr REQUIRED) |
| 36 | + |
| 37 | +find_package(rmw REQUIRED) |
| 38 | + |
| 39 | +# RMW default configuration |
| 40 | +set(RMW_UXRCE_TRANSPORT "udp" CACHE STRING "Sets Micro XRCE-DDS transport to use. (udp | serial | custom)") |
| 41 | +set(RMW_UXRCE_IPV "ipv6" CACHE STRING "Sets Micro XRCE-DDS IP version to use. (ipv4 | ipv6)") |
| 42 | +set(RMW_UXRCE_CREATION_MODE "xml" CACHE STRING "Sets creation mode in Micro XRCE-DDS. (xml | refs)") |
| 43 | +set(RMW_UXRCE_STREAM_HISTORY "55" CACHE STRING "This value sets the number of MTUs to buffer. Micro XRCE-DDS client configuration provides their size") |
| 44 | +set(RMW_UXRCE_MAX_HISTORY "4" CACHE STRING "This value sets the number of history slots available for RMW subscriptions, requests and replies") |
| 45 | +set(RMW_UXRCE_MAX_NODES "4" CACHE STRING "This value sets the maximum number of nodes.") |
| 46 | +set(RMW_UXRCE_MAX_PUBLISHERS "4" CACHE STRING "This value sets the maximum number of publishers for an application.") |
| 47 | +set(RMW_UXRCE_MAX_SUBSCRIPTIONS "4" CACHE STRING "This value sets the maximum number of subscriptions for an application.") |
| 48 | +set(RMW_UXRCE_MAX_SERVICES "4" CACHE STRING "This value sets the maximum number of services for an application.") |
| 49 | +set(RMW_UXRCE_MAX_CLIENTS "4" CACHE STRING "This value sets the maximum number of clients for an application.") |
| 50 | +set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a node name.") |
| 51 | +set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.") |
| 52 | +set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.") |
| 53 | +set(RMW_UXRCE_XML_BUFFER_LENGTH "600" CACHE STRING "This value sets the maximum number of characters for a XML buffer.") |
| 54 | +set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.") |
| 55 | + |
| 56 | +# Transport handle define macros. |
| 57 | +set(MICRO_XRCEDDS_SERIAL OFF) |
| 58 | +set(MICRO_XRCEDDS_UDP OFF) |
| 59 | +set(MICRO_XRCEDDS_CUSTOM_SERIAL OFF) |
| 60 | +set(MICRO_XRCEDDS_IPV4 OFF) |
| 61 | +set(MICRO_XRCEDDS_IPV6 OFF) |
| 62 | +if(${RMW_UXRCE_TRANSPORT} STREQUAL "serial") |
| 63 | + set(MICRO_XRCEDDS_SERIAL ON) |
| 64 | + set(RMW_UXRCE_DEFAULT_SERIAL_DEVICE "/dev/ttyAMA0" CACHE STRING "Sets the agent serial port.") |
| 65 | +elseif(${RMW_UXRCE_TRANSPORT} STREQUAL "udp") |
| 66 | + set(MICRO_XRCEDDS_UDP ON) |
| 67 | + if(${RMW_UXRCE_IPV} STREQUAL "ipv4") |
| 68 | + set(MICRO_XRCEDDS_IPV4 ON) |
| 69 | + set(RMW_UXRCE_DEFAULT_UDP_IP "127.0.0.1" CACHE STRING "Sets the agent IP address.") |
| 70 | + elseif(${RMW_UXRCE_IPV} STREQUAL "ipv6") |
| 71 | + set(MICRO_XRCEDDS_IPV6 ON) |
| 72 | + set(RMW_UXRCE_DEFAULT_UDP_IP "::1" CACHE STRING "Sets the agent IP address.") |
| 73 | + endif () |
| 74 | + set(RMW_UXRCE_DEFAULT_UDP_PORT "8888" CACHE STRING "Sets the agent IP port.") |
| 75 | +elseif(${RMW_UXRCE_TRANSPORT} STREQUAL "custom_serial") |
| 76 | + set(MICRO_XRCEDDS_CUSTOM_SERIAL ON) |
| 77 | +else() |
| 78 | + message(FATAL_ERROR "Transport not supported. Use \"serial\", \"udp\", \"custom\"") |
| 79 | +endif() |
| 80 | + |
| 81 | +# Create entities type define macros. |
| 82 | +set(MICRO_XRCEDDS_USE_REFS OFF) |
| 83 | +set(MICRO_XRCEDDS_USE_XML OFF) |
| 84 | +if(${RMW_UXRCE_CREATION_MODE} STREQUAL "refs") |
| 85 | + set(MICRO_XRCEDDS_USE_REFS ON) |
| 86 | +elseif(${RMW_UXRCE_CREATION_MODE} STREQUAL "xml") |
| 87 | + set(MICRO_XRCEDDS_USE_XML ON) |
| 88 | +else() |
| 89 | + message(FATAL_ERROR "Creation mode not supported. Use \"refs\" or \"xml\"") |
| 90 | +endif() |
| 91 | + |
| 92 | +# Create source files with the define |
| 93 | +configure_file(${PROJECT_SOURCE_DIR}/src/config.h.in |
| 94 | + ${PROJECT_BINARY_DIR}/include/rmw_microxrcedds_c/config.h |
| 95 | + ) |
| 96 | + |
| 97 | +set(SRCS |
| 98 | + src/identifiers.c |
| 99 | + src/memory.c |
| 100 | + src/rmw_client.c |
| 101 | + src/rmw_compare_gids_equal.c |
| 102 | + src/rmw_count.c |
| 103 | + src/rmw_get_gid_for_publisher.c |
| 104 | + src/rmw_get_implementation_identifier.c |
| 105 | + src/rmw_get_serialization_format.c |
| 106 | + src/rmw_guard_condition.c |
| 107 | + src/rmw_init.c |
| 108 | + src/rmw_logging.c |
| 109 | + src/rmw_microxrcedds_topic.c |
| 110 | + src/rmw_node.c |
| 111 | + src/rmw_node_info_and_types.c |
| 112 | + src/rmw_node_names.c |
| 113 | + src/rmw_publish.c |
| 114 | + src/rmw_publisher.c |
| 115 | + src/rmw_request.c |
| 116 | + src/rmw_response.c |
| 117 | + src/rmw_serialize.c |
| 118 | + src/rmw_service.c |
| 119 | + src/rmw_service_names_and_types.c |
| 120 | + src/rmw_service_server_is_available.c |
| 121 | + src/rmw_subscription.c |
| 122 | + src/rmw_take.c |
| 123 | + src/rmw_topic_names_and_types.c |
| 124 | + src/rmw_trigger_guard_condition.c |
| 125 | + src/rmw_uros_options.c |
| 126 | + src/rmw_wait.c |
| 127 | + src/rmw_wait_set.c |
| 128 | + src/types.c |
| 129 | + src/utils.c |
| 130 | + src/callbacks.c |
| 131 | + ) |
| 132 | + |
| 133 | +add_library(${PROJECT_NAME} |
| 134 | + ${SRCS} |
| 135 | + ) |
| 136 | + |
| 137 | +target_link_libraries(${PROJECT_NAME} |
| 138 | + microcdr |
| 139 | + microxrcedds_client |
| 140 | + ) |
| 141 | + |
| 142 | +# Type support lock-up mechanism |
| 143 | +find_package(rosidl_typesupport_microxrcedds_c) |
| 144 | +if(rosidl_typesupport_microxrcedds_c_FOUND) |
| 145 | + ament_target_dependencies(${PROJECT_NAME} |
| 146 | + "rosidl_typesupport_microxrcedds_c" |
| 147 | + ) |
| 148 | + target_compile_definitions(${PROJECT_NAME} |
| 149 | + PUBLIC |
| 150 | + HAVE_C_TYPESUPPORT |
| 151 | + ) |
| 152 | + find_package(rosidl_typesupport_microxrcedds_cpp) |
| 153 | +else() |
| 154 | + find_package(rosidl_typesupport_microxrcedds_cpp REQUIRED) |
| 155 | +endif() |
| 156 | +if(rosidl_typesupport_microxrcedds_cpp_FOUND) |
| 157 | + ament_target_dependencies(${PROJECT_NAME} |
| 158 | + "rosidl_typesupport_microxrcedds_cpp" |
| 159 | + ) |
| 160 | + target_compile_definitions(${PROJECT_NAME} |
| 161 | + PUBLIC |
| 162 | + HAVE_CPP_TYPESUPPORT |
| 163 | + ) |
| 164 | +endif() |
| 165 | + |
| 166 | +ament_target_dependencies(${PROJECT_NAME} |
| 167 | + "rcutils" |
| 168 | + "rmw" |
| 169 | + ) |
| 170 | + |
| 171 | +configure_rmw_library(${PROJECT_NAME}) |
| 172 | + |
| 173 | +target_include_directories(${PROJECT_NAME} |
| 174 | + PUBLIC |
| 175 | + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 176 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> |
| 177 | + ) |
| 178 | + |
| 179 | +set_target_properties(${PROJECT_NAME} PROPERTIES |
| 180 | + C_STANDARD |
| 181 | + 99 |
| 182 | + C_STANDARD_REQUIRED |
| 183 | + YES |
| 184 | + ) |
| 185 | + |
| 186 | +target_compile_options(${PROJECT_NAME} |
| 187 | + PRIVATE |
| 188 | + $<$<C_COMPILER_ID:GNU>:-Wall> |
| 189 | + $<$<C_COMPILER_ID:GNU>:-Wextra> |
| 190 | + $<$<C_COMPILER_ID:GNU>:-pedantic> |
| 191 | + $<$<C_COMPILER_ID:GNU>:-Werror-implicit-function-declaration> |
| 192 | + $<$<C_COMPILER_ID:GNU>:$<$<VERSION_GREATER:$<C_COMPILER_VERSION>,8.1>:-Wcast-align=strict>> |
| 193 | + $<$<C_COMPILER_ID:GNU>:-Wvla> |
| 194 | + $<$<C_COMPILER_ID:MSVC>:/Wall> |
| 195 | + ) |
| 196 | + |
| 197 | +ament_export_include_directories(${PROJECT_SOURCE_DIR}/include) |
| 198 | +ament_export_libraries(${PROJECT_NAME}) |
| 199 | + |
| 200 | +ament_export_dependencies( |
| 201 | + rcutils |
| 202 | + rmw |
| 203 | + ) |
| 204 | + |
| 205 | +if(rosidl_typesupport_microxrcedds_c_FOUND) |
| 206 | + ament_export_dependencies(rosidl_typesupport_microxrcedds_c) |
| 207 | + set(implementations |
| 208 | + "c:rosidl_typesupport_c:rosidl_typesupport_microxrcedds_c" |
| 209 | + ) |
| 210 | +endif() |
| 211 | +if(rosidl_typesupport_microxrcedds_cpp_FOUND) |
| 212 | + ament_export_dependencies(rosidl_typesupport_microxrcedds_cpp) |
| 213 | + set(implementations |
| 214 | + ${implementations} |
| 215 | + "cpp:rosidl_typesupport_cpp:rosidl_typesupport_microxrcedds_cpp" |
| 216 | + ) |
| 217 | +endif() |
| 218 | + |
| 219 | +register_rmw_implementation( |
| 220 | + ${implementations} |
| 221 | + ) |
| 222 | + |
| 223 | +if(BUILD_TESTING) |
| 224 | + find_package(ament_lint_auto REQUIRED) |
| 225 | + ament_lint_auto_find_test_dependencies() |
| 226 | + add_subdirectory(test) |
| 227 | +endif() |
| 228 | + |
| 229 | +ament_package() |
| 230 | + |
| 231 | +# Install config.h file. |
| 232 | +install( |
| 233 | + FILES |
| 234 | + ${PROJECT_BINARY_DIR}/include/rmw_microxrcedds_c/config.h |
| 235 | + DESTINATION |
| 236 | + include/rmw_microxrcedds_c |
| 237 | + ) |
| 238 | + |
| 239 | +# Install includes. |
| 240 | +install( |
| 241 | + DIRECTORY |
| 242 | + ${PROJECT_SOURCE_DIR}/include/ |
| 243 | + DESTINATION |
| 244 | + include |
| 245 | + ) |
| 246 | + |
| 247 | +# Install library. |
| 248 | +install( |
| 249 | + TARGETS |
| 250 | + ${PROJECT_NAME} |
| 251 | + ARCHIVE DESTINATION |
| 252 | + lib |
| 253 | + LIBRARY DESTINATION |
| 254 | + lib |
| 255 | + RUNTIME DESTINATION |
| 256 | + bin |
| 257 | + ) |
0 commit comments