From 756ef6886da0b17fb7013f12c4bdc96eca819c56 Mon Sep 17 00:00:00 2001 From: Mikael Arguedas Date: Thu, 15 Jun 2017 13:48:42 -0700 Subject: [PATCH] use CMAKE_X_STANDARD and check compiler rather than platform --- rclcpp/CMakeLists.txt | 15 +++++++++++---- rclcpp_lifecycle/CMakeLists.txt | 10 ++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/rclcpp/CMakeLists.txt b/rclcpp/CMakeLists.txt index 7e5fd70..33e291f 100644 --- a/rclcpp/CMakeLists.txt +++ b/rclcpp/CMakeLists.txt @@ -12,10 +12,17 @@ find_package(rosidl_generator_cpp REQUIRED) find_package(rosidl_typesupport_c REQUIRED) find_package(rosidl_typesupport_cpp REQUIRED) -if(WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wpedantic") +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # we dont use add_compile_options with pedantic in message packages + # because the Python C extensions dont comply with it + # TODO(mikaelarguedas) change to add_compile_options + # once this is not a message package anymore + # https://github.com/ros2/system_tests/issues/191 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") endif() include_directories(include) diff --git a/rclcpp_lifecycle/CMakeLists.txt b/rclcpp_lifecycle/CMakeLists.txt index 9f22fa5..7bf52ef 100644 --- a/rclcpp_lifecycle/CMakeLists.txt +++ b/rclcpp_lifecycle/CMakeLists.txt @@ -2,10 +2,12 @@ cmake_minimum_required(VERSION 3.5) project(rclcpp_lifecycle) -if(WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wpedantic") +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +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)