Autogen: Use integers to store the Qt version

This commit is contained in:
Sebastian Holtermann
2018-08-13 12:06:19 +02:00
parent 1d87c9f318
commit 3aa11f31fc
4 changed files with 91 additions and 68 deletions
+4 -4
View File
@@ -34,6 +34,7 @@
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmOutputConverter.h" #include "cmOutputConverter.h"
#include "cmPolicies.h" #include "cmPolicies.h"
#include "cmQtAutoGen.h"
#include "cmQtAutoGenInitializer.h" #include "cmQtAutoGenInitializer.h"
#include "cmSourceFile.h" #include "cmSourceFile.h"
#include "cmState.h" #include "cmState.h"
@@ -1495,15 +1496,14 @@ bool cmGlobalGenerator::QtAutoGen()
continue; continue;
} }
std::string qtVersionMajor = auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target);
cmQtAutoGenInitializer::GetQtMajorVersion(target);
// don't do anything if there is no Qt4 or Qt5Core (which contains moc) // 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; continue;
} }
autogenInits.emplace_back(cm::make_unique<cmQtAutoGenInitializer>( autogenInits.emplace_back(cm::make_unique<cmQtAutoGenInitializer>(
target, mocEnabled, uicEnabled, rccEnabled, qtVersionMajor)); target, mocEnabled, uicEnabled, rccEnabled, qtVersion));
} }
} }
+26
View File
@@ -28,6 +28,32 @@ public:
RCC 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: public:
/// @brief Returns the generator name /// @brief Returns the generator name
static std::string const& GeneratorName(GeneratorT genType); static std::string const& GeneratorName(GeneratorT genType);
+57 -52
View File
@@ -173,18 +173,17 @@ static bool StaticLibraryCycle(cmGeneratorTarget const* targetOrigin,
return cycle; return cycle;
} }
cmQtAutoGenInitializer::cmQtAutoGenInitializer( cmQtAutoGenInitializer::cmQtAutoGenInitializer(cmGeneratorTarget* target,
cmGeneratorTarget* target, bool mocEnabled, bool uicEnabled, bool rccEnabled, bool mocEnabled,
std::string const& qtVersionMajor) bool uicEnabled,
bool rccEnabled,
IntegerVersion const& qtVersion)
: Target(target) : Target(target)
, QtVersionMajor(qtVersionMajor) , QtVersion(qtVersion)
{ {
Moc.Enabled = mocEnabled; Moc.Enabled = mocEnabled;
Uic.Enabled = uicEnabled; Uic.Enabled = uicEnabled;
Rcc.Enabled = rccEnabled; Rcc.Enabled = rccEnabled;
this->QtVersionMinor =
cmQtAutoGenInitializer::GetQtMinorVersion(target, this->QtVersionMajor);
} }
bool cmQtAutoGenInitializer::InitCustomTargets() bool cmQtAutoGenInitializer::InitCustomTargets()
@@ -381,14 +380,14 @@ bool cmQtAutoGenInitializer::InitMoc()
// Moc predefs command // Moc predefs command
if (this->Target->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") && if (this->Target->GetPropertyAsBool("AUTOMOC_COMPILER_PREDEFINES") &&
this->QtVersionGreaterOrEqual(5, 8)) { (this->QtVersion >= IntegerVersion(5, 8))) {
this->Moc.PredefsCmd = this->Moc.PredefsCmd =
makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND"); makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_PREDEFINES_COMMAND");
} }
// Moc includes // Moc includes
{ {
bool const appendImplicit = (this->QtVersionMajor == "5"); bool const appendImplicit = (this->QtVersion.Major == 5);
auto GetIncludeDirs = auto GetIncludeDirs =
[this, localGen, appendImplicit](std::string const& cfg) -> std::string { [this, localGen, appendImplicit](std::string const& cfg) -> std::string {
// Get the include dirs for this target, without stripping the implicit // Get the include dirs for this target, without stripping the implicit
@@ -725,7 +724,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
// Process qrc files // Process qrc files
if (!this->Rcc.Qrcs.empty()) { if (!this->Rcc.Qrcs.empty()) {
const bool QtV5 = (this->QtVersionMajor == "5"); const bool QtV5 = (this->QtVersion.Major == 5);
// Target rcc options // Target rcc options
std::vector<std::string> optionsTarget; std::vector<std::string> optionsTarget;
cmSystemTools::ExpandListArgument( cmSystemTools::ExpandListArgument(
@@ -1097,6 +1096,9 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
ofs << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value) ofs << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value)
<< ")\n"; << ")\n";
}; };
auto CWriteUInt = [&ofs](const char* key, unsigned int value) {
ofs << "set(" << key << " " << value << ")\n";
};
auto CWriteList = [&CWrite](const char* key, auto CWriteList = [&CWrite](const char* key,
std::vector<std::string> const& list) { std::vector<std::string> const& list) {
CWrite(key, cmJoin(list, ";")); CWrite(key, cmJoin(list, ";"));
@@ -1152,7 +1154,7 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
CWriteMap("AM_SETTINGS_FILE", this->AutogenTarget.ConfigSettingsFile); CWriteMap("AM_SETTINGS_FILE", this->AutogenTarget.ConfigSettingsFile);
ofs << "# Qt\n"; 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_MOC_EXECUTABLE", this->Moc.Executable);
CWrite("AM_QT_UIC_EXECUTABLE", this->Uic.Executable); CWrite("AM_QT_UIC_EXECUTABLE", this->Uic.Executable);
@@ -1265,53 +1267,56 @@ void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename,
this->Target->AddSource(filename); this->Target->AddSource(filename);
} }
std::string cmQtAutoGenInitializer::GetQtMajorVersion( cmQtAutoGenInitializer::IntegerVersion cmQtAutoGenInitializer::GetQtVersion(
cmGeneratorTarget const* target) cmGeneratorTarget const* target)
{ {
cmQtAutoGenInitializer::IntegerVersion res;
cmMakefile* makefile = target->Target->GetMakefile(); cmMakefile* makefile = target->Target->GetMakefile();
// -- Major version
std::string qtMajor = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); std::string qtMajor = makefile->GetSafeDefinition("QT_VERSION_MAJOR");
if (qtMajor.empty()) { if (qtMajor.empty()) {
qtMajor = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); qtMajor = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
} }
const char* targetQtVersion = {
target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", ""); const char* targetQtVersion =
if (targetQtVersion != nullptr) { target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", "");
qtMajor = targetQtVersion; if (targetQtVersion != nullptr) {
qtMajor = targetQtVersion;
}
} }
return qtMajor;
}
std::string cmQtAutoGenInitializer::GetQtMinorVersion( // -- Minor version
cmGeneratorTarget const* target, std::string const& qtVersionMajor)
{
cmMakefile* makefile = target->Target->GetMakefile();
std::string qtMinor; std::string qtMinor;
if (qtVersionMajor == "5") { if (!qtMajor.empty()) {
qtMinor = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR"); if (qtMajor == "5") {
} qtMinor = makefile->GetSafeDefinition("Qt5Core_VERSION_MINOR");
if (qtMinor.empty()) { }
qtMinor = makefile->GetSafeDefinition("QT_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 = // -- Convert to integer
target->GetLinkInterfaceDependentStringProperty("QT_MINOR_VERSION", ""); if (!qtMajor.empty() && !qtMinor.empty()) {
if (targetQtVersion != nullptr) { unsigned long majorUL(0);
qtMinor = targetQtVersion; 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( return res;
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;
} }
bool cmQtAutoGenInitializer::GetMocExecutable() bool cmQtAutoGenInitializer::GetMocExecutable()
@@ -1321,9 +1326,9 @@ bool cmQtAutoGenInitializer::GetMocExecutable()
// Find moc executable // Find moc executable
{ {
std::string targetName; std::string targetName;
if (this->QtVersionMajor == "5") { if (this->QtVersion.Major == 5) {
targetName = "Qt5::moc"; targetName = "Qt5::moc";
} else if (QtVersionMajor == "4") { } else if (this->QtVersion.Major == 4) {
targetName = "Qt4::moc"; targetName = "Qt4::moc";
} else { } else {
err = "The AUTOMOC feature supports only Qt 4 and Qt 5"; err = "The AUTOMOC feature supports only Qt 4 and Qt 5";
@@ -1382,9 +1387,9 @@ bool cmQtAutoGenInitializer::GetUicExecutable()
// Find uic executable // Find uic executable
{ {
std::string targetName; std::string targetName;
if (this->QtVersionMajor == "5") { if (this->QtVersion.Major == 5) {
targetName = "Qt5::uic"; targetName = "Qt5::uic";
} else if (QtVersionMajor == "4") { } else if (this->QtVersion.Major == 4) {
targetName = "Qt4::uic"; targetName = "Qt4::uic";
} else { } else {
err = "The AUTOUIC feature supports only Qt 4 and Qt 5"; err = "The AUTOUIC feature supports only Qt 4 and Qt 5";
@@ -1395,7 +1400,7 @@ bool cmQtAutoGenInitializer::GetUicExecutable()
if (tgt != nullptr) { if (tgt != nullptr) {
this->Uic.Executable = tgt->ImportedGetLocation(""); this->Uic.Executable = tgt->ImportedGetLocation("");
} else { } else {
if (this->QtVersionMajor == "5") { if (this->QtVersion.Major == 5) {
// Project does not use Qt5Widgets, but has AUTOUIC ON anyway // Project does not use Qt5Widgets, but has AUTOUIC ON anyway
} else { } else {
err = "Could not find target " + targetName; err = "Could not find target " + targetName;
@@ -1447,9 +1452,9 @@ bool cmQtAutoGenInitializer::GetRccExecutable()
// Find rcc executable // Find rcc executable
{ {
std::string targetName; std::string targetName;
if (this->QtVersionMajor == "5") { if (this->QtVersion.Major == 5) {
targetName = "Qt5::rcc"; targetName = "Qt5::rcc";
} else if (QtVersionMajor == "4") { } else if (this->QtVersion.Major == 4) {
targetName = "Qt4::rcc"; targetName = "Qt4::rcc";
} else { } else {
err = "The AUTORCC feature supports only Qt 4 and Qt 5"; 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); cmSystemTools::OUTPUT_NONE, cmDuration::zero(), cmProcessOutput::Auto);
if (result) { if (result) {
// Detect if rcc supports (-)-list // Detect if rcc supports (-)-list
if (this->QtVersionMajor == "5") { if (this->QtVersion.Major == 5) {
if (stdOut.find("--list") != std::string::npos) { if (stdOut.find("--list") != std::string::npos) {
this->Rcc.ListOptions.push_back("--list"); this->Rcc.ListOptions.push_back("--list");
} else { } else {
+4 -12
View File
@@ -18,10 +18,6 @@ class cmTarget;
class cmQtAutoGenInitializer : public cmQtAutoGen class cmQtAutoGenInitializer : public cmQtAutoGen
{ {
public: public:
static std::string GetQtMajorVersion(cmGeneratorTarget const* target);
static std::string GetQtMinorVersion(cmGeneratorTarget const* target,
std::string const& qtVersionMajor);
/// @brief Rcc job information /// @brief Rcc job information
class Qrc class Qrc
{ {
@@ -48,9 +44,11 @@ public:
}; };
public: public:
static IntegerVersion GetQtVersion(cmGeneratorTarget const* target);
cmQtAutoGenInitializer(cmGeneratorTarget* target, bool mocEnabled, cmQtAutoGenInitializer(cmGeneratorTarget* target, bool mocEnabled,
bool uicEnabled, bool rccEnabled, bool uicEnabled, bool rccEnabled,
std::string const& qtVersionMajor); IntegerVersion const& qtVersion);
bool InitCustomTargets(); bool InitCustomTargets();
bool SetupCustomTargets(); bool SetupCustomTargets();
@@ -69,9 +67,6 @@ private:
void AddGeneratedSource(std::string const& filename, GeneratorT genType); void AddGeneratedSource(std::string const& filename, GeneratorT genType);
bool QtVersionGreaterOrEqual(unsigned long requestMajor,
unsigned long requestMinor) const;
bool GetMocExecutable(); bool GetMocExecutable();
bool GetUicExecutable(); bool GetUicExecutable();
bool GetRccExecutable(); bool GetRccExecutable();
@@ -83,11 +78,8 @@ private:
private: private:
cmGeneratorTarget* Target; cmGeneratorTarget* Target;
// Qt
std::string QtVersionMajor;
std::string QtVersionMinor;
// Configuration // Configuration
IntegerVersion QtVersion;
bool MultiConfig = false; bool MultiConfig = false;
std::string ConfigDefault; std::string ConfigDefault;
std::vector<std::string> ConfigsList; std::vector<std::string> ConfigsList;