summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2018-08-13 10:06:19 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2018-08-13 16:12:47 (GMT)
commit3aa11f31fcb9780d6e54647a97ca876a2a409251 (patch)
tree028811cfd2b61b280538392a6dc93771f127962c
parent1d87c9f318b45ba9984378580d5b4926acfd4c11 (diff)
downloadCMake-3aa11f31fcb9780d6e54647a97ca876a2a409251.zip
CMake-3aa11f31fcb9780d6e54647a97ca876a2a409251.tar.gz
CMake-3aa11f31fcb9780d6e54647a97ca876a2a409251.tar.bz2
Autogen: Use integers to store the Qt version
-rw-r--r--Source/cmGlobalGenerator.cxx8
-rw-r--r--Source/cmQtAutoGen.h26
-rw-r--r--Source/cmQtAutoGenInitializer.cxx109
-rw-r--r--Source/cmQtAutoGenInitializer.h16
4 files changed, 91 insertions, 68 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 324b56a..4060269 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -34,6 +34,7 @@
#include "cmMakefile.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
+#include "cmQtAutoGen.h"
#include "cmQtAutoGenInitializer.h"
#include "cmSourceFile.h"
#include "cmState.h"
@@ -1495,15 +1496,14 @@ bool cmGlobalGenerator::QtAutoGen()
continue;
}
- std::string qtVersionMajor =
- cmQtAutoGenInitializer::GetQtMajorVersion(target);
+ auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target);
// don't do anything if there is no Qt4 or Qt5Core (which contains moc)
- if (qtVersionMajor != "4" && qtVersionMajor != "5") {
+ if (qtVersion.Major != 4 && qtVersion.Major != 5) {
continue;
}
autogenInits.emplace_back(cm::make_unique<cmQtAutoGenInitializer>(
- target, mocEnabled, uicEnabled, rccEnabled, qtVersionMajor));
+ target, mocEnabled, uicEnabled, rccEnabled, qtVersion));
}
}
diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h
index a3e16ac..4118dc7 100644
--- a/Source/cmQtAutoGen.h
+++ b/Source/cmQtAutoGen.h
@@ -28,6 +28,32 @@ public:
RCC
};
+ /// @brief Integer version
+ struct IntegerVersion
+ {
+ unsigned int Major = 0;
+ unsigned int Minor = 0;
+
+ IntegerVersion() = default;
+ IntegerVersion(unsigned int major, unsigned int minor)
+ : Major(major)
+ , Minor(minor)
+ {
+ }
+
+ bool operator>(IntegerVersion const version)
+ {
+ return (this->Major > version.Major) ||
+ ((this->Major == version.Major) && (this->Minor > version.Minor));
+ }
+
+ bool operator>=(IntegerVersion const version)
+ {
+ return (this->Major > version.Major) ||
+ ((this->Major == version.Major) && (this->Minor >= version.Minor));
+ }
+ };
+
public:
/// @brief Returns the generator name
static std::string const& GeneratorName(GeneratorT genType);
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 674657c..db7fde6 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -173,18 +173,17 @@ static bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin,
return cycle;
}
-cmQtAutoGenInitializer::cmQtAutoGenInitializer(
- cmGeneratorTarget* target, bool mocEnabled, bool uicEnabled, bool rccEnabled,
- std::string const& qtVersionMajor)
+cmQtAutoGenInitializer::cmQtAutoGenInitializer(cmGeneratorTarget* target,
+ bool mocEnabled,
+ bool uicEnabled,
+ bool rccEnabled,
+ IntegerVersion const& qtVersion)
: Target(target)
- , QtVersionMajor(qtVersionMajor)
+ , QtVersion(qtVersion)
{
Moc.Enabled = mocEnabled;
Uic.Enabled = uicEnabled;
Rcc.Enabled = rccEnabled;
-
- this->QtVersionMinor =
- cmQtAutoGenInitializer::GetQtMinorVersion(target, this->QtVersionMajor);
}
bool cmQtAutoGenInitializer::InitCustomTargets()
@@ -381,14 +380,14 @@ bool cmQtAutoGenInitializer::InitMoc()
// Moc predefs command
if (this->Target->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
- this->QtVersionGreaterOrEqual(5, 8)) {
+ (this->QtVersion >= IntegerVersion(5, 8))) {
this->Moc.PredefsCmd =
makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND");
}
// Moc includes
{
- bool const appendImplicit = (this->QtVersionMajor == "5");
+ bool const appendImplicit = (this->QtVersion.Major == 5);
auto GetIncludeDirs =
[this, localGen, appendImplicit](std::string const& cfg) -> std::string {
// Get the include dirs for this target, without stripping the implicit
@@ -725,7 +724,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
// Process qrc files
if (!this->Rcc.Qrcs.empty()) {
- const bool QtV5 = (this->QtVersionMajor == "5");
+ const bool QtV5 = (this->QtVersion.Major == 5);
// Target rcc options
std::vector<std::string> optionsTarget;
cmSystemTools::ExpandListArgument(
@@ -1097,6 +1096,9 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
ofs << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value)
<< ")\n";
};
+ auto CWriteUInt = [&ofs](const char* key, unsigned int value) {
+ ofs << "set(" << key << " " << value << ")\n";
+ };
auto CWriteList = [&CWrite](const char* key,
std::vector<std::string> const& list) {
CWrite(key, cmJoin(list, ";"));
@@ -1152,7 +1154,7 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
CWriteMap("AM_SETTINGS_FILE", this->AutogenTarget.ConfigSettingsFile);
ofs << "# Qt\n";
- CWrite("AM_QT_VERSION_MAJOR", this->QtVersionMajor);
+ CWriteUInt("AM_QT_VERSION_MAJOR", this->QtVersion.Major);
CWrite("AM_QT_MOC_EXECUTABLE", this->Moc.Executable);
CWrite("AM_QT_UIC_EXECUTABLE", this->Uic.Executable);
@@ -1265,53 +1267,56 @@ void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename,
this->Target->AddSource(filename);
}
-std::string cmQtAutoGenInitializer::GetQtMajorVersion(
+cmQtAutoGenInitializer::IntegerVersion cmQtAutoGenInitializer::GetQtVersion(
cmGeneratorTarget const* target)
{
+ cmQtAutoGenInitializer::IntegerVersion res;
cmMakefile* makefile = target->Target->GetMakefile();
+
+ // -- Major version
std::string qtMajor = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
if (qtMajor.empty()) {
qtMajor = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
}
- const char* targetQtVersion =
- target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", "");
- if (targetQtVersion != nullptr) {
- qtMajor = targetQtVersion;
+ {
+ const char* targetQtVersion =
+ target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", "");
+ if (targetQtVersion != nullptr) {
+ qtMajor = targetQtVersion;
+ }
}
- return qtMajor;
-}
-std::string cmQtAutoGenInitializer::GetQtMinorVersion(
- cmGeneratorTarget const* target, std::string const& qtVersionMajor)
-{
- cmMakefile* makefile = target->Target->GetMakefile();
+ // -- Minor version
std::string qtMinor;
- if (qtVersionMajor == "5") {
- qtMinor = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR");
- }
- if (qtMinor.empty()) {
- qtMinor = makefile->GetSafeDefinition("QT_VERSION_MINOR");
+ if (!qtMajor.empty()) {
+ if (qtMajor == "5") {
+ qtMinor = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR");
+ }
+ if (qtMinor.empty()) {
+ qtMinor = makefile->GetSafeDefinition("QT_VERSION_MINOR");
+ }
+ {
+ const char* targetQtVersion =
+ target->GetLinkInterfaceDependentStringProperty("QT_MINOR_VERSION",
+ "");
+ if (targetQtVersion != nullptr) {
+ qtMinor = targetQtVersion;
+ }
+ }
}
- const char* targetQtVersion =
- target->GetLinkInterfaceDependentStringProperty("QT_MINOR_VERSION", "");
- if (targetQtVersion != nullptr) {
- qtMinor = targetQtVersion;
+ // -- Convert to integer
+ if (!qtMajor.empty() && !qtMinor.empty()) {
+ unsigned long majorUL(0);
+ unsigned long minorUL(0);
+ if (cmSystemTools::StringToULong(qtMajor.c_str(), &majorUL) &&
+ cmSystemTools::StringToULong(qtMinor.c_str(), &minorUL)) {
+ res.Major = static_cast<unsigned int>(majorUL);
+ res.Minor = static_cast<unsigned int>(minorUL);
+ }
}
- return qtMinor;
-}
-bool cmQtAutoGenInitializer::QtVersionGreaterOrEqual(
- unsigned long requestMajor, unsigned long requestMinor) const
-{
- unsigned long majorUL(0);
- unsigned long minorUL(0);
- if (cmSystemTools::StringToULong(this->QtVersionMajor.c_str(), &majorUL) &&
- cmSystemTools::StringToULong(this->QtVersionMinor.c_str(), &minorUL)) {
- return (majorUL > requestMajor) ||
- (majorUL == requestMajor && minorUL >= requestMinor);
- }
- return false;
+ return res;
}
bool cmQtAutoGenInitializer::GetMocExecutable()
@@ -1321,9 +1326,9 @@ bool cmQtAutoGenInitializer::GetMocExecutable()
// Find moc executable
{
std::string targetName;
- if (this->QtVersionMajor == "5") {
+ if (this->QtVersion.Major == 5) {
targetName = "Qt5::moc";
- } else if (QtVersionMajor == "4") {
+ } else if (this->QtVersion.Major == 4) {
targetName = "Qt4::moc";
} else {
err = "The AUTOMOC feature supports only Qt 4 and Qt 5";
@@ -1382,9 +1387,9 @@ bool cmQtAutoGenInitializer::GetUicExecutable()
// Find uic executable
{
std::string targetName;
- if (this->QtVersionMajor == "5") {
+ if (this->QtVersion.Major == 5) {
targetName = "Qt5::uic";
- } else if (QtVersionMajor == "4") {
+ } else if (this->QtVersion.Major == 4) {
targetName = "Qt4::uic";
} else {
err = "The AUTOUIC feature supports only Qt 4 and Qt 5";
@@ -1395,7 +1400,7 @@ bool cmQtAutoGenInitializer::GetUicExecutable()
if (tgt != nullptr) {
this->Uic.Executable = tgt->ImportedGetLocation("");
} else {
- if (this->QtVersionMajor == "5") {
+ if (this->QtVersion.Major == 5) {
// Project does not use Qt5Widgets, but has AUTOUIC ON anyway
} else {
err = "Could not find target " + targetName;
@@ -1447,9 +1452,9 @@ bool cmQtAutoGenInitializer::GetRccExecutable()
// Find rcc executable
{
std::string targetName;
- if (this->QtVersionMajor == "5") {
+ if (this->QtVersion.Major == 5) {
targetName = "Qt5::rcc";
- } else if (QtVersionMajor == "4") {
+ } else if (this->QtVersion.Major == 4) {
targetName = "Qt4::rcc";
} else {
err = "The AUTORCC feature supports only Qt 4 and Qt 5";
@@ -1479,7 +1484,7 @@ bool cmQtAutoGenInitializer::GetRccExecutable()
cmSystemTools::OUTPUT_NONE, cmDuration::zero(), cmProcessOutput::Auto);
if (result) {
// Detect if rcc supports (-)-list
- if (this->QtVersionMajor == "5") {
+ if (this->QtVersion.Major == 5) {
if (stdOut.find("--list") != std::string::npos) {
this->Rcc.ListOptions.push_back("--list");
} else {
diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h
index 295d41f..ce00e00 100644
--- a/Source/cmQtAutoGenInitializer.h
+++ b/Source/cmQtAutoGenInitializer.h
@@ -18,10 +18,6 @@ class cmTarget;
class cmQtAutoGenInitializer : public cmQtAutoGen
{
public:
- static std::string GetQtMajorVersion(cmGeneratorTarget const* target);
- static std::string GetQtMinorVersion(cmGeneratorTarget const* target,
- std::string const& qtVersionMajor);
-
/// @brief Rcc job information
class Qrc
{
@@ -48,9 +44,11 @@ public:
};
public:
+ static IntegerVersion GetQtVersion(cmGeneratorTarget const* target);
+
cmQtAutoGenInitializer(cmGeneratorTarget* target, bool mocEnabled,
bool uicEnabled, bool rccEnabled,
- std::string const& qtVersionMajor);
+ IntegerVersion const& qtVersion);
bool InitCustomTargets();
bool SetupCustomTargets();
@@ -69,9 +67,6 @@ private:
void AddGeneratedSource(std::string const& filename, GeneratorT genType);
- bool QtVersionGreaterOrEqual(unsigned long requestMajor,
- unsigned long requestMinor) const;
-
bool GetMocExecutable();
bool GetUicExecutable();
bool GetRccExecutable();
@@ -83,11 +78,8 @@ private:
private:
cmGeneratorTarget* Target;
- // Qt
- std::string QtVersionMajor;
- std::string QtVersionMinor;
-
// Configuration
+ IntegerVersion QtVersion;
bool MultiConfig = false;
std::string ConfigDefault;
std::vector<std::string> ConfigsList;