From 488723f5cd9bec3f7b35b26c89ce2d92ad7d4db4 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Wed, 16 Sep 2015 22:08:22 +0200
Subject: cmMakefile: Store container of cmExportBuildFileGenerators.

Set a cmLocalGenerator on each instance at compute time.  That will
soon be needed to access cmGeneratorTarget instances.

If a cmExportBuildFileGenerator is processed early during configure time as a
result of CMP0024 it must be removed from the list to process later at generate
time.
---
 Source/cmExportBuildFileGenerator.cxx | 21 ++++++++++++++-------
 Source/cmExportBuildFileGenerator.h   |  8 ++------
 Source/cmExportCommand.cxx            |  2 +-
 Source/cmGlobalGenerator.cxx          | 32 +++++++++++++++++++++++++++++---
 Source/cmGlobalGenerator.h            |  7 +++++--
 Source/cmIncludeCommand.cxx           |  1 +
 Source/cmMakefile.cxx                 | 23 +++++++++++++++++++++++
 Source/cmMakefile.h                   |  7 +++++++
 bootstrap                             |  1 +
 9 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index 400fa17..560cfc5 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -18,13 +18,18 @@
 
 //----------------------------------------------------------------------------
 cmExportBuildFileGenerator::cmExportBuildFileGenerator()
-  : Backtrace()
 {
-  this->Makefile = 0;
+  this->LG = 0;
   this->ExportSet = 0;
 }
 
 //----------------------------------------------------------------------------
+void cmExportBuildFileGenerator::Compute(cmLocalGenerator* lg)
+{
+  this->LG = lg;
+}
+
+//----------------------------------------------------------------------------
 bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
 {
   std::vector<cmGeneratorTarget*> allTargets;
@@ -37,7 +42,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
         tei = targets.begin();
       tei != targets.end(); ++tei)
     {
-    cmGeneratorTarget *te = this->Makefile
+    cmGeneratorTarget *te = this->LG->GetMakefile()
                                 ->FindGeneratorTargetToUse(*tei);
     expectedTargets += sep + this->Namespace + te->Target->GetExportName();
     sep = " ";
@@ -49,8 +54,9 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
       {
       std::ostringstream e;
       e << "given target \"" << te->GetName() << "\" more than once.";
-      this->Makefile->GetCMakeInstance()
-          ->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
+      this->LG->GetGlobalGenerator()->GetCMakeInstance()
+          ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                         this->LG->GetMakefile()->GetBacktrace());
       return false;
       }
     if (te->GetType() == cmTarget::INTERFACE_LIBRARY)
@@ -328,8 +334,9 @@ cmExportBuildFileGenerator
   e << "If the required target is not easy to reference in this call, "
     << "consider using the APPEND option with multiple separate calls.";
 
-  this->Makefile->GetCMakeInstance()
-      ->IssueMessage(cmake::FATAL_ERROR, e.str(), this->Backtrace);
+  this->LG->GetGlobalGenerator()->GetCMakeInstance()
+      ->IssueMessage(cmake::FATAL_ERROR, e.str(),
+                     this->LG->GetMakefile()->GetBacktrace());
 }
 
 std::string
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index ff3d2e1..16695f1 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -43,10 +43,7 @@ public:
   /** Set whether to append generated code to the output file.  */
   void SetAppendMode(bool append) { this->AppendMode = append; }
 
-  void SetMakefile(cmMakefile *mf) {
-    this->Makefile = mf;
-    this->Backtrace = this->Makefile->GetBacktrace();
-  }
+  void Compute(cmLocalGenerator* lg);
 
 protected:
   // Implement virtual methods from the superclass.
@@ -80,8 +77,7 @@ protected:
   std::vector<std::string> Targets;
   cmExportSet *ExportSet;
   std::vector<cmGeneratorTarget*> Exports;
-  cmMakefile* Makefile;
-  cmListFileBacktrace Backtrace;
+  cmLocalGenerator* LG;
 };
 
 #endif
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index 6a1d7f3..c2d9cc4 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -221,7 +221,7 @@ bool cmExportCommand
     {
     ebfg->SetTargets(targets);
     }
-  ebfg->SetMakefile(this->Makefile);
+  this->Makefile->AddExportBuildFileGenerator(ebfg);
   ebfg->SetExportOld(this->ExportOld.IsEnabled());
 
   // Compute the set of configurations exported.
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 6750611..9ac0019 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -73,7 +73,7 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm)
   this->CurrentMakefile = 0;
   this->TryCompileOuterMakefile = 0;
 
-  this->ConfigureDoneCMP0026 = false;
+  this->ConfigureDoneCMP0026AndCMP0024 = false;
 }
 
 cmGlobalGenerator::~cmGlobalGenerator()
@@ -234,6 +234,16 @@ bool cmGlobalGenerator::GenerateImportFile(const std::string &file)
   if (it != this->BuildExportSets.end())
     {
     bool result = it->second->GenerateImportFile();
+
+    if (!this->ConfigureDoneCMP0026AndCMP0024)
+      {
+      for (std::vector<cmMakefile*>::const_iterator mit =
+           this->Makefiles.begin(); mit != this->Makefiles.end(); ++mit)
+        {
+        (*mit)->RemoveExportBuildFileGeneratorCMP0024(it->second);
+        }
+      }
+
     delete it->second;
     it->second = 0;
     this->BuildExportSets.erase(it);
@@ -1122,11 +1132,11 @@ void cmGlobalGenerator::Configure()
       this->CMakeInstance->GetHomeOutputDirectory());
 
   // now do it
