Browse Source

exports: Create class cmExportSet

Replace direct use of 'std::vector<cmTargetExport const*>' with a
dedicated class.
Yury G. Kudryashov 13 years ago
parent
commit
d13ec1ac31

+ 2 - 0
Source/CMakeLists.txt

@@ -176,6 +176,8 @@ set(SRCS
   cmExportFileGenerator.cxx
   cmExportInstallFileGenerator.h
   cmExportInstallFileGenerator.cxx
+  cmExportSet.h
+  cmExportSet.cxx
   cmExtraCodeBlocksGenerator.cxx
   cmExtraCodeBlocksGenerator.h
   cmExtraEclipseCDT4Generator.cxx

+ 9 - 8
Source/cmExportInstallFileGenerator.cxx

@@ -15,6 +15,7 @@
 #include "cmInstallExportGenerator.h"
 #include "cmInstallTargetGenerator.h"
 #include "cmTargetExport.h"
+#include "cmExportSet.h"
 
 //----------------------------------------------------------------------------
 cmExportInstallFileGenerator
@@ -36,11 +37,11 @@ std::string cmExportInstallFileGenerator::GetConfigImportFileGlob()
 bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
 {
   // Create all the imported targets.
-  for(std::vector<cmTargetExport*>::const_iterator
-        tei = this->ExportSet->begin();
-      tei != this->ExportSet->end(); ++tei)
+  for(std::vector<cmTargetExport const*>::const_iterator
+        tei = this->ExportSet->GetTargetExports()->begin();
+      tei != this->ExportSet->GetTargetExports()->end(); ++tei)
     {
-    cmTargetExport* te = *tei;
+    cmTargetExport const* te = *tei;
     if(this->ExportedTargets.insert(te->Target).second)
       {
       this->GenerateImportTargetCode(os, te->Target);
@@ -161,12 +162,12 @@ cmExportInstallFileGenerator
     }
 
   // Add each target in the set to the export.
-  for(std::vector<cmTargetExport*>::const_iterator
-        tei = this->ExportSet->begin();
-      tei != this->ExportSet->end(); ++tei)
+  for(std::vector<cmTargetExport const*>::const_iterator
+        tei = this->ExportSet->GetTargetExports()->begin();
+      tei != this->ExportSet->GetTargetExports()->end(); ++tei)
     {
     // Collect import properties for this target.
-    cmTargetExport* te = *tei;
+    cmTargetExport const* te = *tei;
     ImportPropertyMap properties;
     std::set<std::string> importedLocations;
     this->SetImportLocationProperty(config, suffix, te->ArchiveGenerator,

+ 3 - 2
Source/cmExportInstallFileGenerator.h

@@ -18,6 +18,7 @@ class cmInstallExportGenerator;
 class cmInstallFilesGenerator;
 class cmInstallTargetGenerator;
 class cmTargetExport;
+class cmExportSet;
 
 /** \class cmExportInstallFileGenerator
  * \brief Generate a file exporting targets from an install tree.
@@ -46,7 +47,7 @@ public:
 
   /** Set the set of targets to be exported.  These are the targets
       associated with the export name.  */
-  void SetExportSet(std::vector<cmTargetExport*> const* eSet)
+  void SetExportSet(cmExportSet const* eSet)
     { this->ExportSet = eSet; }
 
   /** Get the per-config file generated for each configuraiton.  This
@@ -83,7 +84,7 @@ protected:
 
   cmInstallExportGenerator* InstallExportGenerator;
   std::string Name;
-  std::vector<cmTargetExport*> const* ExportSet;
+  cmExportSet const* ExportSet;
 
   std::string ImportPrefix;
 

+ 27 - 0
Source/cmExportSet.cxx

@@ -0,0 +1,27 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
+#include "cmExportSet.h"
+#include "cmTargetExport.h"
+
+cmExportSet::~cmExportSet()
+{
+  for(unsigned int i = 0; i < this->TargetExports.size(); ++ i)
+    {
+    delete this->TargetExports[i];
+    }
+}
+
+void cmExportSet::AddTargetExport(cmTargetExport const* te)
+{
+  this->TargetExports.push_back(te);
+}

+ 38 - 0
Source/cmExportSet.h

@@ -0,0 +1,38 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+#ifndef cmExportSet_h
+#define cmExportSet_h
+
+#include "cmSystemTools.h"
+class cmTargetExport;
+
+/// A set of targets that were installed with the same EXPORT parameter.
+class cmExportSet
+{
+public:
+  /// Construct an empty export set named \a name
+  cmExportSet(const std::string &name) : Name(name) {}
+  /// Destructor
+  ~cmExportSet();
+
+  void AddTargetExport(cmTargetExport const* tgt);
+
+  std::string const& GetName() const { return this->Name; }
+  std::vector<cmTargetExport const*> const* GetTargetExports() const
+     { return &this->TargetExports; }
+
+private:
+  std::vector<cmTargetExport const*> TargetExports;
+  std::string Name;
+};
+
+#endif

+ 14 - 22
Source/cmGlobalGenerator.cxx

@@ -76,12 +76,13 @@ cmGlobalGenerator::~cmGlobalGenerator()
     }
 
   this->ClearGeneratorTargets();
-  this->ClearExportSets();
+  this->ExportSets.clear();
 }
 
 void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
                                                 cmMakefile *mf,
-                                                bool optional) {
+                                                bool optional)
+{
   std::string langComp = "CMAKE_";
   langComp += lang;
   langComp += "_COMPILER";
@@ -817,7 +818,7 @@ void cmGlobalGenerator::Configure()
 {
   this->FirstTimeProgress = 0.0f;
   this->ClearGeneratorTargets();
-  this->ClearExportSets();
+  this->ExportSets.clear();
   // Delete any existing cmLocalGenerators
   unsigned int i;
   for (i = 0; i < this->LocalGenerators.size(); ++i)
@@ -1467,33 +1468,24 @@ void cmGlobalGenerator::AddInstallComponent(const char* component)
 }
 
 void cmGlobalGenerator::AddTargetToExport(const char* exportSetName,
-                                           cmTargetExport *te)
+                                           cmTargetExport const* te)
 {
-  if ((exportSetName) && (*exportSetName) && (te))
+  std::map<cmStdString, cmExportSet>::iterator it = ExportSets.find(exportSetName);
+  // If EXPORT named exportSetName does not exist, create it.
+  if (it == ExportSets.end())
     {
-    this->ExportSets[exportSetName].push_back(te);
+    cmStdString key = exportSetName;
+    cmExportSet value(key);
+    it = ExportSets.insert(std::make_pair(key, value)).first;
     }
+  it->second.AddTargetExport(te);
 }
 
 //----------------------------------------------------------------------------
-void cmGlobalGenerator::ClearExportSets()
-{
-  for(std::map<cmStdString, std::vector<cmTargetExport*> >::iterator
-        setIt = this->ExportSets.begin();
-      setIt != this->ExportSets.end(); ++setIt)
-    {
-    for(unsigned int i = 0; i < setIt->second.size(); ++i)
-      {
-      delete setIt->second[i];
-      }
-    }
-  this->ExportSets.clear();
-}
 
-const std::vector<cmTargetExport*>* cmGlobalGenerator::GetExportSet(
-                                                        const char* name) const
+const cmExportSet *cmGlobalGenerator::GetExportSet(const char* name) const
 {
-  std::map<cmStdString, std::vector<cmTargetExport*> >::const_iterator
+  std::map<cmStdString, cmExportSet >::const_iterator
                                      exportSetIt = this->ExportSets.find(name);
   if (exportSetIt != this->ExportSets.end())
     {

+ 4 - 4
Source/cmGlobalGenerator.h

@@ -18,6 +18,7 @@
 #include "cmTarget.h" // For cmTargets
 #include "cmTargetDepend.h" // For cmTargetDependSet
 #include "cmSystemTools.h" // for cmSystemTools::OutputOption
+#include "cmExportSet.h" // For cmExportSet
 class cmake;
 class cmGeneratorTarget;
 class cmMakefile;
@@ -154,9 +155,9 @@ public:
     { return &this->InstallComponents; }
 
   ///! Add one installed target to the sets of the exports
-  void AddTargetToExport(const char* exportSet, cmTargetExport* te);
+  void AddTargetToExport(const char* exportSet, cmTargetExport const* te);
   ///! Get the export target set with the   given name
-  const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
+  const cmExportSet *GetExportSet(const char* name) const;
 
   /** Add a file to the manifest of generated targets for a configuration.  */
   void AddToManifest(const char* config, std::string const& f);
@@ -328,8 +329,7 @@ protected:
   std::set<cmStdString> InstallComponents;
   bool InstallTargetEnabled;
   // Sets of named target exports
-  std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
-  void ClearExportSets();
+  std::map<cmStdString, cmExportSet> ExportSets;
 
   // Manifest of all targets that will be built for each configuration.
   // This is computed just before local generators generate.

+ 2 - 1
Source/cmInstallExportGenerator.cxx

@@ -23,6 +23,7 @@
 #include "cmInstallFilesGenerator.h"
 
 #include "cmExportInstallFileGenerator.h"
+#include "cmExportSet.h"
 
 //----------------------------------------------------------------------------
 cmInstallExportGenerator::cmInstallExportGenerator(
@@ -114,7 +115,7 @@ void cmInstallExportGenerator::ComputeTempDir()
 void cmInstallExportGenerator::GenerateScript(std::ostream& os)
 {
   // Get the export set requested.
-  ExportSet const* exportSet =
+  cmExportSet const* exportSet =
     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
     ->GetExportSet(this->Name.c_str());
 

+ 3 - 6
Source/cmInstallExportGenerator.h

@@ -17,8 +17,7 @@
 class cmExportInstallFileGenerator;
 class cmInstallFilesGenerator;
 class cmInstallTargetGenerator;
-class cmTarget;
-class cmTargetExport;
+class cmExportSet;
 class cmMakefile;
 
 /** \class cmInstallExportGenerator
@@ -35,13 +34,11 @@ public:
                            cmMakefile* mf);
   ~cmInstallExportGenerator();
 protected:
-  typedef std::vector<cmTargetExport*> ExportSet;
-
   virtual void GenerateScript(std::ostream& os);
   virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
   virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
-  void GenerateImportFile(ExportSet const* exportSet);
-  void GenerateImportFile(const char* config, ExportSet const* exportSet);
+  void GenerateImportFile(cmExportSet const* exportSet);
+  void GenerateImportFile(const char* config, cmExportSet const* exportSet);
   void ComputeTempDir();
 
   std::string Name;

+ 1 - 0
bootstrap

@@ -199,6 +199,7 @@ CMAKE_CXX_SOURCES="\
   cmMakefile \
   cmExportFileGenerator \
   cmExportInstallFileGenerator \
+  cmExportSet \
   cmInstallDirectoryGenerator \
   cmGeneratedFileStream \
   cmGeneratorTarget \