瀏覽代碼

Merge topic 'vs9-custom-command-dedup'

066f4d0f0a VS: Avoid unnecessary duplication of custom commands across targets in VS 9
8bb5c96bf8 cmLocalVisualStudio7Generator: Adopt SourcesVisited lookup table

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5206
Brad King 5 年之前
父節點
當前提交
51fc3ac972

+ 0 - 7
Source/cmLocalVisualStudio10Generator.cxx

@@ -68,13 +68,6 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
 
 void cmLocalVisualStudio10Generator::GenerateTarget(cmGeneratorTarget* target)
 {
-  auto& targetVisited = this->GetSourcesVisited(target);
-  auto& deps = this->GlobalGenerator->GetTargetDirectDepends(target);
-  for (auto& d : deps) {
-    // Take the union of visited source files of custom commands
-    auto depVisited = this->GetSourcesVisited(d);
-    targetVisited.insert(depVisited.begin(), depVisited.end());
-  }
   if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
         ->TargetIsFortranOnly(target)) {
     this->cmLocalVisualStudio7Generator::GenerateTarget(target);

+ 0 - 9
Source/cmLocalVisualStudio10Generator.h

@@ -28,19 +28,10 @@ public:
   void ReadAndStoreExternalGUID(const std::string& name,
                                 const char* path) override;
 
-  std::set<cmSourceFile const*>& GetSourcesVisited(
-    cmGeneratorTarget const* target)
-  {
-    return SourcesVisited[target];
-  };
-
 protected:
   const char* ReportErrorLabel() const override;
   bool CustomCommandUseLocal() const override { return true; }
 
 private:
   void GenerateTarget(cmGeneratorTarget* target) override;
-
-  std::map<cmGeneratorTarget const*, std::set<cmSourceFile const*>>
-    SourcesVisited;
 };

+ 15 - 1
Source/cmLocalVisualStudio7Generator.cxx

@@ -86,6 +86,15 @@ void cmLocalVisualStudio7Generator::Generate()
     if (!gt->IsInBuildSystem() || gt->GetProperty("EXTERNAL_MSPROJECT")) {
       continue;
     }
+
+    auto& gtVisited = this->GetSourcesVisited(gt);
+    auto& deps = this->GlobalGenerator->GetTargetDirectDepends(gt);
+    for (auto& d : deps) {
+      // Take the union of visited source files of custom commands
+      auto depVisited = this->GetSourcesVisited(d);
+      gtVisited.insert(depVisited.begin(), depVisited.end());
+    }
+
     this->GenerateTarget(gt);
   }
 
@@ -1615,6 +1624,8 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
     this->WriteVCProjBeginGroup(fout, name.c_str(), "");
   }
 
+  auto& sourcesVisited = this->GetSourcesVisited(target);
+
   // Loop through each source in the source group.
   for (const cmSourceFile* sf : sourceFiles) {
     std::string source = sf->GetFullPath();
@@ -1638,7 +1649,10 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
       // build it, then it will.
       fout << "\t\t\t\tRelativePath=\"" << d << "\">\n";
       if (cmCustomCommand const* command = sf->GetCustomCommand()) {
-        this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
+        if (sourcesVisited.insert(sf).second) {
+          this->WriteCustomRule(fout, configs, source.c_str(), *command,
+                                fcinfo);
+        }
       } else if (!fcinfo.FileConfigMap.empty()) {
         const char* aCompilerTool = "VCCLCompilerTool";
         std::string ppLang = "CXX";

+ 9 - 0
Source/cmLocalVisualStudio7Generator.h

@@ -83,6 +83,12 @@ public:
   virtual void ReadAndStoreExternalGUID(const std::string& name,
                                         const char* path);
 
+  std::set<cmSourceFile const*>& GetSourcesVisited(
+    cmGeneratorTarget const* target)
+  {
+    return this->SourcesVisited[target];
+  };
+
 protected:
   virtual void GenerateTarget(cmGeneratorTarget* target);
 
@@ -148,4 +154,7 @@ private:
   bool FortranProject;
   bool WindowsCEProject;
   std::unique_ptr<cmLocalVisualStudio7GeneratorInternals> Internal;
+
+  std::map<cmGeneratorTarget const*, std::set<cmSourceFile const*>>
+    SourcesVisited;
 };