Przeglądaj źródła

exports: Add cmExportSetMap class

This is a map<string, cmExportSet *> with overloaded operator[] and destructor.
Yury G. Kudryashov 13 lat temu
rodzic
commit
5c898fbd99

+ 2 - 0
Source/CMakeLists.txt

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

+ 34 - 0
Source/cmExportSetMap.cxx

@@ -0,0 +1,34 @@
+/*============================================================================
+  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 "cmExportSetMap.h"
+#include "cmExportSet.h"
+
+cmExportSet* cmExportSetMap::operator[](const std::string &name)
+{
+  std::map<std::string, cmExportSet*>::iterator it = this->find(name);
+  if (it == this->end()) // Export set not found
+    {
+    it = this->insert(std::make_pair(name, new cmExportSet(name))).first;
+    }
+  return it->second;
+}
+
+cmExportSetMap::~cmExportSetMap()
+{
+  for(std::map<std::string, cmExportSet*>::iterator it = this->begin();
+      it != this->end();
+      ++ it)
+    {
+    delete it->second;
+    }
+}

+ 33 - 0
Source/cmExportSetMap.h

@@ -0,0 +1,33 @@
+/*============================================================================
+  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 cmExportSetMap_h
+#define cmExportSetMap_h
+
+#include "cmSystemTools.h"
+class cmExportSet;
+
+/// A name -> cmExportSet map with overloaded operator[].
+class cmExportSetMap : public std::map<std::string, cmExportSet*>
+{
+public:
+  /** \brief Overloaded operator[].
+   *
+   * The operator is overloaded because cmExportSet has no default constructor:
+   * we do not want unnamed export sets.
+   */
+  cmExportSet* operator[](const std::string &name);
+
+  /// Overloaded destructor deletes all member export sets.
+  ~cmExportSetMap();
+};
+
+#endif

+ 0 - 29
Source/cmGlobalGenerator.cxx

@@ -1467,35 +1467,6 @@ void cmGlobalGenerator::AddInstallComponent(const char* component)
     }
 }
 
-void cmGlobalGenerator::AddTargetToExport(const char* exportSetName,
-                                           cmTargetExport const* te)
-{
-  std::map<cmStdString, cmExportSet>::iterator it = ExportSets.find(exportSetName);
-  // If EXPORT named exportSetName does not exist, create it.
-  if (it == ExportSets.end())
-    {
-    cmStdString key = exportSetName;
-    cmExportSet value(key);
-    it = ExportSets.insert(std::make_pair(key, value)).first;
-    }
-  it->second.AddTargetExport(te);
-}
-
-//----------------------------------------------------------------------------
-
-const cmExportSet *cmGlobalGenerator::GetExportSet(const char* name) const
-{
-  std::map<cmStdString, cmExportSet >::const_iterator
-                                     exportSetIt = this->ExportSets.find(name);
-  if (exportSetIt != this->ExportSets.end())
-    {
-    return &exportSetIt->second;
-    }
-
-  return 0;
-}
-
-
 void cmGlobalGenerator::EnableInstallTarget()
 {
   this->InstallTargetEnabled = true;

+ 3 - 7
Source/cmGlobalGenerator.h

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

+ 2 - 1
Source/cmInstallCommand.cxx

@@ -18,6 +18,7 @@
 #include "cmInstallExportGenerator.h"
 #include "cmInstallCommandArguments.h"
 #include "cmTargetExport.h"
+#include "cmExportSet.h"
 
 #include <cmsys/Glob.hxx>
 
@@ -745,7 +746,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
       te->LibraryGenerator = libraryGenerator;
       te->RuntimeGenerator = runtimeGenerator;
       this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
-        ->AddTargetToExport(exports.GetCString(), te);
+        ->GetExportSets()[exports.GetString()]->AddTargetExport(te);
       }
     }
 

+ 1 - 1
Source/cmInstallExportGenerator.cxx

@@ -117,7 +117,7 @@ void cmInstallExportGenerator::GenerateScript(std::ostream& os)
   // Get the export set requested.
   cmExportSet const* exportSet =
     this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
-    ->GetExportSet(this->Name.c_str());
+    ->GetExportSets()[this->Name];
 
   // Skip empty sets.
   if(!exportSet)

+ 1 - 0
bootstrap

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