From 9350355e1ae6b1a6b6881d108575aaf8a4d92d1c Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 17 Apr 2020 13:37:43 -0700 Subject: [PATCH] export targets in a addition to include directories / libraries Signed-off-by: Dirk Thomas --- rosidl_runtime_c/CMakeLists.txt | 7 +++++-- .../rosidl_runtime_c/primitives_sequence.h | 2 +- .../primitives_sequence_functions.h | 15 +++++++++++++++ .../include/rosidl_runtime_c/string.h | 1 + .../include/rosidl_runtime_c/string_bounds.h | 5 ++++- .../include/rosidl_runtime_c/u16string.h | 2 +- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/rosidl_runtime_c/CMakeLists.txt b/rosidl_runtime_c/CMakeLists.txt index b4abb6c4c..fa6a3051b 100644 --- a/rosidl_runtime_c/CMakeLists.txt +++ b/rosidl_runtime_c/CMakeLists.txt @@ -14,7 +14,6 @@ endif() find_package(ament_cmake_ros REQUIRED) find_package(rosidl_typesupport_interface REQUIRED) -include_directories(include) add_library(${PROJECT_NAME} "src/message_bounds.c" "src/message_type_support.c" @@ -23,6 +22,9 @@ add_library(${PROJECT_NAME} "src/string_functions.c" "src/u16string_functions.c" ) +target_include_directories(${PROJECT_NAME} PUBLIC + "$" + "$") ament_target_dependencies(${PROJECT_NAME} "rosidl_typesupport_interface") if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -37,6 +39,7 @@ endif() ament_export_dependencies(rosidl_typesupport_interface) ament_export_include_directories(include) ament_export_libraries(${PROJECT_NAME}) +ament_export_targets(${PROJECT_NAME}) ament_index_register_resource("rosidl_runtime_packages") @@ -50,7 +53,7 @@ install( DESTINATION include ) install( - TARGETS ${PROJECT_NAME} + TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence.h b/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence.h index c95320576..5c152a3c6 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence.h @@ -22,7 +22,7 @@ #define ROSIDL_RUNTIME_C__PRIMITIVE_SEQUENCE(STRUCT_NAME, TYPE_NAME) \ typedef struct rosidl_runtime_c__ ## STRUCT_NAME ## __Sequence \ { \ - TYPE_NAME * data; \ + TYPE_NAME * data; /*!< The pointer to an array of STRUCT_NAME */ \ size_t size; /*!< The number of valid items in data */ \ size_t capacity; /*!< The number of allocated items in data */ \ } rosidl_runtime_c__ ## STRUCT_NAME ## __Sequence; diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence_functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence_functions.h index e6ab252b6..e123637b2 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence_functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/primitives_sequence_functions.h @@ -26,6 +26,21 @@ extern "C" { #endif +/// Allocate the memory for the sequence. +/* Calling the function with an already allocated sequence will leak the + * previously allocated memory. + * + * \param sequence a pointer to a sequence struct + * \param size the number of items to allocate in the sequence, both sequence + * fields `size` and `capacity` are set to this parameter + * \return true if successful, false if the passed sequence pointer is null + * or the memory allocation failed + */ +/// Deallocate the memory of the sequence. +/* Calling the function with an already deallocated sequence is a no-op. + * + * \param sequence a pointer to a sequence struct + */ #define ROSIDL_RUNTIME_C__DECLARE_PRIMITIVE_SEQUENCE_FUNCTIONS(STRUCT_NAME, TYPE_NAME) \ ROSIDL_GENERATOR_C_PUBLIC \ bool rosidl_runtime_c__ ## STRUCT_NAME ## __Sequence__init( \ diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/string.h b/rosidl_runtime_c/include/rosidl_runtime_c/string.h index 1660b2523..23d1eeb4e 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/string.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/string.h @@ -22,6 +22,7 @@ /// String struct typedef struct rosidl_runtime_c__String { + /// The pointer to the first character, the sequence ends with a null byte. char * data; /// The length of the string (excluding the null byte). size_t size; diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/string_bounds.h b/rosidl_runtime_c/include/rosidl_runtime_c/string_bounds.h index fbd45cf45..50969946c 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/string_bounds.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/string_bounds.h @@ -18,9 +18,12 @@ #include /// String struct +/* The struct can describe the upper boundary of a rosidl_runtime_c__String + * as well as a rosidl_runtime_c__U16String. + */ typedef struct rosidl_runtime_c__String__bounds { - /// The length of the string (excluding the null byte). + /// The number of characters in the string (excluding the null character). size_t bounds; } rosidl_runtime_c__String__bounds; diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/u16string.h b/rosidl_runtime_c/include/rosidl_runtime_c/u16string.h index 1bc9f79c2..295a37bcc 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/u16string.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/u16string.h @@ -22,7 +22,7 @@ /// U16String struct typedef struct rosidl_runtime_c__U16String { - /// The pointer to the first character. + /// The pointer to the first character, the sequence ends with a null character. uint_least16_t * data; // using uint_least16_t to match a C++ std::u16string /// The length of the u16string (excluding the null byte). size_t size;