Skip to content

Generalize cmake compiler support #1428

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

Conversation

chuckatkins
Copy link
Contributor

Related to #1381

@jagerman
Copy link
Member

This is going to change the default flag to -std=gnu++14; aside from that it looks good.

At the moment I mildly prefer the defaults going to the stricter language version (i.e. skipping the ..._EXTENSION_COMPILE_OPTIONs), but I'm willing to listen to a compelling argument as to why they should changed.

@chuckatkins
Copy link
Contributor Author

I get it, and I actually agree that keeping the default to use no extensions is preferred. So, really the motivation for doing it this way was to mimic CMake's behavior for language standards abstraction. In CMake >= 3.1 (which is when the language standards abstraction was first introduced), the default behavior is to have CXX extensions enabled. This was primarily to make CMake's default behavior match the default behavior of compilers that build with newer standards by default now. Most of them enable extensions by default as well. You can explicitly disable them with set(CMAKE_CXX_EXTENSIONS OFF). I'll take a shot at re-working this to leverage the language abstractions but also disable extensions.

@chuckatkins
Copy link
Contributor Author

Not sure why this would cause the Travis failure but I'll look into it

@chuckatkins chuckatkins force-pushed the generalize-cmake-compiler-support branch from bb8e389 to 8a10107 Compare June 18, 2018 14:36
@chuckatkins chuckatkins force-pushed the generalize-cmake-compiler-support branch from 8a10107 to 58e551c Compare June 18, 2018 14:49
@ax3l
Copy link
Collaborator

ax3l commented Jun 21, 2018

@chuckatkins CI fixed :)

@chuckatkins chuckatkins reopened this Jun 21, 2018
@chuckatkins
Copy link
Contributor Author

I borked these commit so let me rebase and push the correct ones...

@chuckatkins chuckatkins force-pushed the generalize-cmake-compiler-support branch from 1954404 to 9241ae5 Compare June 21, 2018 15:16
if(NOT PYBIND11_CPP_STANDARD AND NOT CMAKE_CXX_STANDARD)
if(NOT MSVC)
if(MSVC)
set(PYBIND11_CPP_STANDARD /std:c++14)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is potentially problematic. The version requirement for pybind11 is MSVC 2015 Update 3. I don't think it will be able to deal with C++14 mode.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSVC 2015 Update 3 is the one that introduced /std:c++14 and /std:c++latest.

https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm good point -- and I forgot that we're actually testing MSVC 2015 on AppVeyor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the MSVC behavior isn't changed in this PR from what it was before. I only inverted the if/else order to have the larger, most often followed, code block to be the if condition rather than the else.

@wjakob
Copy link
Member

wjakob commented Jun 24, 2018

Looks good to me – @jagerman ?

@jagerman
Copy link
Member

Looks good to me.

@chuckatkins
Copy link
Contributor Author

ping?

@jagerman
Copy link
Member

One more change needed before merging: the documentation for compiling should be updated to reference the newer cmake style. It's a nicer approach and is likely to fit better with other cmake projects in the future.

I have one other question: what happens if someone is using the existing PYBIND11_CPP_STANDARD and updates pybind -- does the project continue to build with the current flags? (In other words, is the CMAKE_CXX_... stuff purely opt-in and just not set if not being used?)

@wjakob
Copy link
Member

wjakob commented Aug 28, 2018

@chuckatkins : I think this is basically ready to be merged, except for the documentation by @jagerman above. Could you please add this? Thanks!

@ax3l
Copy link
Collaborator

ax3l commented Apr 25, 2020

Will we ever merge a PR from a CMake co-author / Kitware employee that sits two doors from the CMake maintainers and just add the docs about changing style wishes ourselves? ;-)

Yes, all CMAKE_... flags in CMake are intended to be set only to overwrite defaults. Typical use cases: Toolchains, super builds, or manual CLI calls that enforce a specific compiler, specific flags or a specific CXX standard. The extra block in there just extends compiler support, e.g. when pybind11 is called as subproject for projects running with more sciency/experimental/HPC compilers than the big three in our CI.

@wjakob
Copy link
Member

wjakob commented Apr 25, 2020

Happy to merge it, but I don't have the clock cycles to look into documenting this atm. (Remote working with a two-year old who is bored out of her mind has been quite the challenge.) @ax3l -- if you want this merged, can you open a new PR based on this one?

@ax3l
Copy link
Collaborator

ax3l commented Apr 26, 2020

Sure thing, please see #2184.

@wjakob
Copy link
Member

wjakob commented Apr 26, 2020

Merged via #2184

@wjakob wjakob closed this Apr 26, 2020
@wjakob
Copy link
Member

wjakob commented Apr 26, 2020

Thanks @chuckatkins and @ax3l

@ax3l ax3l mentioned this pull request Jul 21, 2020
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.

5 participants