浏览代码

Merge topic 'autogen-ninja-multi-config'

8a526f6a44 Autogen: Fix Ninja Multi-Config dependency graph regression
3cac48e8cd Autogen: Restore <target_name>_autogen_timestamp_deps target

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !10039
Brad King 1 年之前
父节点
当前提交
5aebb62d0c
共有 2 个文件被更改,包括 55 次插入17 次删除
  1. 54 17
      Source/cmQtAutoGenInitializer.cxx
  2. 1 0
      Tests/RunCMake/Autogen_6/RunCMakeTest.cmake

+ 54 - 17
Source/cmQtAutoGenInitializer.cxx

@@ -1334,12 +1334,25 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
   }
   }
 
 
   if (this->Uic.Enabled) {
   if (this->Uic.Enabled) {
-    // Make all ui_*.h files byproducts of the ${target}_autogen/timestamp
-    // custom command if the generation of depfile is enabled.
-    auto& byProducts = useDepfile ? timestampByproducts : autogenByproducts;
-    for (auto const& file : this->Uic.UiHeaders) {
-      this->AddGeneratedSource(file.first, this->Uic);
-      byProducts.push_back(file.second);
+    auto const useAdvancedUicGraph = [this]() -> bool {
+      if (this->MultiConfig && this->GlobalGen->IsNinja()) {
+        return this->UseBetterGraph;
+      }
+      return true;
+    }();
+    if (useAdvancedUicGraph) {
+      // Make all ui_*.h files byproducts of the ${target}_autogen/timestamp
+      // custom command if the generation of depfile is enabled.
+      auto& byProducts = useDepfile ? timestampByproducts : autogenByproducts;
+      for (auto const& file : this->Uic.UiHeaders) {
+        this->AddGeneratedSource(file.first, this->Uic);
+        byProducts.push_back(file.second);
+      }
+    } else {
+      for (auto const& file : this->Uic.UiHeaders) {
+        this->AddGeneratedSource(file.first, this->Uic);
+        autogenByproducts.push_back(file.second);
+      }
     }
     }
   }
   }
 
 
@@ -1477,16 +1490,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
       }
       }
     }
     }
 
 
-    // For the Ninja, Makefile and Qt >= 5.15, add custom commands that create
-    // XXX_autogen/timestamp files. Those custom commands have a depfile
-    // assigned that is generated from the depfiles that were created by moc.
-    //
-    // The XXX_autogen targets merely wrap the XXX_autogen/timestamp custom
-    // commands.
-    // The dependency tree would then look like
-    // the original dependencies of '_autogen' target <-'/timestamp' file
-    // <- '_autogen' target
-
     cmTarget* timestampTarget = nullptr;
     cmTarget* timestampTarget = nullptr;
     std::vector<std::string> dependencies(
     std::vector<std::string> dependencies(
       this->AutogenTarget.DependFiles.begin(),
       this->AutogenTarget.DependFiles.begin(),
@@ -1494,6 +1497,40 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
     if (useDepfile) {
     if (useDepfile) {
       // Create a custom command that generates a timestamp file and
       // Create a custom command that generates a timestamp file and
       // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
       // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
+      //
+      // Also create an additional '_autogen_timestamp_deps' that the custom
+      // command will depend on. It will have no sources or commands to
+      // execute, but it will have dependencies that would originally be
+      // assigned to the pre-Qt 5.15 'autogen' target. These dependencies will
+      // serve as a list of order-only dependencies for the custom command,
+      // without forcing the custom command to re-execute.
+      //
+      // The dependency tree would then look like
+      // '_autogen_timestamp_deps (order-only)' <- '/timestamp' file <-
+      // '_autogen' target.
+      const auto timestampTargetName =
+        cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
+
+      auto cc = cm::make_unique<cmCustomCommand>();
+      cc->SetWorkingDirectory(this->Dir.Work.c_str());
+      cc->SetDepends(dependencies);
+      cc->SetEscapeOldStyle(false);
+      timestampTarget = this->LocalGen->AddUtilityCommand(timestampTargetName,
+                                                          true, std::move(cc));
+
+      this->LocalGen->AddGeneratorTarget(
+        cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen));
+
+      // Set FOLDER property on the timestamp target, so it appears in the
+      // appropriate folder in an IDE or in the file api.
+      if (!this->TargetsFolder.empty()) {
+        timestampTarget->SetProperty("FOLDER", this->TargetsFolder);
+      }
+
+      // Make '/timestamp' file depend on '_autogen_timestamp_deps' and on the
+      // moc and uic executables (whichever are enabled).
+      dependencies.clear();
+      dependencies.push_back(timestampTargetName);
 
 
       AddAutogenExecutableToDependencies(this->Moc, dependencies);
       AddAutogenExecutableToDependencies(this->Moc, dependencies);
       AddAutogenExecutableToDependencies(this->Uic, dependencies);
       AddAutogenExecutableToDependencies(this->Uic, dependencies);
@@ -1538,7 +1575,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
           { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
           { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
         this->AddGeneratedSource(outputFile, this->Moc);
         this->AddGeneratedSource(outputFile, this->Moc);
       }
       }
-      auto cc = cm::make_unique<cmCustomCommand>();
+      cc = cm::make_unique<cmCustomCommand>();
       cc->SetOutputs(outputFile);
       cc->SetOutputs(outputFile);
       cc->SetByproducts(timestampByproducts);
       cc->SetByproducts(timestampByproducts);
       cc->SetDepends(dependencies);
       cc->SetDepends(dependencies);

+ 1 - 0
Tests/RunCMake/Autogen_6/RunCMakeTest.cmake

@@ -6,6 +6,7 @@ if (DEFINED with_qt_version)
     -Dwith_qt_version=${with_qt_version}
     -Dwith_qt_version=${with_qt_version}
     "-DQt${with_qt_version}_DIR:PATH=${Qt${with_qt_version}_DIR}"
     "-DQt${with_qt_version}_DIR:PATH=${Qt${with_qt_version}_DIR}"
     "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}"
     "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}"
+    "-DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=ON"
   )
   )
   if (QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0)
   if (QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0)
     macro(set_test_variables_for_unwanted_builds)
     macro(set_test_variables_for_unwanted_builds)