Skip to content

Commit 7ba5ffc

Browse files
committed
Static type support initial
Signed-off-by: Your Name <[email protected]> Default to OFF Signed-off-by: Your Name <[email protected]> Linter Signed-off-by: Your Name <[email protected]> Fix Signed-off-by: Your Name <[email protected]> Refactor Reafactor Signed-off-by: Your Name <[email protected]> Lint
1 parent 3bd7d81 commit 7ba5ffc

File tree

5 files changed

+74
-7
lines changed

5 files changed

+74
-7
lines changed

rosidl_typesupport_c/CMakeLists.txt

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.5)
22

33
project(rosidl_typesupport_c)
44

5+
option(ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT "Enable static typesupport" OFF)
6+
57
# Default to C11
68
if(NOT CMAKE_C_STANDARD)
79
set(CMAKE_C_STANDARD 11)
@@ -16,13 +18,17 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1618
endif()
1719

1820
find_package(ament_cmake_ros REQUIRED)
19-
find_package(rcpputils REQUIRED)
2021
find_package(rcutils REQUIRED)
2122
find_package(rosidl_runtime_c REQUIRED)
23+
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
24+
find_package(rcpputils REQUIRED)
25+
endif()
2226

23-
ament_export_dependencies(rcpputils)
2427
ament_export_dependencies(rosidl_runtime_c)
2528
ament_export_dependencies(rosidl_typesupport_interface)
29+
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
30+
ament_export_dependencies(rcpputils)
31+
endif()
2632

2733
ament_export_include_directories(include)
2834

@@ -36,15 +42,23 @@ if(WIN32)
3642
target_compile_definitions(${PROJECT_NAME}
3743
PRIVATE "ROSIDL_TYPESUPPORT_C_BUILDING_DLL")
3844
endif()
45+
target_compile_definitions(${PROJECT_NAME}
46+
PRIVATE
47+
$<$<BOOL:${ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT}>:ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT>
48+
)
3949
target_include_directories(${PROJECT_NAME} PUBLIC
4050
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
4151
"$<INSTALL_INTERFACE:include>")
4252

4353
ament_target_dependencies(${PROJECT_NAME}
44-
"rcpputils"
4554
"rcutils"
4655
"rosidl_runtime_c"
4756
)
57+
if(NOT ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT)
58+
ament_target_dependencies(${PROJECT_NAME}
59+
"rcpputils"
60+
)
61+
endif()
4862
ament_export_libraries(${PROJECT_NAME})
4963
ament_export_targets(${PROJECT_NAME})
5064

rosidl_typesupport_c/cmake/rosidl_typesupport_c_generate_interfaces.cmake

+5-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,10 @@ if(NOT typesupports MATCHES ";")
126126
${rosidl_generate_interfaces_TARGET}__${typesupports})
127127
else()
128128
if("${rosidl_typesupport_c_LIBRARY_TYPE}" STREQUAL "STATIC")
129-
message(FATAL_ERROR "Multiple typesupports [${typesupports}] but static "
130-
"linking was requested")
129+
target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix}
130+
PRIVATE
131+
ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
132+
)
131133
endif()
132134
endif()
133135

@@ -151,6 +153,7 @@ add_dependencies(
151153
add_dependencies(
152154
${rosidl_generate_interfaces_TARGET}${_target_suffix}
153155
${rosidl_generate_interfaces_TARGET}__rosidl_generator_c
156+
${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_c
154157
)
155158

156159
if(NOT rosidl_generate_interfaces_SKIP_INSTALL)

rosidl_typesupport_c/resource/msg__type_support.cpp.em

+21
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,34 @@ typedef struct _@(message.structure.namespaced_type.name)_type_support_data_t
7676
void * data[@(len(type_supports))];
7777
} _@(message.structure.namespaced_type.name)_type_support_data_t;
7878

79+
#ifdef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
80+
#ifdef __cplusplus
81+
extern "C"
82+
{
83+
#endif
84+
@[for type_support in sorted(type_supports)]@
85+
rosidl_message_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name))();
86+
@[end for]@
87+
#ifdef __cplusplus
88+
}
89+
#endif
90+
91+
static _@(message.structure.namespaced_type.name)_type_support_data_t _@(message.structure.namespaced_type.name)_message_typesupport_data = {
92+
{
93+
@[for type_support in sorted(type_supports)]@
94+
(void*) ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(message.structure.namespaced_type.name)),
95+
@[end for]@
96+
}
97+
};
98+
#else
7999
static _@(message.structure.namespaced_type.name)_type_support_data_t _@(message.structure.namespaced_type.name)_message_typesupport_data = {
80100
{
81101
@[for type_support in sorted(type_supports)]@
82102
0, // will store the shared library later
83103
@[end for]@
84104
}
85105
};
106+
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
86107

