exports: Create class cmExportSet

Replace direct use of 'std::vector<cmTargetExport const*>' with a
dedicated class.
This commit is contained in:
Yury G. Kudryashov 2012-02-27 10:09:40 +04:00 committed by Brad King
parent 4e2347cbf3
commit d13ec1ac31
10 changed files with 103 additions and 43 deletions

View File

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

View File

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

View File

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

27
Source/cmExportSet.cxx Normal file
View File

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

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

View File

@ -76,12 +76,13 @@ cmGlobalGenerator::~cmGlobalGenerator()
} }
this->ClearGeneratorTargets(); this->ClearGeneratorTargets();
this->ClearExportSets(); this->ExportSets.clear();
} }
void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang, void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
cmMakefile *mf, cmMakefile *mf,
bool optional) { bool optional)
{
std::string langComp = "CMAKE_"; std::string langComp = "CMAKE_";
langComp += lang; langComp += lang;
langComp += "_COMPILER"; langComp += "_COMPILER";
@ -817,7 +818,7 @@ void cmGlobalGenerator::Configure()
{ {
this->FirstTimeProgress = 0.0f; this->FirstTimeProgress = 0.0f;
this->ClearGeneratorTargets(); this->ClearGeneratorTargets();
this->ClearExportSets(); this->ExportSets.clear();
// Delete any existing cmLocalGenerators // Delete any existing cmLocalGenerators
unsigned int i; unsigned int i;
for (i = 0; i < this->LocalGenerators.size(); ++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, 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 cmExportSet *cmGlobalGenerator::GetExportSet(const char* name) const
const char* name) const
{ {
std::map<cmStdString, std::vector<cmTargetExport*> >::const_iterator std::map<cmStdString, cmExportSet >::const_iterator
exportSetIt = this->ExportSets.find(name); exportSetIt = this->ExportSets.find(name);
if (exportSetIt != this->ExportSets.end()) if (exportSetIt != this->ExportSets.end())
{ {

View File

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

View File

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

View File

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

View File

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