[cmake-developers] how does target_compile_features() test the c++11 conformance?

Chuck Atkins chuck.atkins at kitware.com
Thu Jun 29 16:39:17 EDT 2017


Hi Claus,

how does target_compile_features() test the c++11 conformance?
>

It doesn't.  The language features supported by different compilers and
thier various versions is basically a manually constructed whitelist since
testing for them at configure time is far too costly.  You can see the
details for msvc here in the internal compiler detection logic in the CMake
distribution: Modules/Compiler/MSVC-CXX-FeatureTests.cmake


 target_compile_features(${targetname} PRIVATE cxx_std_11) # OK
>
> But wenn I use this most features are missing:
>
> target_compile_features(${targetname} PRIVATE
>    cxx_contextual_conversions  # OK
> ...

   #FIXME: missing features at MS VS12 2013:
> ...
>    cxx_aggregate_default_initializers

...
>  )
>

The cxx_std_11 compile feature is a meta-feature.  Basically it tells CMake
to Use the compiler in C++11 mode if possible, and then the cmpiler will do
what it can.  This is effectively adding the -std=c++11 flag to gcc or
-std=c++1y for cxx_std_14.  The compiler may not support all the features
but CMake knows that it can at least support *some* so it will try to use
what it can.  MSVC is a bit of an oddball with compilers since you cant
actually control the language level (maybe with 2017 you can), i.e. you
can't explicitly instruct msvc to build in C++98 mode only.

The individual language features wre initially put in place due to the
half-broken C++11 implementations that thend to be available in many
compilers (as you're finding out).  However, over time as it's used more
that level of granularity is less and less useful.  Hence the addition of
the meta-features for language levels.  Several compilers that have
reecently added language standard support in CMake (IBM XL, Cray, PGI) are
now just using the meta-feature as the maintenace burdon for maintaining
the feature tables is too great with respect to the reward.

Hope that helps clarify the state of things.

----------
Chuck Atkins
Staff R&D Engineer, Scientific Computing
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20170629/c70f5100/attachment.html>


More information about the cmake-developers mailing list