diff options
author | Brad King <brad.king@kitware.com> | 2019-01-31 15:58:15 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-01-31 15:58:23 (GMT) |
commit | 9eaa6aa599ebc4f380fbc36e352fd5ad25c5bcd7 (patch) | |
tree | c5de0f6ea39c42a541219de4ebcc63b26cbc5513 /Source | |
parent | 5107a84d46ad245221843adbef092118649e6dc7 (diff) | |
parent | 91d98542d26318d8f51c434e689ccf6cddc2d3d0 (diff) | |
download | CMake-9eaa6aa599ebc4f380fbc36e352fd5ad25c5bcd7.zip CMake-9eaa6aa599ebc4f380fbc36e352fd5ad25c5bcd7.tar.gz CMake-9eaa6aa599ebc4f380fbc36e352fd5ad25c5bcd7.tar.bz2 |
Merge topic 'autogen-qt-version-from-dirprops'
91d98542d2 Merge branch 'autogen-qt-version-from-dirprops-release' into autogen-qt-version-from-dirprops-master
062d21c36a Autogen: Read the Qt version from directory properties as well
17ac7c4024 Tests: add cases for providing Qt5Core_VERSION manually
2df6d69014 AutoGen: query Qt5 version from directory properties
b598dfb65e Tests: add cases for providing Qt5Core_VERSION manually
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2883
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 1d7f6d1..caeed15 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1370,7 +1370,7 @@ void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, this->Target->AddSource(filename, prepend); } -static unsigned int CharPtrToInt(const char* const input) +static unsigned int CharPtrToUInt(const char* const input) { unsigned long tmp = 0; if (input != nullptr && cmSystemTools::StringToULong(input, &tmp)) { @@ -1379,36 +1379,43 @@ static unsigned int CharPtrToInt(const char* const input) return 0; } -static unsigned int StringToInt(const std::string& input) -{ - return input.empty() ? 0 : CharPtrToInt(input.c_str()); -} - -static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions( +static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions( cmGeneratorTarget const* target) { cmMakefile* makefile = target->Target->GetMakefile(); - - std::vector<cmQtAutoGenInitializer::IntegerVersion> result; - for (const std::string& prefix : - std::vector<std::string>({ "Qt6Core", "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); + std::vector<cmQtAutoGen::IntegerVersion> result; + // Adds a version to the result (nullptr safe) + auto addVersion = [&result](const char* major, const char* minor) { + cmQtAutoGen::IntegerVersion ver(CharPtrToUInt(major), + CharPtrToUInt(minor)); + if (ver.Major != 0) { + result.emplace_back(ver); } + }; + // Qt version variable prefixes + std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core", "QT" } }; + + // Read versions from variables + for (const std::string& prefix : prefixes) { + addVersion(makefile->GetDefinition(prefix + "_VERSION_MAJOR"), + makefile->GetDefinition(prefix + "_VERSION_MINOR")); + } + + // Read versions from directory properties + for (const std::string& prefix : prefixes) { + addVersion(makefile->GetProperty(prefix + "_VERSION_MAJOR"), + makefile->GetProperty(prefix + "_VERSION_MINOR")); } return result; } -std::pair<cmQtAutoGenInitializer::IntegerVersion, unsigned int> +std::pair<cmQtAutoGen::IntegerVersion, unsigned int> cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target) { std::pair<IntegerVersion, unsigned int> res( IntegerVersion(), - CharPtrToInt(target->GetLinkInterfaceDependentStringProperty( + CharPtrToUInt(target->GetLinkInterfaceDependentStringProperty( "QT_MAJOR_VERSION", ""))); auto knownQtVersions = GetKnownQtVersions(target); |