Browse Source

Merge topic 'autogen-deps' into release-3.21

4bda03370d AutoGen: Fix needless compilation of mocs_compilation.cpp

Acked-by: Kitware Robot <[email protected]>
Merge-request: !6381
Brad King 4 years ago
parent
commit
2f7c4a788c
1 changed files with 23 additions and 5 deletions
  1. 23 5
      Source/cmQtAutoGenInitializer.cxx

+ 23 - 5
Source/cmQtAutoGenInitializer.cxx

@@ -1111,11 +1111,30 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
   // Register info file as generated by CMake
   // Register info file as generated by CMake
   this->Makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
   this->Makefile->AddCMakeOutputFile(this->AutogenTarget.InfoFile);
 
 
+  // Determine whether to use a depfile for the AUTOGEN target.
+  const bool useNinjaDepfile = this->QtVersion >= IntegerVersion(5, 15) &&
+    this->GlobalGen->GetName().find("Ninja") != std::string::npos;
+
   // Files provided by the autogen target
   // Files provided by the autogen target
   std::vector<std::string> autogenByproducts;
   std::vector<std::string> autogenByproducts;
+  std::vector<std::string> timestampByproducts;
   if (this->Moc.Enabled) {
   if (this->Moc.Enabled) {
     this->AddGeneratedSource(this->Moc.CompilationFile, this->Moc, true);
     this->AddGeneratedSource(this->Moc.CompilationFile, this->Moc, true);
-    autogenByproducts.push_back(this->Moc.CompilationFileGenex);
+    if (useNinjaDepfile) {
+      if (this->MultiConfig) {
+        // Make all mocs_compilation_<CONFIG>.cpp files byproducts of the
+        // ${target}_autogen/timestamp custom command.
+        // We cannot just use Moc.CompilationFileGenex here, because that
+        // custom command runs cmake_autogen for each configuration.
+        for (const auto& p : this->Moc.CompilationFile.Config) {
+          timestampByproducts.push_back(p.second);
+        }
+      } else {
+        timestampByproducts.push_back(this->Moc.CompilationFileGenex);
+      }
+    } else {
+      autogenByproducts.push_back(this->Moc.CompilationFileGenex);
+    }
   }
   }
 
 
   if (this->Uic.Enabled) {
   if (this->Uic.Enabled) {
@@ -1265,8 +1284,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
       this->AutogenTarget.DependFiles.begin(),
       this->AutogenTarget.DependFiles.begin(),
       this->AutogenTarget.DependFiles.end());
       this->AutogenTarget.DependFiles.end());
 
 
-    const bool useNinjaDepfile = this->QtVersion >= IntegerVersion(5, 15) &&
-      this->GlobalGen->GetName().find("Ninja") != std::string::npos;
     if (useNinjaDepfile) {
     if (useNinjaDepfile) {
       // 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.
@@ -1327,8 +1344,9 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
       this->AddGeneratedSource(outputFile, this->Moc);
       this->AddGeneratedSource(outputFile, this->Moc);
       const std::string no_main_dependency;
       const std::string no_main_dependency;
       this->LocalGen->AddCustomCommandToOutput(
       this->LocalGen->AddCustomCommandToOutput(
-        outputFile, dependencies, no_main_dependency, commandLines,
-        autogenComment.c_str(), this->Dir.Work.c_str(),
+        { outputFile }, timestampByproducts, dependencies, no_main_dependency,
+        /*implicit_depends=*/{}, commandLines, autogenComment.c_str(),
+        this->Dir.Work.c_str(),
         /*cmp0116=*/cmPolicies::NEW, /*replace=*/false,
         /*cmp0116=*/cmPolicies::NEW, /*replace=*/false,
         /*escapeOldStyle=*/false,
         /*escapeOldStyle=*/false,
         /*uses_terminal=*/false,
         /*uses_terminal=*/false,