Skip to content

CMake interaction with C/C++ std flags #1097

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

Closed
henryiii opened this issue Sep 18, 2017 · 0 comments · Fixed by #2338
Closed

CMake interaction with C/C++ std flags #1097

henryiii opened this issue Sep 18, 2017 · 0 comments · Fixed by #2338

Comments

@henryiii
Copy link
Collaborator

This started in the discussion for #1089. The core issue was that C++ flags mix into C compilation, because PyBind has it's own implementation of C++ flags, and it doesn't include a way to separate C code.

CMake 2.8 was released in 2009, long before C++11 (much less the other standards) were released. Modern CMake does have a way to select C++ versions, and PyBind can be in contention with them.

Method 1: CMake 3.1+: CMAKE_CXX_STANDARD (and CMAKE_CXX_STANDARD_REQUIRED, CMAKE_CXX_EXTENSIONS). The current implementation does include checks for these, and turns off custom flags.
Method 2: CMake 3.1+: Manually listing features with target_compile_features. This was supposed to be the "best" way to do things, but listing every feature in C++11 is tedious.
Method 3: CMake 3.8: Meta-compile features were added for C++ standards, finally allowing target_compile_features(my_target PUBLIC cxx_std_11) or similar.

The first method is checked and appropriately handled by pybind11. The final method is not well supported by pybind11. I believe that by leaving PYBIND_CPP_STANDARD on CMake 3.8+, PyBind should default to this method. This should allow overriding the standard (automatically handled by CMake if you request it on a pybind target), as well as keep the C++/C separate without non-portable generator expressions.

And we can avoid the awful CPP/CXX mixed name by phasing out PYBIND_CPP_STANDARD on new targets 😉.

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 a pull request may close this issue.

1 participant