Skip to content

Commit

Permalink
Use target_compile_features for c/c++ standards (#615)
Browse files Browse the repository at this point in the history
* Use target_compile_features for c/c++ standards

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>

* Need CMake 3.8 for standard features

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz authored Mar 30, 2021
1 parent 93d5a7e commit ee82458
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
14 changes: 3 additions & 11 deletions ros2pkg/ros2pkg/resource/ament_cmake/CMakeLists.txt.em
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(@(project_name))

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# 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()
Expand All @@ -32,6 +22,7 @@ find_package(@dep REQUIRED)
@[if cpp_library_name]@

add_library(@(cpp_library_name) src/@(cpp_library_name).cpp)
target_compile_features(@(cpp_library_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_include_directories(@(cpp_library_name) PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
Expand Down Expand Up @@ -69,6 +60,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
@[ if dependencies]@
ament_target_dependencies(
@(cpp_node_name)
Expand Down
14 changes: 3 additions & 11 deletions ros2pkg/ros2pkg/resource/cmake/CMakeLists.txt.em
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(@(project_name))

set(@(project_name)_MAJOR_VERSION 0)
Expand All @@ -7,16 +7,6 @@ set(@(project_name)_PATCH_VERSION 0)
set(@(project_name)_VERSION
${@(project_name)_MAJOR_VERSION}.${@(project_name)_MINOR_VERSION}.${@(project_name)_PATCH_VERSION})

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# 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()
Expand All @@ -35,6 +25,7 @@ find_package(@dep REQUIRED)
@[if cpp_library_name]@

add_library(@(cpp_library_name) SHARED src/@(cpp_library_name).cpp)
target_compile_features(@(cpp_library_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_include_directories(@(cpp_library_name) PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
Expand Down Expand Up @@ -82,6 +73,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
@[ if dependencies]@
target_link_libraries(@(cpp_node_name)
@[ for dep in dependencies]@
Expand Down

0 comments on commit ee82458

Please sign in to comment.