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

Avoid setting CMAKE_CXX_STANDARD explicitly in libraries #44

Open
traversaro opened this issue Jan 31, 2019 · 1 comment
Open

Avoid setting CMAKE_CXX_STANDARD explicitly in libraries #44

traversaro opened this issue Jan 31, 2019 · 1 comment

Comments

@traversaro
Copy link
Member

traversaro commented Jan 31, 2019

In abseil/abseil-cpp#259 (comment) , a good point is made against setting CMAKE_CXX_STANDARD explicitly in libraries, in favor of just using target_compile_features(mylib PUBLIC cxx_std_11) to specify the minimum required standard language to compile.
We never set the CMAKE_CXX_STANDARD in this tutorial, but as the use of setting CMAKE_CXX_STANDARD is widespread in robotology libraries, it would be good to have one point where we discuss this. Requiring CMake 3.10 would be a good occasion to switch to use target_compile_features(mylib PUBLIC cxx_std_11).

@drdanz
Copy link
Member

drdanz commented Feb 2, 2019

While I'm in favour of suggesting this, I think there might be a reason for having it in some cases, for example, if your code uses some c++ deprecated features, removed in c++17 (e.g. throw(typeid) or register), your code will not compile if you set target_compile_features(mylib PUBLIC cxx_std_11) but CMake decides to use C++17.

I'm not 100% sure if this is true, and the documentation does not specify it, but if I remember correctly, I added it in YARP when GCC switched to have c++14 enabled by default, and YARP was being compiled without the -std=c++11 flag (therefore equivalent to -std=c++14), setting the variable restored the build flag.

Requiring CMake 3.10 would be a good occasion to switch to use target_compile_features(mylib PUBLIC cxx_std_11).

Looking forward to that day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants