### ROSIDL Runtime C++ Installation Rules Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_cpp/CMakeLists.txt This snippet defines the installation rules for the rosidl_runtime_cpp package. It specifies which directories and targets should be installed. ```cmake install( DIRECTORY include/ DESTINATION include/${PROJECT_NAME} ) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ) ament_package() ``` -------------------------------- ### Install package files Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_c/CMakeLists.txt Installs include directories and target binaries, and finalizes the ament package. ```cmake install( DIRECTORY include/ DESTINATION include/${PROJECT_NAME} ) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) ament_package() ``` -------------------------------- ### ROS 2 rosidl CMakeLists.txt Configuration Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_cmake/CMakeLists.txt This snippet shows the basic CMake configuration for the rosidl package. It finds required packages like ament_cmake and ament_cmake_python, installs the Python package, and sets up testing dependencies if BUILD_TESTING is enabled. It also configures package extras and installs the cmake directory. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_cmake NONE) find_package(ament_cmake REQUIRED) find_package(ament_cmake_python REQUIRED) ament_python_install_package(${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() endif() ament_package( CONFIG_EXTRAS "rosidl_cmake-extras.cmake" ) install( DIRECTORY cmake DESTINATION share/${PROJECT_NAME} ) ``` -------------------------------- ### Configure rosidl_typesupport_interface CMake Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_typesupport_interface/CMakeLists.txt Defines the interface library, sets up include directories for build and install interfaces, and exports the package targets. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_typesupport_interface NONE) find_package(ament_cmake REQUIRED) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE "$" "$") # Export old-style CMake variables ament_export_include_directories("include/${PROJECT_NAME}") # Export modern CMake targets ament_export_targets(${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() # For gtest enable_language(C CXX) # Default to C11 if(NOT CMAKE_C_STANDARD) set(CMAKE_C_STANDARD 11) endif() # Default to C++17 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() find_package(ament_cmake_gtest REQUIRED) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() ament_add_gtest(test_macros test/test_macros.cpp) if(TARGET test_macros) target_link_libraries(test_macros ${PROJECT_NAME}) endif() endif() ament_package() install( DIRECTORY include/ DESTINATION include/${PROJECT_NAME} ) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ) ``` -------------------------------- ### ROS 2 rosidl Package CMake Configuration Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_buffer_backend/CMakeLists.txt This CMakeLists.txt file sets up a ROS 2 rosidl package. It configures C++ standards, finds necessary dependencies like ament_cmake and rmw, defines an INTERFACE library, and manages installation rules for headers and the library target. It also includes optional testing configurations. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_buffer_backend) # Default to C++17 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # Find dependencies find_package(ament_cmake REQUIRED) find_package(rmw REQUIRED) # This is a header-only library add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE $ $ ) target_link_libraries(${PROJECT_NAME} INTERFACE rmw::rmw ) # Install headers install( DIRECTORY include/ DESTINATION include/${PROJECT_NAME} ) # Install library target install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include/${PROJECT_NAME} ) # Export dependencies ament_export_targets(${PROJECT_NAME} HAS_LIBRARY_TARGET) ament_export_dependencies(rmw) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() endif() ament_package() ``` -------------------------------- ### CMake configuration for rosidl_parser Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_parser/CMakeLists.txt Defines the project requirements, Python package installation, and testing configuration for the rosidl_parser package. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_parser NONE) find_package(ament_cmake REQUIRED) find_package(ament_cmake_python REQUIRED) ament_python_install_package(${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(ament_cmake_mypy REQUIRED) ament_lint_auto_find_test_dependencies() endif() ament_package() if(BUILD_TESTING) find_package(ament_cmake_pytest REQUIRED) ament_add_pytest_test(pytest test) endif() install( PROGRAMS bin/idl2png DESTINATION lib/${PROJECT_NAME}) ``` -------------------------------- ### CMake configuration for rosidl_buffer Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_buffer/CMakeLists.txt Defines the project, sets C++17 standards, configures compiler warnings, and manages library installation and testing. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_buffer) # 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 dependencies find_package(ament_cmake REQUIRED) add_library(${PROJECT_NAME} SHARED src/c_helpers.cpp ) target_include_directories(${PROJECT_NAME} PUBLIC $ $ ) target_compile_definitions(${PROJECT_NAME} PRIVATE "ROSIDL_BUFFER_BUILDING_DLL") # Install headers install( DIRECTORY include/ DESTINATION include/${PROJECT_NAME} ) # Install library target install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include/${PROJECT_NAME} ) # Export modern CMake targets ament_export_targets(${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() find_package(ament_cmake_gtest REQUIRED) ament_add_gtest(test_buffer test/test_buffer.cpp) if(TARGET test_buffer) target_link_libraries(test_buffer ${PROJECT_NAME}) endif() ament_add_gtest(test_c_helpers test/test_c_helpers.cpp) if(TARGET test_c_helpers) target_link_libraries(test_c_helpers ${PROJECT_NAME}) endif() endif() ament_package() ``` -------------------------------- ### Configure rosidl_runtime_c CMake build Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_c/CMakeLists.txt Sets up the C and C++ standards, finds required dependencies, and defines the library target for rosidl_runtime_c. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_runtime_c C) # Default to C11 if(NOT CMAKE_C_STANDARD) set(CMAKE_C_STANDARD 11) endif() # 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_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake REQUIRED) find_package(ament_cmake_ros_core REQUIRED) find_package(rcutils REQUIRED) find_package(rosidl_buffer REQUIRED) find_package(rosidl_typesupport_interface REQUIRED) file(GLOB type_description_sources "src/type_description/*.c") file(GLOB type_description_includes "include/rosidl_runtime_c/type_description/*.h") add_library(${PROJECT_NAME} "src/message_type_support.c" "src/primitives_sequence_functions.c" "src/sequence_bound.c" "src/service_type_support.c" "src/string_functions.c" "src/type_hash.c" "src/u16string_functions.c" "src/type_description_utils.c" ${type_description_sources} ) target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") target_link_libraries(${PROJECT_NAME} PUBLIC rcutils::rcutils rosidl_buffer::rosidl_buffer rosidl_typesupport_interface::rosidl_typesupport_interface ) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_OPTIONS -Wall -Wextra -Wpedantic) endif() if(WIN32) target_compile_definitions(${PROJECT_NAME} PRIVATE "ROSIDL_GENERATOR_C_BUILDING_DLL") endif() if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION) target_compile_definitions(${PROJECT_NAME} PUBLIC RCUTILS_ENABLE_FAULT_INJECTION) endif() ament_export_dependencies(rcutils rosidl_buffer rosidl_typesupport_interface) # Export old-style CMake variables ament_export_include_directories("include/${PROJECT_NAME}") ament_export_libraries(${PROJECT_NAME}) ``` -------------------------------- ### ROSIDL Runtime C++ CMakeLists.txt Configuration Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_cpp/CMakeLists.txt This snippet defines the CMake build configuration for the rosidl_runtime_cpp package. It sets up the project, finds necessary packages, defines an interface library, configures include directories and link libraries, and handles platform-specific definitions. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_runtime_cpp) find_package(ament_cmake REQUIRED) find_package(rosidl_runtime_c REQUIRED) find_package(rosidl_buffer REQUIRED) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE "$" "$") target_link_libraries(${PROJECT_NAME} INTERFACE rosidl_runtime_c::rosidl_runtime_c rosidl_buffer::rosidl_buffer) if(MSVC) target_compile_definitions(${PROJECT_NAME} INTERFACE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) endif() # Export old-style CMake variables ament_export_include_directories("include/${PROJECT_NAME}") # Export modern CMake targets ament_export_targets(${PROJECT_NAME}) ament_index_register_resource("rosidl_runtime_packages") ament_export_dependencies(rosidl_runtime_c rosidl_buffer) ``` -------------------------------- ### Configure linters for generated code Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_c/CMakeLists.txt Configures cppcheck, cpplint, and uncrustify for testing generated source code. ```cmake if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(performance_test_fixture REQUIRED) # Give cppcheck hints about macro definitions coming from outside this package get_target_property(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS performance_test_fixture::performance_test_fixture INTERFACE_INCLUDE_DIRECTORIES) set(AMENT_LINT_AUTO_FILE_EXCLUDE ${type_description_includes} ${type_description_sources}) ament_lint_auto_find_test_dependencies() # Run specific linters on copied generated code if(ament_cmake_cppcheck_FOUND) ament_cppcheck( TESTNAME "cppcheck_copied_type_description_interfaces" ${type_description_includes} ${type_description_sources}) endif() if(ament_cmake_cpplint_FOUND) ament_cpplint( TESTNAME "cpplint_copied_type_description_interfaces" # the generated code might contain longer lines for templated types MAX_LINE_LENGTH 999 ${type_description_includes} ${type_description_sources}) endif() if(ament_cmake_uncrustify_FOUND) ament_uncrustify( TESTNAME "uncrustify_copied_type_description_interfaces" # the generated code might contain longer lines for templated types MAX_LINE_LENGTH 0 ${type_description_includes} ${type_description_sources}) endif() ``` -------------------------------- ### Configure CMake for ROS 2 Interface Generation Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_generator_tests/CMakeLists.txt Sets up the project, compiler standards, and finds necessary ROS 2 dependencies for interface generation and testing. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_generator_tests) # Default to C++17 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() # Default to C11 if(NOT CMAKE_C_STANDARD) set(CMAKE_C_STANDARD 11) 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) if(BUILD_TESTING) find_package(ament_cmake_gtest REQUIRED) find_package(ament_cmake_pytest REQUIRED) find_package(ament_lint_auto REQUIRED) find_package(rosidl_cmake REQUIRED) find_package(rosidl_generator_cpp REQUIRED) find_package(rosidl_generator_type_description REQUIRED) find_package(rosidl_runtime_c REQUIRED) find_package(rosidl_runtime_cpp REQUIRED) find_package(test_interface_files REQUIRED) find_package(type_description_interfaces REQUIRED) ament_lint_auto_find_test_dependencies() rosidl_generate_interfaces(${PROJECT_NAME} ${test_interface_files_ACTION_FILES} ${test_interface_files_MSG_FILES} ${test_interface_files_SRV_FILES} msg/BasicIdl.idl msg/SmallConstant.msg ADD_LINTER_TESTS SKIP_INSTALL ) rosidl_get_typesupport_target(cpp_generator_target "${PROJECT_NAME}" "rosidl_generator_cpp") macro(add_generator_cpp_test) ament_add_gtest(${test_name} test/rosidl_generator_cpp/${test_name}.cpp) if(TARGET ${test_name}) add_dependencies(${test_name} ${PROJECT_NAME}) target_link_libraries(${test_name} ${cpp_generator_target} rosidl_runtime_cpp::rosidl_runtime_cpp ) endif() endmacro() if(MSVC) # https://developercommunity.visualstudio.com/content/problem/919371/c2017-illegal-escape-sequence-when-using-in-a-raw.html set_source_files_properties( test/rosidl_generator_cpp/test_traits.cpp PROPERTIES COMPILE_FLAGS "/Zc:preprocessor") endif() set(generator_cpp_test_names test_msg_builder test_msg_initialization test_srv_initialization test_interfaces test_msg_datatype test_name test_traits ) foreach(test_name ${generator_cpp_test_names}) add_generator_cpp_test() endforeach() rosidl_get_typesupport_target(c_generator_target "${PROJECT_NAME}" "rosidl_generator_c") add_executable( test_compilation_c test/rosidl_generator_c/test_compilation.c test/rosidl_generator_c/separate_compilation.c ) ament_add_test( test_compilation_c COMMAND "$" GENERATE_RESULT_FOR_RETURN_CODE_ZERO ) target_link_libraries(test_compilation_c ${c_generator_target} rosidl_runtime_c::rosidl_runtime_c ) add_executable(test_interfaces_c test/rosidl_generator_c/test_interfaces.c) ament_add_test( test_interfaces_c COMMAND "$" GENERATE_RESULT_FOR_RETURN_CODE_ZERO ) target_link_libraries(test_interfaces_c ${c_generator_target} rosidl_runtime_c::rosidl_runtime_c ) add_executable( test_invalid_initialization_c test/rosidl_generator_c/test_invalid_initialization.c ) ament_add_test( test_invalid_initialization_c COMMAND "$" GENERATE_RESULT_FOR_RETURN_CODE_ZERO ) target_link_libraries(test_invalid_initialization_c ${c_generator_target} rosidl_runtime_c::rosidl_runtime_c ) add_executable( test_descriptions_c test/rosidl_generator_c/test_descriptions.c ) ament_add_test( test_descriptions_c COMMAND "$" GENERATE_RESULT_FOR_RETURN_CODE_ZERO ) target_link_libraries(test_descriptions_c ${c_generator_target} rosidl_runtime_c::rosidl_runtime_c type_description_interfaces::type_description_interfaces ) ament_add_pytest_test(test_hash_generator test/rosidl_generator_type_description ENV GENERATED_TEST_FILE_DIR=${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_type_description/${PROJECT_NAME} ) endif() ament_package() if(TEST cpplint) # must set the property after ament_package() set_tests_properties(cpplint PROPERTIES TIMEOUT 300) endif() ``` -------------------------------- ### ROSIDL Runtime C++ Testing Configuration Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_cpp/CMakeLists.txt This snippet configures testing for the rosidl_runtime_cpp package, including finding linting and testing packages, setting up C++ standards and compiler flags, and adding Google Test and performance tests. ```cmake if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(performance_test_fixture REQUIRED) # Give cppcheck hints about macro definitions coming from outside this package get_target_property(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS performance_test_fixture::performance_test_fixture INTERFACE_INCLUDE_DIRECTORIES) file(GLOB type_description_includes "include/rosidl_runtime_cpp/type_description/*.hpp") set(AMENT_LINT_AUTO_FILE_EXCLUDE ${type_description_includes}) ament_lint_auto_find_test_dependencies() # Run specific linters on copied generated code if(ament_cmake_cppcheck_FOUND) ament_cppcheck( TESTNAME "cppcheck_copied_type_description_interfaces" ${type_description_includes}) endif() if(ament_cmake_cpplint_FOUND) ament_cpplint( TESTNAME "cpplint_copied_type_description_interfaces" # the generated code might contain longer lines for templated types MAX_LINE_LENGTH 999 ${type_description_includes}) endif() if(ament_cmake_uncrustify_FOUND) ament_uncrustify( TESTNAME "uncrustify_copied_type_description_interfaces" # the generated code might contain longer lines for templated types MAX_LINE_LENGTH 0 ${type_description_includes}) endif() find_package(ament_cmake_gtest REQUIRED) # 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() ament_add_gtest(test_bounded_vector test/test_bounded_vector.cpp) if(TARGET test_bounded_vector) target_link_libraries(test_bounded_vector ${PROJECT_NAME}) endif() add_performance_test(benchmark_bounded_vector test/benchmark/benchmark_bounded_vector.cpp) if(TARGET benchmark_bounded_vector) target_link_libraries(benchmark_bounded_vector ${PROJECT_NAME}) endif() endif() ``` -------------------------------- ### Configure CMake for ROS 2 Interface Introspection Tests Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_typesupport_introspection_tests/CMakeLists.txt Sets up the project, finds necessary ROS 2 packages, configures compiler standards, generates interfaces, and registers GTest targets. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_typesupport_introspection_tests) find_package(ament_cmake REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() # 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() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # When building under Clang, the "TYPED_TEST_SUITE" macros in the tests print the following # warning: "must specify at least one argument for '...' parameter of variadic macro". # Since this isn't really a problem, and will be allowed under C++20, just disable the warning. add_compile_options(-Wno-gnu-zero-variadic-macro-arguments) endif() find_package(rosidl_cmake REQUIRED) find_package(rosidl_generator_c REQUIRED) find_package(rosidl_generator_cpp REQUIRED) find_package(rosidl_typesupport_introspection_c REQUIRED) find_package(rosidl_typesupport_introspection_cpp REQUIRED) find_package(test_interface_files REQUIRED) # Drop BoundedPlainSequences as BoundedSequences # already encompasses all the same member types list( FILTER test_interface_files_MSG_FILES EXCLUDE REGEX ".*BoundedPlainSequences.*") rosidl_generate_interfaces(${PROJECT_NAME} ${test_interface_files_MSG_FILES} ${test_interface_files_SRV_FILES} # ${test_interface_files_ACTION_FILES} SKIP_INSTALL ) find_package(rosidl_buffer REQUIRED) find_package(rcutils REQUIRED) find_package(rcpputils REQUIRED) find_package(rosidl_typesupport_interface REQUIRED) add_library(${PROJECT_NAME}_library INTERFACE) target_include_directories(${PROJECT_NAME}_library INTERFACE include/) target_link_libraries(${PROJECT_NAME}_library INTERFACE rosidl_buffer::rosidl_buffer rcutils::rcutils rcpputils::rcpputils rosidl_typesupport_interface::rosidl_typesupport_interface rosidl_typesupport_introspection_c::rosidl_typesupport_introspection_c rosidl_typesupport_introspection_cpp::rosidl_typesupport_introspection_cpp) target_compile_features(${PROJECT_NAME}_library INTERFACE cxx_std_17) find_package(ament_cmake_gtest REQUIRED) file(GLOB test_files test/test_*.cpp) foreach(test_file ${test_files}) get_filename_component(target ${test_file} NAME_WE) ament_add_gtest(${target} ${test_file} # Ensure typesupport introspection libraries can be found APPEND_LIBRARY_DIRS "${CMAKE_CURRENT_BINARY_DIR}" ) if(TARGET ${target}) target_include_directories(${target} PRIVATE test) target_link_libraries(${target} ${PROJECT_NAME}_library ${PROJECT_NAME}__rosidl_generator_c ${PROJECT_NAME}__rosidl_generator_cpp ${PROJECT_NAME}__rosidl_typesupport_introspection_c ${PROJECT_NAME}__rosidl_typesupport_introspection_cpp) endif() endforeach() endif() ament_package() ``` -------------------------------- ### ROS 2 rosidl_typesupport_introspection_cpp CMakeLists.txt Configuration Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_typesupport_introspection_cpp/CMakeLists.txt This CMakeLists.txt file sets up the build for the rosidl_typesupport_introspection_cpp package. It includes C++17 as the default standard, enables compiler warnings for GCC and Clang, and finds required ament packages. It also defines library targets and handles platform-specific compile definitions for Windows DLLs. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_typesupport_introspection_cpp) # Default to C++17 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_python REQUIRED) find_package(ament_cmake_ros_core REQUIRED) find_package(rosidl_runtime_cpp REQUIRED) find_package(rosidl_typesupport_introspection_c REQUIRED) ament_export_dependencies(rosidl_runtime_cpp rosidl_typesupport_introspection_c) ament_python_install_package(${PROJECT_NAME}) add_library(${PROJECT_NAME} src/identifier.cpp) if(WIN32) target_compile_definitions(${PROJECT_NAME} PRIVATE "ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_BUILDING_DLL") endif() target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") target_link_libraries(${PROJECT_NAME} PUBLIC rosidl_runtime_cpp::rosidl_runtime_cpp rosidl_typesupport_introspection_c::rosidl_typesupport_introspection_c ) # Export old-style CMake variables ament_export_include_directories("include/${PROJECT_NAME}") ament_export_libraries(${PROJECT_NAME}) # Export modern CMake targets ament_export_targets(${PROJECT_NAME}) ament_index_register_resource("rosidl_typesupport_cpp") ament_index_register_resource("rosidl_runtime_packages") if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() endif() if(BUILD_SHARED_LIBS) set(${PROJECT_NAME}_LIBRARY_TYPE "SHARED") else() set(${PROJECT_NAME}_LIBRARY_TYPE "STATIC") endif() ament_package( CONFIG_EXTRAS "rosidl_typesupport_introspection_cpp-extras.cmake.in" ) install( PROGRAMS bin/rosidl_typesupport_introspection_cpp DESTINATION lib/rosidl_typesupport_introspection_cpp ) install( DIRECTORY cmake resource DESTINATION share/${PROJECT_NAME} ) install( DIRECTORY include/ DESTINATION include/${PROJECT_NAME} ) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) ``` -------------------------------- ### ROSIDL Generator Type Description CMakeLists Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_generator_type_description/CMakeLists.txt This CMakeLists.txt file configures the build process for the rosidl_generator_type_description package. It includes finding necessary packages like ament_cmake_python and ament_cmake_ros_core, registering resources, and handling testing dependencies if BUILD_TESTING is enabled. ```cmake cmake_minimum_required(VERSION 3.20) project(rosidl_generator_type_description) find_package(ament_cmake_python REQUIRED) find_package(ament_cmake_ros_core REQUIRED) ament_index_register_resource("rosidl_generator_packages") ament_python_install_package(${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(ament_cmake_pytest REQUIRED) ament_lint_auto_find_test_dependencies() ament_add_pytest_test(pytest_type_hash_generator test) endif() ament_package( CONFIG_EXTRAS "${PROJECT_NAME}-extras.cmake.in" ) install( PROGRAMS bin/${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME} ) install( DIRECTORY cmake resource DESTINATION share/${PROJECT_NAME} ) ``` -------------------------------- ### Define GTest and performance tests Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_c/CMakeLists.txt Sets up C++17 standard and registers various GTest and performance test targets. ```cmake # For gtest enable_language(CXX) # Default to C++17 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() find_package(ament_cmake_gtest REQUIRED) ament_add_gtest(test_message_type_support test/test_message_type_support.cpp) if(TARGET test_message_type_support) target_link_libraries(test_message_type_support ${PROJECT_NAME}) endif() ament_add_gtest(test_primitives_sequence_functions test/test_primitives_sequence_functions.cpp) if(TARGET test_primitives_sequence_functions) target_link_libraries(test_primitives_sequence_functions ${PROJECT_NAME}) endif() ament_add_gtest(test_sequence_bound test/test_sequence_bound.cpp) if(TARGET test_sequence_bound) target_link_libraries(test_sequence_bound ${PROJECT_NAME}) endif() ament_add_gtest(test_service_type_support test/test_service_type_support.cpp) if(TARGET test_service_type_support) target_link_libraries(test_service_type_support ${PROJECT_NAME}) endif() ament_add_gtest(test_string_functions test/test_string_functions.cpp) if(TARGET test_string_functions) target_link_libraries(test_string_functions ${PROJECT_NAME}) target_compile_definitions(test_string_functions PUBLIC RCUTILS_ENABLE_FAULT_INJECTION) endif() ament_add_gtest(test_type_hash test/test_type_hash.cpp) if(TARGET test_type_hash) target_link_libraries(test_type_hash ${PROJECT_NAME}) endif() ament_add_gtest(test_u16string_functions test/test_u16string_functions.cpp) if(TARGET test_u16string_functions) target_link_libraries(test_u16string_functions ${PROJECT_NAME}) target_compile_definitions(test_u16string_functions PUBLIC RCUTILS_ENABLE_FAULT_INJECTION) endif() ament_add_gtest(test_type_description_utils test/test_type_description_utils.cpp) if(TARGET test_type_description_utils) target_link_libraries(test_type_description_utils ${PROJECT_NAME}) endif() add_performance_test(benchmark_string_conversion test/benchmark/benchmark_string_conversion.cpp) if(TARGET benchmark_string_conversion) target_link_libraries(benchmark_string_conversion ${PROJECT_NAME}) endif() endif() ``` -------------------------------- ### Export targets and register resources Source: https://github.com/ros2/rosidl/blob/rolling/rosidl_runtime_c/CMakeLists.txt Exports CMake targets and registers the package in the ament index. ```cmake ament_export_targets(${PROJECT_NAME}) ament_index_register_resource("rosidl_runtime_packages") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.