Browse Source

Multi-Ninja: Fix PCHs for Visual C++

Fixes: #20711
Cristian Adam 5 years ago
parent
commit
f6cb1e646c

+ 3 - 0
Help/prop_sf/OBJECT_OUTPUTS.rst

@@ -7,3 +7,6 @@ Additional outputs created by compilation of this source file.  If any
 of these outputs is missing the object will be recompiled.  This is
 of these outputs is missing the object will be recompiled.  This is
 supported only on the :generator:`Ninja` and :ref:`Makefile Generators`
 supported only on the :generator:`Ninja` and :ref:`Makefile Generators`
 and will be ignored on other generators.
 and will be ignored on other generators.
+
+This property supports
+:manual:`generator expressions <cmake-generator-expressions(7)>`.

+ 4 - 0
Help/release/dev/genex-OBJECT_OUTPUTS.rst

@@ -0,0 +1,4 @@
+genex-OBJECT_OUTPUTS
+--------------------
+
+* :prop_sf:`OBJECT_OUTPUTS` now support :manual:`generator expressions <cmake-generator-expressions(7)>`.

+ 4 - 0
Source/cmGeneratorTarget.cxx

@@ -3864,6 +3864,10 @@ std::string cmGeneratorTarget::GetPchFileObject(const std::string& config,
       pchSource, false, cmSourceFileLocationKind::Known);
       pchSource, false, cmSourceFileLocationKind::Known);
 
 
     filename = cmStrCat(this->ObjectDirectory, this->GetObjectName(pchSf));
     filename = cmStrCat(this->ObjectDirectory, this->GetObjectName(pchSf));
+    if (this->GetGlobalGenerator()->IsMultiConfig()) {
+      cmSystemTools::ReplaceString(
+        filename, this->GetGlobalGenerator()->GetCMakeCFGIntDir(), config);
+    }
   }
   }
   return inserted.first->second;
   return inserted.first->second;
 }
 }

+ 3 - 1
Source/cmLocalGenerator.cxx

@@ -2633,7 +2633,9 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
           // Exclude the pch files from linking
           // Exclude the pch files from linking
           if (this->Makefile->IsOn("CMAKE_LINK_PCH")) {
           if (this->Makefile->IsOn("CMAKE_LINK_PCH")) {
             if (!ReuseFrom) {
             if (!ReuseFrom) {
-              pch_sf->SetProperty("OBJECT_OUTPUTS", pchFile.c_str());
+              pch_sf->AppendProperty(
+                "OBJECT_OUTPUTS",
+                cmStrCat("$<$<CONFIG:", config, ">:", pchFile, ">"));
             } else {
             } else {
               auto reuseTarget =
               auto reuseTarget =
                 this->GlobalGenerator->FindGeneratorTarget(*ReuseFrom);
                 this->GlobalGenerator->FindGeneratorTarget(*ReuseFrom);

+ 8 - 3
Source/cmMakefileTargetGenerator.cxx

@@ -895,9 +895,14 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
   // Check for extra outputs created by the compilation.
   // Check for extra outputs created by the compilation.
   std::vector<std::string> outputs(1, relativeObj);
   std::vector<std::string> outputs(1, relativeObj);
   if (cmProp extra_outputs_str = source.GetProperty("OBJECT_OUTPUTS")) {
   if (cmProp extra_outputs_str = source.GetProperty("OBJECT_OUTPUTS")) {
-    // Register these as extra files to clean.
-    cmExpandList(*extra_outputs_str, outputs);
-    this->CleanFiles.insert(outputs.begin() + 1, outputs.end());
+    std::string evaluated_outputs = cmGeneratorExpression::Evaluate(
+      *extra_outputs_str, this->LocalGenerator, config);
+
+    if (!evaluated_outputs.empty()) {
+      // Register these as extra files to clean.
+      cmExpandList(evaluated_outputs, outputs);
+      this->CleanFiles.insert(outputs.begin() + 1, outputs.end());
+    }
   }
   }
 
 
   // Write the rule.
   // Write the rule.

+ 13 - 8
Source/cmNinjaTargetGenerator.cxx

@@ -1266,14 +1266,19 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
   }
   }
 
 
   if (cmProp objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
   if (cmProp objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
-    cmNinjaBuild build("phony");
-    build.Comment = "Additional output files.";
-    build.Outputs = cmExpandedList(*objectOutputs);
-    std::transform(build.Outputs.begin(), build.Outputs.end(),
-                   build.Outputs.begin(), MapToNinjaPath());
-    build.ExplicitDeps = objBuild.Outputs;
-    this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
-                                           build);
+    std::string evaluatedObjectOutputs = cmGeneratorExpression::Evaluate(
+      *objectOutputs, this->LocalGenerator, config);
+
+    if (!evaluatedObjectOutputs.empty()) {
+      cmNinjaBuild build("phony");
+      build.Comment = "Additional output files.";
+      build.Outputs = cmExpandedList(evaluatedObjectOutputs);
+      std::transform(build.Outputs.begin(), build.Outputs.end(),
+                     build.Outputs.begin(), MapToNinjaPath());
+      build.ExplicitDeps = objBuild.Outputs;
+      this->GetGlobalGenerator()->WriteBuild(
+        this->GetImplFileStream(fileConfig), build);
+    }
   }
   }
 }
 }