Commit 5fe18eee authored by Sebastian Holtermann's avatar Sebastian Holtermann
Browse files

Autogen: Adaptive missing Qt warning

This makes the warning message for a missing Qt use
the requested Qt version in the message text.
parent f2f16613
......@@ -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("<QTVERSION>")
: 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<cmQtAutoGenInitializer>(
this, target, qtVersion, mocIsValid, uicIsValid, rccIsValid,
this, target, qtVersion.first, mocIsValid, uicIsValid, rccIsValid,
globalAutoGenTarget, globalAutoRccTarget));
}
}
......
......@@ -1409,32 +1409,31 @@ static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions(
return result;
}
cmQtAutoGenInitializer::IntegerVersion cmQtAutoGenInitializer::GetQtVersion(
cmGeneratorTarget const* target)
std::pair<cmQtAutoGenInitializer::IntegerVersion, unsigned int>
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<IntegerVersion, unsigned int> 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<bool, std::string> GetQtExecutable(
......
......@@ -11,6 +11,7 @@
#include <ostream>
#include <set>
#include <string>
#include <utility>
#include <vector>
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<IntegerVersion, unsigned int> GetQtVersion(
cmGeneratorTarget const* target);
cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
cmGeneratorTarget* target,
......
......@@ -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<QTVERSION> COMPONENTS Widgets\)
to your CMakeLists.txt file.
This warning is for project developers. Use -Wno-dev to suppress it.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment