Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle the requirement of C++17 at the CMake exported target level #251

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

traversaro
Copy link
Contributor

@traversaro traversaro commented Apr 22, 2020

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 downstream projects that use CMake, 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 .

@traversaro
Copy link
Contributor Author

Apparently the new DCO check that does not like PR created vai the GitHub web interface.

… level

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 <[email protected]>
@chapulina
Copy link
Contributor

Apparently the new DCO check that does not like PR created vai the GitHub web interface.

I believe you can add "Signed-off-by:" as the commit comment. It's not the most convenient way, but hopefully GitHub will automate that on the interface eventually.

@traversaro
Copy link
Contributor Author

traversaro commented Apr 22, 2020

Apparently the new DCO check that does not like PR created vai the GitHub web interface.

I believe you can add "Signed-off-by:" as the commit comment. It's not the most convenient way, but hopefully GitHub will automate that on the interface eventually.

Related (unofficial) issue: todogroup/gh-issues#50 .

scpeters added a commit to gazebo-tooling/gazebodistro that referenced this pull request Apr 28, 2020
scpeters added a commit to gazebo-tooling/gazebodistro that referenced this pull request Apr 28, 2020
@scpeters
Copy link
Member

testing with ign-physics Build Status https://build.osrfoundation.org/view/ign-citadel/job/ign_physics-ign-2-win/24/

@scpeters
Copy link
Member

thanks @traversaro!

@scpeters scpeters merged commit f7dcdd7 into gazebosim:sdf9 Apr 28, 2020
scpeters pushed a commit that referenced this pull request May 12, 2020
… 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 <[email protected]>
scpeters pushed a commit that referenced this pull request May 12, 2020
… 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 <[email protected]>
scpeters added a commit to scpeters/sdformat that referenced this pull request May 15, 2020
scpeters added a commit to scpeters/sdformat that referenced this pull request May 15, 2020
scpeters added a commit that referenced this pull request May 15, 2020
scpeters added a commit to scpeters/sdformat that referenced this pull request May 15, 2020
scpeters added a commit that referenced this pull request May 15, 2020
scpeters pushed a commit that referenced this pull request Jun 2, 2020
… 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 <[email protected]>
scpeters added a commit that referenced this pull request Jun 2, 2020
traversaro added a commit to robotology/gazebo-yarp-plugins that referenced this pull request Jul 16, 2020
GAZEBO_CXX_FLAGS was added to CMAKE_CXX_FLAGS in #190
to support compilation against Gazebo 6 that required C++11, and unfortunately since then Gazebo did not switch to a modern
way of specifying C++ standard requirement in consuming libraries. Now that YARP requires C++14, passing GAZEBO_CXX_FLAGS 
(that contains -std=c++11) basically bypass the CMake logic to compute the correct C++ standard with which to compile the plugins,
and forces to compile them with C++11. 

As the only reason for which GAZEBO_CXX_FLAGS was added to CMAKE_CXX_FLAGS was to enable C++11 support, and as that is already 
passed as a requirement by YARP, I think we can just remove it.

Related SDFormat PR: gazebosim/sdformat#251 .
traversaro added a commit to traversaro/sdformat that referenced this pull request Sep 5, 2020
… level (gazebosim#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 <[email protected]>
traversaro pushed a commit to traversaro/sdformat that referenced this pull request Sep 5, 2020
FelipeGdM added a commit to FelipeGdM/gzweb that referenced this pull request Jan 22, 2021
Sdf format version 9.0 requires c++17 to be compiled

gazebosim/sdformat#251
FelipeGdM added a commit to FelipeGdM/gzweb that referenced this pull request Feb 1, 2021
Sdf format version 9.0 requires c++17 to be compiled

gazebosim/sdformat#251
FelipeGdM added a commit to FelipeGdM/gzweb that referenced this pull request Feb 1, 2021
Sdf format version 9.0 requires c++17 to be compiled

gazebosim/sdformat#251
FelipeGdM added a commit to FelipeGdM/gzbridge that referenced this pull request Feb 11, 2021
Sdf format version 9.0 requires c++17 to be compiled

gazebosim/sdformat#251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants