From b2343ff08682e23f61be27c4faf02f8e2c37abcf Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 14 Jan 2019 17:04:44 +0100 Subject: Autogen: Fix rcc validity check --- Source/cmQtAutoGenGlobalInitializer.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index f4cf3e0..d1cbd0d 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -93,7 +93,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( bool const rccAvailable = (validQt || !rccExec.empty()); bool const mocIsValid = (moc && mocAvailable); bool const uicIsValid = (uic && uicAvailable); - bool const rccIsValid = (rcc && uicAvailable); + bool const rccIsValid = (rcc && rccAvailable); // Disabled AUTOMOC/UIC/RCC warning bool const mocDisabled = (moc && !mocAvailable); bool const uicDisabled = (uic && !uicAvailable); -- cgit v0.12 From f2f166133402ad5f7998e0fef93b04f56c2f6d07 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 14 Jan 2019 17:33:03 +0100 Subject: Autogen: Add and use QtAutoGen::Tools method --- Source/cmQtAutoGen.cxx | 35 +++++++++++++++++++++++++++++++++ Source/cmQtAutoGen.h | 3 +++ Source/cmQtAutoGenGlobalInitializer.cxx | 14 +------------ Tests/RunCMake/Autogen/NoQt-stderr.txt | 2 +- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Source/cmQtAutoGen.cxx b/Source/cmQtAutoGen.cxx index 000529d..9dc5fa8 100644 --- a/Source/cmQtAutoGen.cxx +++ b/Source/cmQtAutoGen.cxx @@ -99,6 +99,41 @@ std::string cmQtAutoGen::GeneratorNameUpper(GeneratorT genType) return cmSystemTools::UpperCase(cmQtAutoGen::GeneratorName(genType)); } +std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc) +{ + std::string res; + std::vector lst; + if (moc) { + lst.emplace_back("AUTOMOC"); + } + if (uic) { + lst.emplace_back("AUTOUIC"); + } + if (rcc) { + lst.emplace_back("AUTORCC"); + } + switch (lst.size()) { + case 1: + res += lst.at(0); + break; + case 2: + res += lst.at(0); + res += " and "; + res += lst.at(1); + break; + case 3: + res += lst.at(0); + res += ", "; + res += lst.at(1); + res += " and "; + res += lst.at(2); + break; + default: + break; + } + return res; +} + std::string cmQtAutoGen::Quoted(std::string const& text) { static const char* rep[18] = { "\\", "\\\\", "\"", "\\\"", "\a", "\\a", diff --git a/Source/cmQtAutoGen.h b/Source/cmQtAutoGen.h index 4118dc7..96d1946 100644 --- a/Source/cmQtAutoGen.h +++ b/Source/cmQtAutoGen.h @@ -60,6 +60,9 @@ public: /// @brief Returns the generator name in upper case static std::string GeneratorNameUpper(GeneratorT genType); + /// @brief Returns a string with the requested tool names + static std::string Tools(bool moc, bool uic, bool rcc); + /// @brief Returns the string escaped and enclosed in quotes static std::string Quoted(std::string const& text); diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index d1cbd0d..a5a8423 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -102,19 +102,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( std::string msg = "AUTOGEN: No valid Qt version found for target "; msg += target->GetName(); msg += ". "; - { - std::vector lst; - if (mocDisabled) { - lst.emplace_back("AUTOMOC"); - } - if (uicDisabled) { - lst.emplace_back("AUTOUIC"); - } - if (rccDisabled) { - lst.emplace_back("AUTORCC"); - } - msg += cmJoin(lst, ", "); - } + msg += cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled); msg += " disabled. Consider adding:\n"; if (uicDisabled) { msg += " find_package(Qt5 COMPONENTS Widgets)\n"; diff --git a/Tests/RunCMake/Autogen/NoQt-stderr.txt b/Tests/RunCMake/Autogen/NoQt-stderr.txt index 6b4a933..66b6cae 100644 --- a/Tests/RunCMake/Autogen/NoQt-stderr.txt +++ b/Tests/RunCMake/Autogen/NoQt-stderr.txt @@ -1,5 +1,5 @@ ^CMake Warning \(dev\) in CMakeLists.txt: - AUTOGEN: No valid Qt version found for target main. AUTOMOC, AUTOUIC, + AUTOGEN: No valid Qt version found for target main. AUTOMOC, AUTOUIC and AUTORCC disabled. Consider adding: find_package\(Qt5 COMPONENTS Widgets\) -- cgit v0.12 From 5fe18eee1392c312612fad0e6f408ea7cb1ef29d Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 14 Jan 2019 18:32:17 +0100 Subject: Autogen: Adaptive missing Qt warning This makes the warning message for a missing Qt use the requested Qt version in the message text. --- Source/cmQtAutoGenGlobalInitializer.cxx | 20 +++++++++------ Source/cmQtAutoGenInitializer.cxx | 43 ++++++++++++++++----------------- Source/cmQtAutoGenInitializer.h | 5 +++- Tests/RunCMake/Autogen/NoQt-stderr.txt | 2 +- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index a5a8423..0b1995d 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -85,8 +85,8 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( // We support Qt4, Qt5 and Qt6 auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target); - bool const validQt = (qtVersion.Major == 4) || - (qtVersion.Major == 5) || (qtVersion.Major == 6); + bool const validQt = (qtVersion.first.Major == 4) || + (qtVersion.first.Major == 5) || (qtVersion.first.Major == 6); bool const mocAvailable = (validQt || !mocExec.empty()); bool const uicAvailable = (validQt || !uicExec.empty()); @@ -104,10 +104,16 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( msg += ". "; msg += cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled); msg += " disabled. Consider adding:\n"; - if (uicDisabled) { - msg += " find_package(Qt5 COMPONENTS Widgets)\n"; - } else { - msg += " find_package(Qt5 COMPONENTS Core)\n"; + { + std::string version = (qtVersion.second == 0) + ? std::string("") + : std::to_string(qtVersion.second); + std::string comp = uicDisabled ? "Widgets" : "Core"; + msg += " find_package(Qt"; + msg += version; + msg += " COMPONENTS "; + msg += comp; + msg += ")\n"; } msg += "to your CMakeLists.txt file."; target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg); @@ -115,7 +121,7 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( if (mocIsValid || uicIsValid || rccIsValid) { // Create autogen target initializer Initializers_.emplace_back(cm::make_unique( - this, target, qtVersion, mocIsValid, uicIsValid, rccIsValid, + this, target, qtVersion.first, mocIsValid, uicIsValid, rccIsValid, globalAutoGenTarget, globalAutoRccTarget)); } } diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index e4d2c82..7721e91 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1409,32 +1409,31 @@ static std::vector GetKnownQtVersions( return result; } -cmQtAutoGenInitializer::IntegerVersion cmQtAutoGenInitializer::GetQtVersion( - cmGeneratorTarget const* target) +std::pair +cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target) { - auto knownQtVersions = GetKnownQtVersions(target); - if (knownQtVersions.empty()) { - return cmQtAutoGenInitializer::IntegerVersion(); // No Qt - } - - // Pick a version from the known versions: - auto targetVersion = CharPtrToInt( - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", "")); + std::pair res( + IntegerVersion(), + CharPtrToInt(target->GetLinkInterfaceDependentStringProperty( + "QT_MAJOR_VERSION", ""))); - if (targetVersion == 0) { - // No specific version was requested by the target: - // Use highest known Qt version. - return knownQtVersions.at(0); - } - - for (auto it : knownQtVersions) { - if (it.Major == targetVersion) { - return it; + auto knownQtVersions = GetKnownQtVersions(target); + if (!knownQtVersions.empty()) { + if (res.second == 0) { + // No specific version was requested by the target: + // Use highest known Qt version. + res.first = knownQtVersions.at(0); + } else { + // Pick a version from the known versions: + for (auto it : knownQtVersions) { + if (it.Major == res.second) { + res.first = it; + break; + } + } } } - - // Requested version was not found - return cmQtAutoGenInitializer::IntegerVersion(); + return res; } std::pair GetQtExecutable( diff --git a/Source/cmQtAutoGenInitializer.h b/Source/cmQtAutoGenInitializer.h index 5cef1b3..47f157c 100644 --- a/Source/cmQtAutoGenInitializer.h +++ b/Source/cmQtAutoGenInitializer.h @@ -11,6 +11,7 @@ #include #include #include +#include #include class cmGeneratorTarget; @@ -76,7 +77,9 @@ public: }; public: - static IntegerVersion GetQtVersion(cmGeneratorTarget const* target); + /// @return The detected Qt version and the required Qt major version + static std::pair GetQtVersion( + cmGeneratorTarget const* target); cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer, cmGeneratorTarget* target, diff --git a/Tests/RunCMake/Autogen/NoQt-stderr.txt b/Tests/RunCMake/Autogen/NoQt-stderr.txt index 66b6cae..1c6660a 100644 --- a/Tests/RunCMake/Autogen/NoQt-stderr.txt +++ b/Tests/RunCMake/Autogen/NoQt-stderr.txt @@ -2,7 +2,7 @@ AUTOGEN: No valid Qt version found for target main. AUTOMOC, AUTOUIC and AUTORCC disabled. Consider adding: - find_package\(Qt5 COMPONENTS Widgets\) + find_package\(Qt COMPONENTS Widgets\) to your CMakeLists.txt file. This warning is for project developers. Use -Wno-dev to suppress it. -- cgit v0.12