cmake forces c++11 on an app that needs c++14

David Faure faure at kde.org
Sat Jun 4 09:03:37 UTC 2016


Symptom: zanshin doesn't compile with Qt 5.7 and cmake from "release" branch,
error is "std::make_unique not found".

Reason: zanshin wants -std=c++14, but gets a compile line like this:
-std=c++0x [...] -std=c++14 [...] -std=gnu++11
so in the end only C++11 is enabled, not C++14.

In order to enable C++14, Zanshin does this:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

Linking to Qt5::Core brings the -std=c++0x but that's fine it's before the 
other flags.

cmake itself however adds -std=gnu+11.
An ugly workaround is to do
   set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++14")
I looked into the "cmake-compile-features" mechanism, but that's only about 
language features, while zanshin only needs c++14 for a newer feature in the 
standard library (the fact that <memory> provides std::make_unique).
I could hack it by picking a language feature and saying that zanshin requires 
that, but that's still a workaround.

Doesn't cmake have a better solution for this?

(For instance not adding -std=gnu+11 if the flags already contain -std=c++14?
Or providing a way to "force" c++14, without the indirection of required 
language features?)

PS: the above analysis is mostly deduced from grepping; it seems logical to 
me, but what's strange is that it only started happening when switching to Qt 
5.7... I don't understand why.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5



More information about the Kde-buildsystem mailing list