summaryrefslogtreecommitdiff
path: root/Source/cmQtAutoGeneratorInitializer.cxx
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2017-04-06 04:14:35 +0200
committerBrad King <brad.king@kitware.com>2017-04-20 08:59:07 -0400
commit0903531964cff8888dd1cbf2a9c82ac6bb9a522f (patch)
tree2cf7d844d3ee291ecb5ba77547bddb0a490aa150 /Source/cmQtAutoGeneratorInitializer.cxx
parent135611176c5d4958b9b5a36c63fada8a9e4fb1ef (diff)
downloadcmake-0903531964cff8888dd1cbf2a9c82ac6bb9a522f.tar.gz
Autogen: Pass explicit predefines header to moc if possible
Qt is relying on whoever calls moc to include a file with the predefined values that will be used by the compiler, otherwise moc takes wrong paths and weird things happen. Instead, generate an include file and feed it to all mocs to make sure it's generating correct code. Co-Author: Sebastian Holtermann <sebholt@xwmw.org> Fixes: #16640
Diffstat (limited to 'Source/cmQtAutoGeneratorInitializer.cxx')
-rw-r--r--Source/cmQtAutoGeneratorInitializer.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index d69794c743..c7e02e66bd 100644
--- a/Source/cmQtAutoGeneratorInitializer.cxx
+++ b/Source/cmQtAutoGeneratorInitializer.cxx
@@ -96,6 +96,41 @@ static std::string GetQtMajorVersion(cmGeneratorTarget const* target)
return qtMajorVersion;
}
+static std::string GetQtMinorVersion(cmGeneratorTarget const* target,
+ const std::string& qtMajorVersion)
+{
+ cmMakefile* makefile = target->Target->GetMakefile();
+ std::string qtMinorVersion;
+ if (qtMajorVersion == "5") {
+ qtMinorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR");
+ }
+ if (qtMinorVersion.empty()) {
+ qtMinorVersion = makefile->GetSafeDefinition("QT_VERSION_MINOR");
+ }
+
+ const char* targetQtVersion =
+ target->GetLinkInterfaceDependentStringProperty("QT_MINOR_VERSION", "");
+ if (targetQtVersion != CM_NULLPTR) {
+ qtMinorVersion = targetQtVersion;
+ }
+ return qtMinorVersion;
+}
+
+static bool QtVersionGreaterOrEqual(const std::string& major,
+ const std::string& minor,
+ unsigned long requestMajor,
+ unsigned long requestMinor)
+{
+ unsigned long majorUL(0);
+ unsigned long minorUL(0);
+ if (cmSystemTools::StringToULong(major.c_str(), &majorUL) &&
+ cmSystemTools::StringToULong(minor.c_str(), &minorUL)) {
+ return (majorUL > requestMajor) ||
+ (majorUL == requestMajor && minorUL >= requestMinor);
+ }
+ return false;
+}
+
static void GetCompileDefinitionsAndDirectories(
cmGeneratorTarget const* target, const std::string& config,
std::string& incs, std::string& defs)
@@ -258,6 +293,12 @@ static void MocSetupAutoTarget(
AddDefinitionEscaped(makefile, "_moc_depend_filters",
GetSafeProperty(target, "AUTOMOC_DEPEND_FILTERS"));
+ if (QtVersionGreaterOrEqual(
+ qtMajorVersion, GetQtMinorVersion(target, qtMajorVersion), 5, 8)) {
+ AddDefinitionEscaped(
+ makefile, "_moc_predefs_cmd",
+ makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND"));
+ }
// Moc includes and compile definitions
{
std::string _moc_incs;