87108
static const type_support_map_t _@(message.structure.namespaced_type.name)_message_typesupport_map = {
88109
@(len(type_supports)),

rosidl_typesupport_c/resource/srv__type_support.cpp.em

+21
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,34 @@ typedef struct _@(service.namespaced_type.name)_type_support_data_t
8484
void * data[@(len(type_supports))];
8585
} _@(service.namespaced_type.name)_type_support_data_t;
8686

87+
#ifdef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
88+
#ifdef __cplusplus
89+
extern "C"
90+
{
91+
#endif
92+
@[for type_support in sorted(type_supports)]@
93+
rosidl_service_type_support_t * ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name))();
94+
@[end for]@
95+
#ifdef __cplusplus
96+
}
97+
#endif
98+
99+
static _@(service.namespaced_type.name)_type_support_data_t _@(service.namespaced_type.name)_service_typesupport_data = {
100+
{
101+
@[for type_support in sorted(type_supports)]@
102+
(void*) ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(@(type_support), @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.namespaced_type.name)),
103+
@[end for]@
104+
}
105+
};
106+
#else
87107
static _@(service.namespaced_type.name)_type_support_data_t _@(service.namespaced_type.name)_service_typesupport_data = {
88108
{
89109
@[for type_support in sorted(type_supports)]@
90110
0, // will store the shared library later
91111
@[end for]@
92112
}
93113
};
114+
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
94115

95116
static const type_support_map_t _@(service.namespaced_type.name)_service_typesupport_map = {
96117
@(len(type_supports)),

rosidl_typesupport_c/src/type_support_dispatch.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef TYPE_SUPPORT_DISPATCH_HPP_
1616
#define TYPE_SUPPORT_DISPATCH_HPP_
1717

18+
#ifndef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
19+
1820
#include <cstddef>
1921
#include <cstdio>
2022
#include <cstring>
@@ -24,6 +26,9 @@
2426
#include <string>
2527

2628
#include "rcpputils/shared_library.hpp"
29+
30+
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
31+
2732
#include "rcutils/error_handling.h"
2833
#include "rcutils/snprintf.h"
2934
#include "rosidl_typesupport_c/identifier.h"
@@ -50,6 +55,8 @@ get_typesupport_handle_function(
5055
if (strcmp(map->typesupport_identifier[i], identifier) != 0) {
5156
continue;
5257
}
58+
typedef const TypeSupport * (* funcSignature)(void);
59+
#ifndef ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
5360
rcpputils::SharedLibrary * lib = nullptr;
5461

5562
if (!map->data[i]) {
@@ -103,9 +110,10 @@ get_typesupport_handle_function(
103110
map->symbol_name[i], e.what());
104111
return nullptr;
105112
}
106-
107-
typedef const TypeSupport * (* funcSignature)(void);
108113
funcSignature func = reinterpret_cast<funcSignature>(sym);
114+
#else
115+
funcSignature func = reinterpret_cast<funcSignature>(map->data[i]);
116+
#endif // ROSIDL_TYPESUPPORT_STATIC_TYPESUPPORT
109117
const TypeSupport * ts = func();
110118
return ts;
111119
}

0 commit comments

Comments
 (0)