From 71c7cc2a66e748e64f5a241e44a21b31b0df95ae Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 7 Mar 2023 14:43:58 -0500 Subject: [PATCH] Update all rclcpp packages to C++17. (#2121) The main reason to do this is so that we can compile rclcpp with the clang static analyzer. As of clang++-14 (what is in Ubuntu 22.04), the default still seems to be C++14, so we need to specify C++17 so that new things in the rclcpp headers work properly. Further, due to reasons I don't fully understand, I needed to set CMAKE_CXX_STANDARD_REQUIRED in order for clang to really use that version. So set this as well. Signed-off-by: Chris Lalancette --- rclcpp/CMakeLists.txt | 1 + rclcpp_action/CMakeLists.txt | 5 +++-- rclcpp_components/CMakeLists.txt | 5 +++-- rclcpp_lifecycle/CMakeLists.txt | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rclcpp/CMakeLists.txt b/rclcpp/CMakeLists.txt index 0379d5f87a..db7ee3e59e 100644 --- a/rclcpp/CMakeLists.txt +++ b/rclcpp/CMakeLists.txt @@ -25,6 +25,7 @@ find_package(tracetools 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") # About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of diff --git a/rclcpp_action/CMakeLists.txt b/rclcpp_action/CMakeLists.txt index 353e179244..785ed0e5e1 100644 --- a/rclcpp_action/CMakeLists.txt +++ b/rclcpp_action/CMakeLists.txt @@ -9,9 +9,10 @@ find_package(rcl_action REQUIRED) find_package(rcpputils REQUIRED) find_package(rosidl_runtime_c REQUIRED) -# Default to C++14 +# Default to C++17 if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) + 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( diff --git a/rclcpp_components/CMakeLists.txt b/rclcpp_components/CMakeLists.txt index 0b9cda7803..121ef434c2 100644 --- a/rclcpp_components/CMakeLists.txt +++ b/rclcpp_components/CMakeLists.txt @@ -2,9 +2,10 @@ cmake_minimum_required(VERSION 3.5) project(rclcpp_components) -# Default to C++14 +# Default to C++17 if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) + 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( diff --git a/rclcpp_lifecycle/CMakeLists.txt b/rclcpp_lifecycle/CMakeLists.txt index cffed32a32..2863a13529 100644 --- a/rclcpp_lifecycle/CMakeLists.txt +++ b/rclcpp_lifecycle/CMakeLists.txt @@ -2,9 +2,10 @@ cmake_minimum_required(VERSION 3.5) project(rclcpp_lifecycle) -# Default to C++14 +# Default to C++17 if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) + 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 -Wnon-virtual-dtor -Woverloaded-virtual)