From 5c898fbd99f6d12e8835a0dd3b229d93812e7533 Mon Sep 17 00:00:00 2001 From: "Yury G. Kudryashov" Date: Thu, 1 Mar 2012 02:02:56 +0400 Subject: [PATCH] exports: Add cmExportSetMap class This is a map with overloaded operator[] and destructor. --- Source/CMakeLists.txt | 2 ++ Source/cmExportSetMap.cxx | 34 +++++++++++++++++++++++++++++ Source/cmExportSetMap.h | 33 ++++++++++++++++++++++++++++ Source/cmGlobalGenerator.cxx | 29 ------------------------ Source/cmGlobalGenerator.h | 10 +++------ Source/cmInstallCommand.cxx | 3 ++- Source/cmInstallExportGenerator.cxx | 2 +- bootstrap | 1 + 8 files changed, 76 insertions(+), 38 deletions(-) create mode 100644 Source/cmExportSetMap.cxx create mode 100644 Source/cmExportSetMap.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index e04b7c9b1..186aa6db6 100644 --- a/Source/CMakeLists.txt +++ b/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 diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx new file mode 100644 index 000000000..96fdb3e4f --- /dev/null +++ b/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::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::iterator it = this->begin(); + it != this->end(); + ++ it) + { + delete it->second; + } +} diff --git a/Source/cmExportSetMap.h b/Source/cmExportSetMap.h new file mode 100644 index 000000000..4663c5538 --- /dev/null +++ b/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 +{ +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 diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 5640af94a..e464381e3 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1467,35 +1467,6 @@ void cmGlobalGenerator::AddInstallComponent(const char* component) } } -void cmGlobalGenerator::AddTargetToExport(const char* exportSetName, - cmTargetExport const* te) -{ - std::map::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::const_iterator - exportSetIt = this->ExportSets.find(name); - if (exportSetIt != this->ExportSets.end()) - { - return &exportSetIt->second; - } - - return 0; -} - - void cmGlobalGenerator::EnableInstallTarget() { this->InstallTargetEnabled = true; diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 568e138aa..71c3a4d80 100644 --- a/Source/cmGlobalGenerator.h +++ b/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* 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 InstallComponents; bool InstallTargetEnabled; // Sets of named target exports - std::map ExportSets; + cmExportSetMap ExportSets; // Manifest of all targets that will be built for each configuration. // This is computed just before local generators generate. diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 62fc2ef3b..6eaa1035d 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -18,6 +18,7 @@ #include "cmInstallExportGenerator.h" #include "cmInstallCommandArguments.h" #include "cmTargetExport.h" +#include "cmExportSet.h" #include @@ -745,7 +746,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) te->LibraryGenerator = libraryGenerator; te->RuntimeGenerator = runtimeGenerator; this->Makefile->GetLocalGenerator()->GetGlobalGenerator() - ->AddTargetToExport(exports.GetCString(), te); + ->GetExportSets()[exports.GetString()]->AddTargetExport(te); } } diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index a9cd3fe12..0179cd148 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/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) diff --git a/bootstrap b/bootstrap index a9e8a86f0..d51d80f81 100755 --- a/bootstrap +++ b/bootstrap @@ -200,6 +200,7 @@ CMAKE_CXX_SOURCES="\ cmExportFileGenerator \ cmExportInstallFileGenerator \ cmExportSet \ + cmExportSetMap \ cmInstallDirectoryGenerator \ cmGeneratedFileStream \ cmGeneratorTarget \