Imported Upstream version 3.17.5
[platform/upstream/cmake.git] / Source / cmQtAutoGenInitializer.cxx
index 629367d..d8b9100 100644 (file)
@@ -1180,11 +1180,54 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
     if (useNinjaDepfile) {
       // Create a custom command that generates a timestamp file and
       // has a depfile assigned. The depfile is created by JobDepFilesMergeT.
-
-      // Add additional autogen target dependencies
+      //
+      // 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");
+      std::vector<std::string> timestampTargetProvides;
+      cmCustomCommandLines timestampTargetCommandLines;
+
+      // Add additional autogen target dependencies to
+      // '_autogen_timestamp_deps'.
       for (const cmTarget* t : this->AutogenTarget.DependTargets) {
         dependencies.push_back(t->GetName());
       }
+
+      cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
+        timestampTargetName, true, this->Dir.Work.c_str(),
+        /*byproducts=*/timestampTargetProvides,
+        /*depends=*/dependencies, timestampTargetCommandLines, false, nullptr);
+      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);
+
+      if (this->Moc.ExecutableTarget != nullptr) {
+        dependencies.push_back(this->Moc.ExecutableTarget->Target->GetName());
+      }
+      if (this->Uic.ExecutableTarget != nullptr) {
+        dependencies.push_back(this->Uic.ExecutableTarget->Target->GetName());
+      }
+
+      // Create the custom command that outputs the timestamp file.
       const char timestampFileName[] = "timestamp";
       const std::string outputFile =
         cmStrCat(this->Dir.Build, "/", timestampFileName);
@@ -1465,6 +1508,7 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
   info.SetConfig("PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
   info.Set("DEP_FILE", this->AutogenTarget.DepFile);
   info.Set("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName);
+  info.SetArray("CMAKE_LIST_FILES", this->Makefile->GetListFiles());
   info.SetArray("HEADER_EXTENSIONS",
                 this->Makefile->GetCMakeInstance()->GetHeaderExtensions());
   info.SetArrayArray(