[cmake-developers] compute-default-dialect topic
Stephen Kelly
steveire at gmail.com
Wed Sep 16 15:00:24 EDT 2015
Brad King wrote:
> On 09/16/2015 02:22 PM, Stephen Kelly wrote:
>>> The default dialect computed with the compiler id may not be the
>>> same as the effective default dialect when CMAKE_CXX_FLAGS is
>>> considered.
>>
>> I pushed another fixup which may disable the test in that case, and may
>> also disable it with GNU 6 and other compilers with default standard >=
>> 11.
>
> That may fix the trouble for CMake's test suite, but might this
> also be a problem for projects in general? Actually this could
> be an existing problem whether CMake computes or memorizes the
> raw compiler default. If we're making decisions about what flags
> to add based on CMAKE_<LANG>_STANDARD_DEFAULT, but the user has
> already specified their own -std= flags in CMAKE_<LANG>_FLAGS,
> might we end up with the incorrect standard level, or multiple
> flags?
Multiple flags, apparently.
I made a project with
target_compile_features(hello PRIVATE cxx_decltype_auto) # -std=c++14
and built it with GNU 5.1(default dialect 98).
I ran cmake with -DCMAKE_CXX_FLAGS=-std=c++11.
The result is that a default of 11 is computed (with my branch) for the
CXX_STANDARD_DEFAULT because of the CMAKE_CXX_FLAGS=-std=c++11, but 14 is
the requirement, so
-std=c++11 -std=gnu++14
appears on the command line. The latter 'wins' in this case.
If I instead use
target_compile_features(hello PRIVATE cxx_static_assert) # -std=c++11
Then
-std=c++11 -std=gnu++11
appears instead, which is consistent with the design of CompileFeatures.
Arguably the -std=gnu++11 should not be added in that case, but changing
that existing behavior would be a different topic.
Thanks,
Steve.
More information about the cmake-developers
mailing list