From cf4a3bcf7342fa9605deedc28ef6491ed4e4ff76 Mon Sep 17 00:00:00 2001 From: mini-1235 Date: Sun, 19 Apr 2026 12:13:15 +0000 Subject: [PATCH] Update template to use c17 and c++20 Signed-off-by: mini-1235 --- ros2cli_test_interfaces/CMakeLists.txt | 5 ----- ros2lifecycle_test_fixtures/CMakeLists.txt | 15 ++++++--------- ros2lifecycle_test_fixtures/package.xml | 1 + .../resource/ament_cmake/CMakeLists.txt.em | 4 ++-- ros2pkg/ros2pkg/resource/cmake/CMakeLists.txt.em | 4 ++-- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/ros2cli_test_interfaces/CMakeLists.txt b/ros2cli_test_interfaces/CMakeLists.txt index 9eff3b425..b3c905927 100644 --- a/ros2cli_test_interfaces/CMakeLists.txt +++ b/ros2cli_test_interfaces/CMakeLists.txt @@ -1,11 +1,6 @@ cmake_minimum_required(VERSION 3.20) project(ros2cli_test_interfaces) -# 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() diff --git a/ros2lifecycle_test_fixtures/CMakeLists.txt b/ros2lifecycle_test_fixtures/CMakeLists.txt index b6caac0a5..44df1a18f 100644 --- a/ros2lifecycle_test_fixtures/CMakeLists.txt +++ b/ros2lifecycle_test_fixtures/CMakeLists.txt @@ -2,25 +2,22 @@ cmake_minimum_required(VERSION 3.20) project(ros2lifecycle_test_fixtures) -# Default to C++17 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() +find_package(ament_cmake REQUIRED) +find_package(ament_cmake_ros_core REQUIRED) +find_package(rclcpp_lifecycle REQUIRED) +find_package(rclcpp REQUIRED) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() -find_package(ament_cmake REQUIRED) -find_package(rclcpp_lifecycle REQUIRED) -find_package(rclcpp REQUIRED) add_executable(simple_lifecycle_node src/simple_lifecycle_node.cpp) target_link_libraries(simple_lifecycle_node PRIVATE - rclcpp_lifecycle::rclcpp_lifecycle) + rclcpp_lifecycle::rclcpp_lifecycle + ament_cmake_ros_core::ament_ros_defaults) install(TARGETS simple_lifecycle_node diff --git a/ros2lifecycle_test_fixtures/package.xml b/ros2lifecycle_test_fixtures/package.xml index d15180284..af7c9bc76 100644 --- a/ros2lifecycle_test_fixtures/package.xml +++ b/ros2lifecycle_test_fixtures/package.xml @@ -16,6 +16,7 @@ Michel Hidalgo ament_cmake + ament_cmake_ros_core rclcpp rclcpp_lifecycle diff --git a/ros2pkg/ros2pkg/resource/ament_cmake/CMakeLists.txt.em b/ros2pkg/ros2pkg/resource/ament_cmake/CMakeLists.txt.em index 663c2f81a..323b946e8 100644 --- a/ros2pkg/ros2pkg/resource/ament_cmake/CMakeLists.txt.em +++ b/ros2pkg/ros2pkg/resource/ament_cmake/CMakeLists.txt.em @@ -23,7 +23,7 @@ find_package(@dep REQUIRED) add_library(@(cpp_library_name) src/@(cpp_library_name).cpp) add_library(@(project_name)::@(cpp_library_name) ALIAS @(cpp_library_name)) -target_compile_features(@(cpp_library_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +target_compile_features(@(cpp_library_name) PUBLIC c_std_17 cxx_std_20) # Require C17 and C++20 target_include_directories(@(cpp_library_name) PUBLIC $ $) @@ -61,7 +61,7 @@ target_include_directories(@(cpp_node_name) PUBLIC @[ if cpp_library_name]@ target_link_libraries(@(cpp_node_name) @(cpp_library_name)) @[ else]@ -target_compile_features(@(cpp_node_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +target_compile_features(@(cpp_node_name) PUBLIC c_std_17 cxx_std_20) # Require C17 and C++20 @[ if dependencies]@ target_link_libraries( @(cpp_node_name) diff --git a/ros2pkg/ros2pkg/resource/cmake/CMakeLists.txt.em b/ros2pkg/ros2pkg/resource/cmake/CMakeLists.txt.em index 7cea276bd..c63fdf9b4 100644 --- a/ros2pkg/ros2pkg/resource/cmake/CMakeLists.txt.em +++ b/ros2pkg/ros2pkg/resource/cmake/CMakeLists.txt.em @@ -26,7 +26,7 @@ find_package(@dep REQUIRED) add_library(@(cpp_library_name) SHARED src/@(cpp_library_name).cpp) add_library(@(project_name)::@(cpp_library_name) ALIAS @(cpp_library_name)) -target_compile_features(@(cpp_library_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +target_compile_features(@(cpp_library_name) PUBLIC c_std_17 cxx_std_20) # Require C17 and C++20 target_include_directories(@(cpp_library_name) PUBLIC $ $ @@ -72,7 +72,7 @@ target_include_directories(@(cpp_node_name) PUBLIC @[ if cpp_library_name]@ target_link_libraries(@(cpp_node_name) @(cpp_library_name)) @[ else]@ -target_compile_features(@(cpp_node_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +target_compile_features(@(cpp_node_name) PUBLIC c_std_17 cxx_std_20) # Require C17 and C++20 @[ if dependencies]@ target_link_libraries(@(cpp_node_name) @[ for dep in dependencies]@