summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-09-23 09:52:21 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2019-09-25 08:31:06 (GMT)
commitfc36f4410bcdb76ef23a07e5172cb57b41ff5ce3 (patch)
treebae1a7fc3d5ae517b3643261d6dc0e776931cb85
parent1f0d23546d5721fdd92883da4c4368dad3931393 (diff)
downloadCMake-fc36f4410bcdb76ef23a07e5172cb57b41ff5ce3.zip
CMake-fc36f4410bcdb76ef23a07e5172cb57b41ff5ce3.tar.gz
CMake-fc36f4410bcdb76ef23a07e5172cb57b41ff5ce3.tar.bz2
Autogen: Inline GetKnownQtVersions function
-rw-r--r--Source/cmQtAutoGenInitializer.cxx94
1 files changed, 45 insertions, 49 deletions
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index d595eec..3aba19d 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -1506,64 +1506,60 @@ void cmQtAutoGenInitializer::AddCleanFile(std::string const& fileName)
fileName.c_str(), false);
}
-static unsigned int CharPtrToUInt(const char* const input)
-{
- unsigned long tmp = 0;
- if (input != nullptr && cmStrToULong(input, &tmp)) {
- return static_cast<unsigned int>(tmp);
- }
- return 0;
-}
-
-static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions(
- cmGeneratorTarget const* genTarget)
+std::pair<cmQtAutoGen::IntegerVersion, unsigned int>
+cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target)
{
- // Qt version variable prefixes
- static std::initializer_list<
- std::pair<cm::string_view, cm::string_view>> const keys{
- { "Qt6Core_VERSION_MAJOR", "Qt6Core_VERSION_MINOR" },
- { "Qt5Core_VERSION_MAJOR", "Qt5Core_VERSION_MINOR" },
- { "QT_VERSION_MAJOR", "QT_VERSION_MINOR" },
- };
-
- std::vector<cmQtAutoGen::IntegerVersion> result;
- result.reserve(keys.size() * 2);
-
- // 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);
+ // Converts a char ptr to an unsigned int value
+ auto toUInt = [](const char* const input) -> unsigned int {
+ unsigned long tmp = 0;
+ if (input != nullptr && cmStrToULong(input, &tmp)) {
+ return static_cast<unsigned int>(tmp);
}
+ return 0u;
};
- cmMakefile* makefile = genTarget->Makefile;
+ // Initialize return value to a default
+ std::pair<IntegerVersion, unsigned int> res(
+ IntegerVersion(),
+ toUInt(target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION",
+ "")));
- // Read versions from variables
- for (auto const& keyPair : keys) {
- addVersion(makefile->GetDefinition(std::string(keyPair.first)),
- makefile->GetDefinition(std::string(keyPair.second)));
- }
+ // Acquire known Qt versions
+ std::vector<cmQtAutoGen::IntegerVersion> knownQtVersions;
+ {
+ // Qt version variable prefixes
+ static std::initializer_list<
+ std::pair<cm::string_view, cm::string_view>> const keys{
+ { "Qt6Core_VERSION_MAJOR", "Qt6Core_VERSION_MINOR" },
+ { "Qt5Core_VERSION_MAJOR", "Qt5Core_VERSION_MINOR" },
+ { "QT_VERSION_MAJOR", "QT_VERSION_MINOR" },
+ };
- // Read versions from directory properties
- for (auto const& keyPair : keys) {
- addVersion(makefile->GetProperty(std::string(keyPair.first)),
- makefile->GetProperty(std::string(keyPair.second)));
- }
+ knownQtVersions.reserve(keys.size() * 2);
- return result;
-}
+ // Adds a version to the result (nullptr safe)
+ auto addVersion = [&knownQtVersions, &toUInt](const char* major,
+ const char* minor) {
+ cmQtAutoGen::IntegerVersion ver(toUInt(major), toUInt(minor));
+ if (ver.Major != 0) {
+ knownQtVersions.emplace_back(ver);
+ }
+ };
-std::pair<cmQtAutoGen::IntegerVersion, unsigned int>
-cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target)
-{
- std::pair<IntegerVersion, unsigned int> res(
- IntegerVersion(),
- CharPtrToUInt(target->GetLinkInterfaceDependentStringProperty(
- "QT_MAJOR_VERSION", "")));
+ // Read versions from variables
+ for (auto const& keyPair : keys) {
+ addVersion(target->Makefile->GetDefinition(std::string(keyPair.first)),
+ target->Makefile->GetDefinition(std::string(keyPair.second)));
+ }
+
+ // Read versions from directory properties
+ for (auto const& keyPair : keys) {
+ addVersion(target->Makefile->GetProperty(std::string(keyPair.first)),
+ target->Makefile->GetProperty(std::string(keyPair.second)));
+ }
+ }
- auto knownQtVersions = GetKnownQtVersions(target);
+ // Evaluate known Qt versions
if (!knownQtVersions.empty()) {
if (res.second == 0) {
// No specific version was requested by the target: