[cmake-developers] Wrong cxx-extension flags

Brad King brad.king at kitware.com
Thu Jul 14 15:27:00 EDT 2016


On 07/14/2016 02:48 PM, Kornel Benko wrote:
> I am asking about '-std=gnu++11'.
On 07/14/2016 02:45 PM, Kornel Benko wrote:
> The new cmake-files from QT5.7 are somehow responsible that this happens.

The file `lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake` in Qt 5.7 contains:

  set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)

This tells CMake that dependents of this library need to be compiled as
at least C++11.  This causes `-std=gnu++11` to be added automatically.

What you can do is not add your own flag and instead do

 set(CMAKE_CXX_STANDARD 14)

or set the CXX_STANDARD property of specific targets.  That tells CMake
to build as C++14 so it will add -std=gnu++14.  If you don't want the
extensions then also set

 set(CMAKE_CXX_EXTENSIONS OFF)

Relevant docs:

 https://cmake.org/cmake/help/v3.6/manual/cmake-compile-features.7.html
 https://cmake.org/cmake/help/v3.6/variable/CMAKE_CXX_STANDARD.html
 https://cmake.org/cmake/help/v3.6/variable/CMAKE_CXX_EXTENSIONS.html

-Brad


More information about the cmake-developers mailing list