[CMake] target_compile_features() uses incorrect C++ version
Deniz Bahadir
dbahadir at benocs.com
Wed Dec 5 08:17:59 EST 2018
Am 05.12.18 um 13:40 schrieb Kim Walisch:
> Hi,
>
> I have realized that my C++ primesieve project
> (https://github.com/kimwalisch/primesieve) is
> compiled using -std=gnu++11 with GCC 7.3 and CMake 3.10 (on Ubuntu 18.10
> x64) even
> though the default C++ version used by GCC 7.3 is C++14 as checked below:
>
> $ g++ -dM -E -x c++ /dev/null | grep -F __cplusplus
> #define __cplusplus 201402L
>
> Note that I have not set CXX_STANDARD manually in my CMakeLists.txt so I
> was expecting
> that my project would be compiled either with -std=gnu++14 or without
> any C++ version flag.
> I spent some time investigating where the -std=gnu++11 flag comes from
> and I found that it is
> related to the use of target_compile_features():
>
> target_compile_features(primesieve PRIVATE cxx_auto_type)
>
> This code tells the compiler that my program uses features from C++11
> and that the compiler
> should enable C++11 if the default C++ version of the compiler is e.g.
> C++98. I would
> however expect that if the default C++ version of the compiler is >
> C++11 CMake would not
> add -std=gnu++11 to the compiler flags.
>
> For me this is a CMake bug.
>
> Thanks,
> Kim Walisch
>
Hi Kim,
this does indeed sound like some unwanted behavior.
I recommend you open an issue in CMake's issue-tracker
(https://gitlab.kitware.com/cmake/cmake/issues) and copy your
email-content there.
Best regards,
Deniz Bahadir
More information about the CMake
mailing list