浏览代码

Autogen: Prepare for Qt 6

Handle Qt version > 5 in Qt AutoGen.

This patch does *NOT* include tests and documentation: There is no
Qt 6 yet. I still need this patch to work on a cmake based build
system for Qt 6.
Tobias Hunger 7 年之前
父节点
当前提交
9045f6a30f
共有 2 个文件被更改,包括 12 次插入8 次删除
  1. 2 1
      Source/cmQtAutoGenGlobalInitializer.cxx
  2. 10 7
      Source/cmQtAutoGenInitializer.cxx

+ 2 - 1
Source/cmQtAutoGenGlobalInitializer.cxx

@@ -77,7 +77,8 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
       if (moc || uic || rcc) {
       if (moc || uic || rcc) {
         // We support Qt4 and Qt5
         // We support Qt4 and Qt5
         auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target);
         auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target);
-        if ((qtVersion.Major == 4) || (qtVersion.Major == 5)) {
+        if ((qtVersion.Major == 4) || (qtVersion.Major == 5) ||
+            (qtVersion.Major == 6)) {
           // Create autogen target initializer
           // Create autogen target initializer
           Initializers_.emplace_back(cm::make_unique<cmQtAutoGenInitializer>(
           Initializers_.emplace_back(cm::make_unique<cmQtAutoGenInitializer>(
             this, target, qtVersion, moc, uic, rcc, globalAutoGenTarget,
             this, target, qtVersion, moc, uic, rcc, globalAutoGenTarget,

+ 10 - 7
Source/cmQtAutoGenInitializer.cxx

@@ -42,6 +42,9 @@
 std::string GetQtExecutableTargetName(
 std::string GetQtExecutableTargetName(
   const cmQtAutoGen::IntegerVersion& qtVersion, std::string const& executable)
   const cmQtAutoGen::IntegerVersion& qtVersion, std::string const& executable)
 {
 {
+  if (qtVersion.Major == 6) {
+    return ("Qt6::" + executable);
+  }
   if (qtVersion.Major == 5) {
   if (qtVersion.Major == 5) {
     return ("Qt5::" + executable);
     return ("Qt5::" + executable);
   }
   }
@@ -504,7 +507,7 @@ bool cmQtAutoGenInitializer::InitMoc()
   {
   {
     // We need to disable this until we have all implicit includes available.
     // We need to disable this until we have all implicit includes available.
     // See issue #18669.
     // See issue #18669.
-    // bool const appendImplicit = (this->QtVersion.Major == 5);
+    // bool const appendImplicit = (this->QtVersion.Major >= 5);
 
 
     auto GetIncludeDirs =
     auto GetIncludeDirs =
       [this, localGen](std::string const& cfg) -> std::vector<std::string> {
       [this, localGen](std::string const& cfg) -> std::vector<std::string> {
@@ -839,7 +842,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
 
 
   // Process qrc files
   // Process qrc files
   if (!this->Rcc.Qrcs.empty()) {
   if (!this->Rcc.Qrcs.empty()) {
-    const bool QtV5 = (this->QtVersion.Major == 5);
+    const bool modernQt = (this->QtVersion.Major >= 5);
     // Target rcc options
     // Target rcc options
     std::vector<std::string> optionsTarget;
     std::vector<std::string> optionsTarget;
     cmSystemTools::ExpandListArgument(
     cmSystemTools::ExpandListArgument(
@@ -911,10 +914,10 @@ bool cmQtAutoGenInitializer::InitScanFiles()
         std::vector<std::string> nameOpts;
         std::vector<std::string> nameOpts;
         nameOpts.emplace_back("-name");
         nameOpts.emplace_back("-name");
         nameOpts.emplace_back(std::move(name));
         nameOpts.emplace_back(std::move(name));
-        RccMergeOptions(opts, nameOpts, QtV5);
+        RccMergeOptions(opts, nameOpts, modernQt);
       }
       }
       // Merge file option
       // Merge file option
-      RccMergeOptions(opts, qrc.Options, QtV5);
+      RccMergeOptions(opts, qrc.Options, modernQt);
       qrc.Options = std::move(opts);
       qrc.Options = std::move(opts);
     }
     }
     // RCC resources
     // RCC resources
@@ -1374,7 +1377,7 @@ static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions(
 
 
   std::vector<cmQtAutoGenInitializer::IntegerVersion> result;
   std::vector<cmQtAutoGenInitializer::IntegerVersion> result;
   for (const std::string& prefix :
   for (const std::string& prefix :
-       std::vector<std::string>({ "Qt5Core", "QT" })) {
+       std::vector<std::string>({ "Qt6Core", "Qt5Core", "QT" })) {
     auto tmp = cmQtAutoGenInitializer::IntegerVersion(
     auto tmp = cmQtAutoGenInitializer::IntegerVersion(
       StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MAJOR")),
       StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MAJOR")),
       StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MINOR")));
       StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MINOR")));
@@ -1427,7 +1430,7 @@ std::pair<bool, std::string> GetQtExecutable(
       GetQtExecutableTargetName(qtVersion, executable);
       GetQtExecutableTargetName(qtVersion, executable);
     if (targetName.empty()) {
     if (targetName.empty()) {
       err = "The AUTOMOC, AUTOUIC and AUTORCC feature ";
       err = "The AUTOMOC, AUTOUIC and AUTORCC feature ";
-      err += "supports only Qt 4 and Qt 5";
+      err += "supports only Qt 4, Qt 5 and Qt 6.";
     } else {
     } else {
       cmLocalGenerator* localGen = target->GetLocalGenerator();
       cmLocalGenerator* localGen = target->GetLocalGenerator();
       cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse(targetName);
       cmGeneratorTarget* tgt = localGen->FindGeneratorTargetToUse(targetName);
@@ -1510,7 +1513,7 @@ bool cmQtAutoGenInitializer::GetRccExecutable()
     return false;
     return false;
   }
   }
 
 
-  if (this->QtVersion.Major == 5) {
+  if (this->QtVersion.Major == 5 || this->QtVersion.Major == 6) {
     if (stdOut.find("--list") != std::string::npos) {
     if (stdOut.find("--list") != std::string::npos) {
       this->Rcc.ListOptions.push_back("--list");
       this->Rcc.ListOptions.push_back("--list");
     } else {
     } else {