We recently ran into an issue when the cmake_minimum_required was bumped above 3.21, and policy CMP0128 came into force.
There were common project settings with:
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
The compiler in use was g++ version 7.4.
Pre-CMP0128 this resulted in the “-std=c++1z” compile flag being added (to the compiler invocation).
Post-CMP0128 this is not emitted.
The documentation says that “Extensions are correctly enabled/disabled […]”, but also states: " * Standard mode-affecting flags aren’t added unless necessary to achieve the specified mode."
So is this now considered an extension (the former statement, rather than the latter)?
This was useful to “let cmake figure out the most supported standard for the compiler”.
Is disabling the policy the way to achieve this, now? (loathe to do…)
GCC 7.4 has no support for C++20 whatsoever, with CMP0128
set to NEW
CMake correctly gives up when there’s no flags it knows about to achieve the requested behavior. It assumes the user producing the build knows something about the compiler it does not.
Setting CMAKE_CXX_STANDARD
to 17
will get you the -std=c++1z
flag. Alternatively, upgrading to a GCC version >= 8.0
will get you the -std=c++2a
the current configuration is asking for.
The codebase is actually cross compiled for several platforms, so different versions of gcc come into play (via toolchain files for each platform). Some features of C++20 are conditionally used in shared parts.
However, a common file for compiler settings is used so it was just convenient (and self maintaining) when cmake popped in the closest it could. Although it sounds like it may not have been doing that (hence the policy).
Thanks for the response and clarifying.
Should anyone stumble across this with a similar requirement, it is achievable.
See this comment and associated links.