diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-05-27 15:58:57 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-05-27 23:19:37 (GMT) |
commit | fa55751f83dc5d5bd5f80d12c3076ec703262edb (patch) | |
tree | 7420d760cbeaad79622325d3b285a1b53d2c743f /Source/cmQtAutomoc.cxx | |
parent | f77631672168b1e3b5fad93c2bb83db65cb67e7b (diff) | |
download | CMake-fa55751f83dc5d5bd5f80d12c3076ec703262edb.zip CMake-fa55751f83dc5d5bd5f80d12c3076ec703262edb.tar.gz CMake-fa55751f83dc5d5bd5f80d12c3076ec703262edb.tar.bz2 |
QtAutomoc: Get the Qt version through the target link interface
In Qt 5.1, Qt5::Core has a INTERFACE_QT_MAJOR_VERSION property
of '5', and since CMake 2.8.11, Qt4::QtCore has an
INTERFACE_QT_MAJOR_VERSION of '4'. This was introduced in
commit 4aa10cd6 (FindQt4: Set the INTERFACE_QT_MAJOR_VERSION for
Qt4::QtCore, 2013-03-16), to produce an error if Qt 4 and Qt 5
are erroneously used by the same target. This can also be used
however to determine the Qt major version, and therefore the
particular moc executable to use during automoc steps. This means
that targets in a single buildsystem can use a selection of Qt 4
and Qt 5, and still take advantage of the CMAKE_AUTOMOC feature
without conflicting.
Diffstat (limited to 'Source/cmQtAutomoc.cxx')
-rw-r--r-- | Source/cmQtAutomoc.cxx | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx index 9d14fc2..350b462 100644 --- a/Source/cmQtAutomoc.cxx +++ b/Source/cmQtAutomoc.cxx @@ -309,7 +309,27 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str()); makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE"); - if (makefile->GetDefinition("Qt5Core_VERSION_MAJOR")) + const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); + if (!qtVersion) + { + qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); + } + if (const char *targetQtVersion = + target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) + { + qtVersion = targetQtVersion; + } + if (qtVersion) + { + makefile->AddDefinition("_target_qt_version", qtVersion); + } + + { + const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE"); + makefile->AddDefinition("_qt_moc_executable", qtMoc); + } + + if (strcmp(qtVersion, "5") == 0) { cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc"); if (!qt5Moc) @@ -322,8 +342,11 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) } else { - const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE"); - makefile->AddDefinition("_qt_moc_executable", qtMoc); + if (strcmp(qtVersion, "4") != 0) + { + cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and " + "Qt 5 ", automocTargetName.c_str()); + } } const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); |