summaryrefslogtreecommitdiffstats
path: root/Source/cmQtAutoGenInitializer.cxx
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-02-12 14:59:52 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2019-02-21 17:27:10 (GMT)
commitd9893fb594c904605b3b9ebf3548d2f48793f788 (patch)
treea4664687476a302a3315aa6c5a0c140c14cc33a0 /Source/cmQtAutoGenInitializer.cxx
parent5e36209f716900cb8a61c1bffd480c639be041bb (diff)
downloadCMake-d9893fb594c904605b3b9ebf3548d2f48793f788.zip
CMake-d9893fb594c904605b3b9ebf3548d2f48793f788.tar.gz
CMake-d9893fb594c904605b3b9ebf3548d2f48793f788.tar.bz2
Autogen: Refactor Qt executable name computation
In AUTOGEN a common new base class cmQtAutoGenInitializer::GenVarsT for mo/uic/rcc generator variables allows to generalize variable computation functions.
Diffstat (limited to 'Source/cmQtAutoGenInitializer.cxx')
-rw-r--r--Source/cmQtAutoGenInitializer.cxx248
1 files changed, 124 insertions, 124 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index da0d2f4..1095dad 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -36,25 +36,9 @@
#include <set>
#include <sstream>
#include <string>
-#include <type_traits>
#include <utility>
#include <vector>
-std::string GetQtExecutableTargetName(
- const cmQtAutoGen::IntegerVersion& qtVersion, std::string const& executable)
-{
- if (qtVersion.Major == 6) {
- return ("Qt6::" + executable);
- }
- if (qtVersion.Major == 5) {
- return ("Qt5::" + executable);
- }
- if (qtVersion.Major == 4) {
- return ("Qt4::" + executable);
- }
- return ("");
-}
-
static std::size_t GetParallelCPUCount()
{
static std::size_t count = 0;
@@ -399,16 +383,8 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
}
// Init uic specific settings
- if (this->Uic.Enabled) {
- if (InitUic()) {
- auto* uicTarget = makefile->FindTargetToUse(
- GetQtExecutableTargetName(this->QtVersion, "uic"));
- if (uicTarget != nullptr) {
- this->AutogenTarget.DependTargets.insert(uicTarget);
- }
- } else {
- return false;
- }
+ if (this->Uic.Enabled && !InitUic()) {
+ return false;
}
// Autogen target name
@@ -449,12 +425,6 @@ bool cmQtAutoGenInitializer::InitCustomTargets()
this->AutogenTarget.DependOrigin =
this->Target->GetPropertyAsBool("AUTOGEN_ORIGIN_DEPENDS");
- auto* mocTarget = makefile->FindTargetToUse(
- GetQtExecutableTargetName(this->QtVersion, "moc"));
- if (mocTarget != nullptr) {
- this->AutogenTarget.DependTargets.insert(mocTarget);
- }
-
std::string const deps =
this->Target->GetSafeProperty("AUTOGEN_TARGET_DEPENDS");
if (!deps.empty()) {
@@ -575,7 +545,18 @@ bool cmQtAutoGenInitializer::InitMoc()
}
// Moc executable
- return GetMocExecutable();
+ {
+ if (!this->GetQtExecutable(this->Moc, "moc", false, nullptr)) {
+ return false;
+ }
+ // Let the _autogen target depend on the moc executable
+ if (this->Moc.ExecutableTarget != nullptr) {
+ this->AutogenTarget.DependTargets.insert(
+ this->Moc.ExecutableTarget->Target);
+ }
+ }
+
+ return true;
}
bool cmQtAutoGenInitializer::InitUic()
@@ -618,12 +599,39 @@ bool cmQtAutoGenInitializer::InitUic()
}
// Uic executable
- return GetUicExecutable();
+ {
+ if (!this->GetQtExecutable(this->Uic, "uic", true, nullptr)) {
+ return false;
+ }
+ // Let the _autogen target depend on the uic executable
+ if (this->Uic.ExecutableTarget != nullptr) {
+ this->AutogenTarget.DependTargets.insert(
+ this->Uic.ExecutableTarget->Target);
+ }
+ }
+
+ return true;
}
bool cmQtAutoGenInitializer::InitRcc()
{
- return GetRccExecutable();
+ // Rcc executable
+ {
+ std::string stdOut;
+ if (!this->GetQtExecutable(this->Rcc, "rcc", false, &stdOut)) {
+ return false;
+ }
+ // Evaluate test output
+ if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
+ if (stdOut.find("--list") != std::string::npos) {
+ this->Rcc.ListOptions.emplace_back("--list");
+ } else {
+ this->Rcc.ListOptions.emplace_back("-list");
+ }
+ }
+ }
+
+ return true;
}
bool cmQtAutoGenInitializer::InitScanFiles()
@@ -1109,7 +1117,6 @@ bool cmQtAutoGenInitializer::InitRccTargets()
{
cmMakefile* makefile = this->Target->Target->GetMakefile();
cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
- auto rccTargetName = GetQtExecutableTargetName(this->QtVersion, "rcc");
for (Qrc const& qrc : this->Rcc.Qrcs) {
// Register info file as generated by CMake
@@ -1174,8 +1181,8 @@ bool cmQtAutoGenInitializer::InitRccTargets()
if (!this->TargetsFolder.empty()) {
autoRccTarget->SetProperty("FOLDER", this->TargetsFolder.c_str());
}
- if (!rccTargetName.empty()) {
- autoRccTarget->AddUtility(rccTargetName, makefile);
+ if (!this->Rcc.ExecutableTargetName.empty()) {
+ autoRccTarget->AddUtility(this->Rcc.ExecutableTargetName, makefile);
}
}
// Add autogen target to the origin target dependencies
@@ -1195,8 +1202,8 @@ bool cmQtAutoGenInitializer::InitRccTargets()
// Add resource file to the custom command dependencies
ccDepends.push_back(fileName);
}
- if (!rccTargetName.empty()) {
- ccDepends.push_back(rccTargetName);
+ if (!this->Rcc.ExecutableTargetName.empty()) {
+ ccDepends.push_back(this->Rcc.ExecutableTargetName);
}
makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends,
/*main_dependency*/ std::string(),
@@ -1383,8 +1390,12 @@ static unsigned int CharPtrToUInt(const char* const input)
static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions(
cmGeneratorTarget const* target)
{
- cmMakefile* makefile = target->Target->GetMakefile();
+ // Qt version variable prefixes
+ static std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core",
+ "QT" } };
+
std::vector<cmQtAutoGen::IntegerVersion> result;
+ result.reserve(prefixes.size() * 2);
// Adds a version to the result (nullptr safe)
auto addVersion = [&result](const char* major, const char* minor) {
cmQtAutoGen::IntegerVersion ver(CharPtrToUInt(major),
@@ -1393,8 +1404,7 @@ static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions(
result.emplace_back(ver);
}
};
- // Qt version variable prefixes
- std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core", "QT" } };
+ cmMakefile* makefile = target->Target->GetMakefile();
// Read versions from variables
for (const std::string& prefix : prefixes) {
@@ -1438,99 +1448,89 @@ cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target)
return res;
}
-std::pair<bool, std::string> cmQtAutoGenInitializer::GetQtExecutable(
- const std::string& executable, bool ignoreMissingTarget, std::string* output)
+bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
+ const std::string& executable,
+ bool ignoreMissingTarget,
+ std::string* output) const
{
- const std::string upperExecutable = cmSystemTools::UpperCase(executable);
- std::string result = this->Target->Target->GetSafeProperty(
- "AUTO" + upperExecutable + "_EXECUTABLE");
- if (!result.empty()) {
- cmListFileBacktrace lfbt =
- this->Target->Target->GetMakefile()->GetBacktrace();
- cmGeneratorExpression ge(lfbt);
- std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(result);
- result = cge->Evaluate(this->Target->GetLocalGenerator(), "");
-
- return std::make_pair(true, result);
- }
+ auto print_err = [this, &genVars](std::string const& err) {
+ std::string msg = genVars.GenNameUpper;
+ msg += " for target ";
+ msg += this->Target->GetName();
+ msg += ": ";
+ msg += err;
+ cmSystemTools::Error(msg);
+ };
- std::string err;
+ // Custom executable
+ {
+ std::string const prop = genVars.GenNameUpper + "_EXECUTABLE";
+ std::string const val = this->Target->Target->GetSafeProperty(prop);
+ if (!val.empty()) {
+ // Evaluate generator expression
+ {
+ cmListFileBacktrace lfbt =
+ this->Target->Target->GetMakefile()->GetBacktrace();
+ cmGeneratorExpression ge(lfbt);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
+ genVars.Executable =
+ cge->Evaluate(this->Target->GetLocalGenerator(), "");
+ }
+ if (genVars.Executable.empty() && !ignoreMissingTarget) {
+ print_err(prop + " evaluates to an empty value");
+ return false;
+ }
+ return true;
+ }
+ }
- // Find executable
+ // Find executable target
{
- const std::string targetName =
- GetQtExecutableTargetName(this->QtVersion, executable);
- if (targetName.empty()) {
- err = "The AUTO" + upperExecutable + " feature ";
- err += "supports only Qt 4, Qt 5 and Qt 6.";
- } else {
- cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
- cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse(targetName);
- if (tgt != nullptr) {
- if (tgt->IsImported()) {
- result = tgt->ImportedGetLocation("");
- } else {
- result = tgt->GetLocation("");
- }
+ // Find executable target name
+ std::string targetName;
+ if (this->QtVersion.Major == 4) {
+ targetName = "Qt4::";
+ } else if (this->QtVersion.Major == 5) {
+ targetName = "Qt5::";
+ } else if (this->QtVersion.Major == 6) {
+ targetName = "Qt6::";
+ }
+ targetName += executable;
+
+ // Find target
+ cmLocalGenerator* localGen = this->Target->GetLocalGenerator();
+ cmGeneratorTarget* target = localGen->FindGeneratorTargetToUse(targetName);
+ if (target != nullptr) {
+ genVars.ExecutableTargetName = targetName;
+ genVars.ExecutableTarget = target;
+ if (target->IsImported()) {
+ genVars.Executable = target->ImportedGetLocation("");
} else {
- if (ignoreMissingTarget) {
- return std::make_pair(true, "");
- }
-
- err = "Could not find target " + targetName;
+ genVars.Executable = target->GetLocation("");
}
+ } else {
+ if (ignoreMissingTarget) {
+ return true;
+ }
+ std::string err = "Could not find ";
+ err += executable;
+ err += " executable target ";
+ err += targetName;
+ print_err(err);
+ return false;
}
}
// Test executable
- if (err.empty()) {
- this->GlobalInitializer->GetExecutableTestOutput(executable, result, err,
- output);
- }
-
- // Print error
- if (!err.empty()) {
- std::string msg = "AutoGen (";
- msg += this->Target->GetName();
- msg += "): ";
- msg += err;
- cmSystemTools::Error(msg);
- return std::make_pair(false, "");
- }
-
- return std::make_pair(true, result);
-}
-
-bool cmQtAutoGenInitializer::GetMocExecutable()
-{
- const auto result = this->GetQtExecutable("moc", false, nullptr);
- this->Moc.Executable = result.second;
- return result.first;
-}
-
-bool cmQtAutoGenInitializer::GetUicExecutable()
-{
- const auto result = this->GetQtExecutable("uic", true, nullptr);
- this->Uic.Executable = result.second;
- return result.first;
-}
-
-bool cmQtAutoGenInitializer::GetRccExecutable()
-{
- std::string stdOut;
- const auto result = this->GetQtExecutable("rcc", false, &stdOut);
- this->Rcc.Executable = result.second;
- if (!result.first) {
- return false;
- }
-
- if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
- if (stdOut.find("--list") != std::string::npos) {
- this->Rcc.ListOptions.emplace_back("--list");
- } else {
- this->Rcc.ListOptions.emplace_back("-list");
+ {
+ std::string err;
+ if (!this->GlobalInitializer->GetExecutableTestOutput(
+ executable, genVars.Executable, err, output)) {
+ print_err(err);
+ return false;
}
}
+
return true;
}