Skip to content

Commit d594011

Browse files
traversaroscpeters
authored andcommitted
Properly handle the requirement of C++17 at the CMake exported target level (#251)
SDFormat 9 requires the use of C++17 in its public headers, however it does not correctly expose this requirement in its installed imported targets. In particular, at the moment the requirement of C++17 is only documented via adding the -std=c++17 flag in the `SDFormat_CXX_FLAGS` variable, but this strategy has two problems: * It does not work unless a user explicitly pass this flags to its compilation targets, and this is definitely not obvious if it is not using directly SDFormat, but he is linking sdformat transitively through Gazebo 11. * If a different C++ version is set at the CMake level, it is possible that the `-std=c++17` flag is ignored (it depends what is the order with which the flags are passed to the compiler). For CMake consumers, a better strategy is to use the target_compile_features and explicitly mark that that this library requires the `cxx_std_17` feature, as `PUBLIC` because it also required in the public headers. As the minimum required version of CMake is 3.10, we can use cxx_std_17 as it is available in CMake 3.10, see https://cmake.org/cmake/help/v3.10/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES . Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.it>
1 parent 3bbd303 commit d594011

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ if (NOT WIN32)
164164
endif()
165165

166166
sdf_add_library(${sdf_target} ${sources})
167+
target_compile_features(${sdf_target} PUBLIC cxx_std_17)
167168
target_link_libraries(${sdf_target} PUBLIC ${IGNITION-MATH_LIBRARIES})
168169

169170
target_include_directories(${sdf_target}

0 commit comments

Comments
 (0)