exports: Add cmExportSetMap class

This is a map<string, cmExportSet *> with overloaded operator[] and destructor.
This commit is contained in:
Yury G. Kudryashov 2012-03-01 02:02:56 +04:00 committed by Brad King
parent d13ec1ac31
commit 5c898fbd99
8 changed files with 76 additions and 38 deletions

View File

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

34
Source/cmExportSetMap.cxx Normal file
View File

@ -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
Source/cmExportSetMap.h Normal file
View File

@ -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

View File

@ -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;

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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)

View File

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