-  this->ConfigureDoneCMP0026 = false;
+  this->ConfigureDoneCMP0026AndCMP0024 = false;
   dirMf->Configure();
   dirMf->EnforceDirectoryLevelRules();
 
-  this->ConfigureDoneCMP0026 = true;
+  this->ConfigureDoneCMP0026AndCMP0024 = true;
 
   // Put a copy of each global target in every directory.
   cmTargets globalTargets;
@@ -1226,6 +1236,20 @@ bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
   return false;
 }
 
+void cmGlobalGenerator::ComputeBuildFileGenerators()
+{
+  for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
+    {
+    std::vector<cmExportBuildFileGenerator*> gens =
+        this->Makefiles[i]->GetExportBuildFileGenerators();
+    for (std::vector<cmExportBuildFileGenerator*>::const_iterator it =
+         gens.begin(); it != gens.end(); ++it)
+      {
+      (*it)->Compute(this->LocalGenerators[i]);
+      }
+    }
+}
+
 bool cmGlobalGenerator::Compute()
 {
   // Some generators track files replaced during the Generate.
@@ -1255,6 +1279,8 @@ bool cmGlobalGenerator::Compute()
       this->CreateQtAutoGeneratorsTargets();
 #endif
 
+  this->ComputeBuildFileGenerators();
+
   unsigned int i;
 
   // Add generator specific helper commands
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 55e3766..fc81708 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -362,7 +362,10 @@ public:
   cmFileLockPool& GetFileLockPool() { return FileLockPool; }
 #endif
 
-  bool GetConfigureDoneCMP0026() const { return this->ConfigureDoneCMP0026; }
+  bool GetConfigureDoneCMP0026() const
+  { return this->ConfigureDoneCMP0026AndCMP0024; }
+
+  void ComputeBuildFileGenerators();
 
   std::string MakeSilentFlag;
 protected:
@@ -520,7 +523,7 @@ protected:
   bool ForceUnixPaths;
   bool ToolSupportsColor;
   bool InstallTargetEnabled;
-  bool ConfigureDoneCMP0026;
+  bool ConfigureDoneCMP0026AndCMP0024;
 };
 
 #endif
diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx
index 8890e2b..97d4d56 100644
--- a/Source/cmIncludeCommand.cxx
+++ b/Source/cmIncludeCommand.cxx
@@ -126,6 +126,7 @@ bool cmIncludeCommand
         }
       }
     gg->CreateGenerationObjects();
+    gg->ComputeBuildFileGenerators();
     gg->GenerateImportFile(fname_abs);
     }
 
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 73d3522..f2f7ee7 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -702,6 +702,29 @@ cmMakefile::GetEvaluationFiles() const
   return this->EvaluationFiles;
 }
 
+std::vector<cmExportBuildFileGenerator*>
+cmMakefile::GetExportBuildFileGenerators() const
+{
+  return this->ExportBuildFileGenerators;
+}
+
+void cmMakefile::RemoveExportBuildFileGeneratorCMP0024(
+    cmExportBuildFileGenerator* gen)
+{
+  std::vector<cmExportBuildFileGenerator*>::iterator it =
+      std::find(this->ExportBuildFileGenerators.begin(),
+                this->ExportBuildFileGenerators.end(), gen);
+  if(it != this->ExportBuildFileGenerators.end())
+    {
+    this->ExportBuildFileGenerators.erase(it);
+    }
+}
+
+void cmMakefile::AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen)
+{
+  this->ExportBuildFileGenerators.push_back(gen);
+}
+
 namespace
 {
   struct file_not_persistent
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 0a8dcd5..46fdc94 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -51,6 +51,7 @@ class cmake;
 class cmMakefileCall;
 class cmCMakePolicyCommand;
 class cmGeneratorExpressionEvaluationFile;
+class cmExportBuildFileGenerator;
 
 /** \class cmMakefile
  * \brief Process the input CMakeLists.txt file.
@@ -789,6 +790,11 @@ public:
                   bool inputIsContent);
   std::vector<cmGeneratorExpressionEvaluationFile*> GetEvaluationFiles() const;
 
+  std::vector<cmExportBuildFileGenerator*>
+  GetExportBuildFileGenerators() const;
+  void RemoveExportBuildFileGeneratorCMP0024(cmExportBuildFileGenerator* gen);
+  void AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen);
+
 protected:
   // add link libraries and directories to the target
   void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
@@ -882,6 +888,7 @@ private:
   mutable cmsys::RegularExpression cmNamedCurly;
 
   std::vector<cmMakefile*> UnConfiguredDirectories;
+  std::vector<cmExportBuildFileGenerator*> ExportBuildFileGenerators;
 
   std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles;
 
diff --git a/bootstrap b/bootstrap
index ca86528..54f7ca6 100755
--- a/bootstrap
+++ b/bootstrap
@@ -261,6 +261,7 @@ CMAKE_CXX_SOURCES="\
   cmPropertyDefinitionMap \
   cmMakeDepend \
   cmMakefile \
+  cmExportBuildFileGenerator \
   cmExportFileGenerator \
   cmExportInstallFileGenerator \
   cmExportTryCompileFileGenerator \
-- 
cgit v0.12