فهرست منبع

Autogen: Inline GetKnownQtVersions function

Sebastian Holtermann 6 سال پیش
والد
کامیت
fc36f4410b
1فایلهای تغییر یافته به همراه45 افزوده شده و 49 حذف شده
  1. 45 49
      Source/cmQtAutoGenInitializer.cxx

+ 45 - 49
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: