summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-12-06 14:05:15 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-12-06 14:05:22 (GMT)
commitd69877fe8617031a4077bb2b97d76af6b2e7b088 (patch)
treee31e8672eae4b166a8f3d8f798c661a1a446f79a
parentd0e371f516085a8d744eaf3b24902c35a910528a (diff)
parent5191b74524e6e2ccc3484989910da8ca46ebb100 (diff)
downloadCMake-d69877fe8617031a4077bb2b97d76af6b2e7b088.zip
CMake-d69877fe8617031a4077bb2b97d76af6b2e7b088.tar.gz
CMake-d69877fe8617031a4077bb2b97d76af6b2e7b088.tar.bz2
Merge topic 'autogen-qtversion-detection'
5191b74524 Autogen: Qt version detection cleanup Acked-by: Kitware Robot <kwrobot@kitware.com> Reviewed-by: Sebastian Holtermann <sebholt@xwmw.org> Merge-request: !2694
-rw-r--r--Source/cmQtAutoGenInitializer.cxx85
1 files changed, 47 insertions, 38 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index 70e77d7..d4819a3 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -1348,56 +1348,65 @@ void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename,
this->Target->AddSource(filename);
}
-cmQtAutoGenInitializer::IntegerVersion cmQtAutoGenInitializer::GetQtVersion(
+static unsigned int CharPtrToInt(const char* const input)
+{
+ unsigned long tmp = 0;
+ if (input != nullptr && cmSystemTools::StringToULong(input, &tmp)) {
+ return static_cast<unsigned int>(tmp);
+ }
+ return 0;
+}
+
+static unsigned int StringToInt(const std::string& input)
+{
+ return input.empty() ? 0 : CharPtrToInt(input.c_str());
+}
+
+static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions(
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;
+ std::vector<cmQtAutoGenInitializer::IntegerVersion> result;
+ for (const std::string& prefix :
+ std::vector<std::string>({ "Qt5Core", "QT" })) {
+ auto tmp = cmQtAutoGenInitializer::IntegerVersion(
+ StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MAJOR")),
+ StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MINOR")));
+ if (tmp.Major != 0) {
+ result.push_back(tmp);
}
}
- // -- Minor version
- std::string qtMinor;
- 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;
- }
- }
+ return result;
+}
+
+cmQtAutoGenInitializer::IntegerVersion 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", ""));
+
+ if (targetVersion == 0) {
+ // No specific version was requested by the target:
+ // Use highest known Qt version.
+ return knownQtVersions.at(0);
}
- // -- 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);
+ for (auto it : knownQtVersions) {
+ if (it.Major == targetVersion) {
+ return it;
}
}
- return res;
+ // Requested version was not found
+ return cmQtAutoGenInitializer::IntegerVersion();
}
bool cmQtAutoGenInitializer::GetMocExecutable()