Allow a GeneratorFactory handling of more than one generator

Pass the name of the requested generator to the generator factory,
which is now responsible to check if it can create a matching
generator for the name. This allows us to add more logic to the
factory in a next step, so that not every possible generator needs
to get registered explicit in cmake::AddDefaultGenerators().
This commit is contained in:
Patrick Gansterer 2012-11-19 16:13:54 +01:00 committed by Brad King
parent 984ebc3350
commit 04ff866ca8
4 changed files with 71 additions and 65 deletions

View File

@ -29,7 +29,7 @@ public:
virtual ~cmGlobalGeneratorFactory() {}
/** Create a GlobalGenerator */
virtual cmGlobalGenerator* CreateGlobalGenerator() const = 0;
virtual cmGlobalGenerator* CreateGlobalGenerator(const char* n) const = 0;
/** Get the documentation entry for this factory */
virtual void GetDocumentation(cmDocumentationEntry& entry) const = 0;
@ -43,7 +43,8 @@ class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory
{
public:
/** Create a GlobalGenerator */
virtual cmGlobalGenerator* CreateGlobalGenerator() const {
virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const {
if (strcmp(name, T::GetActualName())) return 0;
return new T; }
/** Get the documentation entry for this factory */

View File

@ -116,7 +116,7 @@ public:
class cmGlobalXCodeGenerator::Factory : public cmGlobalGeneratorFactory
{
public:
virtual cmGlobalGenerator* CreateGlobalGenerator() const;
virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const;
virtual void GetDocumentation(cmDocumentationEntry& entry) const {
cmGlobalXCodeGenerator().GetDocumentation(entry); }
@ -152,8 +152,10 @@ cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory()
//----------------------------------------------------------------------------
cmGlobalGenerator* cmGlobalXCodeGenerator::Factory
::CreateGlobalGenerator() const
::CreateGlobalGenerator(const char* name) const
{
if (strcmp(name, GetActualName()))
return 0;
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmXcodeVersionParser parser;
std::string versionFile;

View File

@ -222,10 +222,10 @@ cmake::~cmake()
{
delete (*j).second;
}
for(RegisteredGeneratorsMap::iterator j = this->Generators.begin();
for(RegisteredGeneratorsVector::iterator j = this->Generators.begin();
j != this->Generators.end(); ++j)
{
delete (*j).second;
delete *j;
}
#ifdef CMAKE_BUILD_WITH_CMAKE
delete this->VariableWatch;
@ -1874,10 +1874,10 @@ void cmake::AddDefaultExtraGenerators()
//----------------------------------------------------------------------------
void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
{
for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
for(RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
i != this->Generators.end(); ++i)
{
i->second->GetGenerators(names);
(*i)->GetGenerators(names);
}
for(RegisteredExtraGeneratorsMap::const_iterator
i = this->ExtraGenerators.begin();
@ -1899,10 +1899,14 @@ cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
}
cmGlobalGenerator* generator = 0;
RegisteredGeneratorsMap::const_iterator genIt = this->Generators.find(name);
if(genIt != this->Generators.end())
for (RegisteredGeneratorsVector::const_iterator i =
this->Generators.begin(); i != this->Generators.end(); ++i)
{
generator = genIt->second->CreateGlobalGenerator();
generator = (*i)->CreateGlobalGenerator(name);
if (generator)
{
break;
}
}
if (generator)
@ -2578,55 +2582,55 @@ void cmake::AddDefaultGenerators()
{
#if defined(_WIN32) && !defined(__CYGWIN__)
# if !defined(CMAKE_BOOT_MINGW)
this->Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
cmGlobalVisualStudio6Generator::NewFactory();
this->Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
cmGlobalVisualStudio7Generator::NewFactory();
this->Generators[cmGlobalVisualStudio10Generator::GetActualName()] =
cmGlobalVisualStudio10Generator::NewFactory();
this->Generators[cmGlobalVisualStudio10IA64Generator::GetActualName()] =
cmGlobalVisualStudio10IA64Generator::NewFactory();
this->Generators[cmGlobalVisualStudio10Win64Generator::GetActualName()] =
cmGlobalVisualStudio10Win64Generator::NewFactory();
this->Generators[cmGlobalVisualStudio11Generator::GetActualName()] =
cmGlobalVisualStudio11Generator::NewFactory();
this->Generators[cmGlobalVisualStudio11Win64Generator::GetActualName()] =
cmGlobalVisualStudio11Win64Generator::NewFactory();
this->Generators[cmGlobalVisualStudio11ARMGenerator::GetActualName()] =
cmGlobalVisualStudio11ARMGenerator::NewFactory();
this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
cmGlobalVisualStudio71Generator::NewFactory();
this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
cmGlobalVisualStudio8Generator::NewFactory();
this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] =
cmGlobalVisualStudio9Generator::NewFactory();
this->Generators[cmGlobalVisualStudio9IA64Generator::GetActualName()] =
cmGlobalVisualStudio9IA64Generator::NewFactory();
this->Generators[cmGlobalVisualStudio9Win64Generator::GetActualName()] =
cmGlobalVisualStudio9Win64Generator::NewFactory();
this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] =
cmGlobalVisualStudio8Win64Generator::NewFactory();
this->Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
cmGlobalBorlandMakefileGenerator::NewFactory();
this->Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
cmGlobalNMakeMakefileGenerator::NewFactory();
this->Generators[cmGlobalJOMMakefileGenerator::GetActualName()] =
cmGlobalJOMMakefileGenerator::NewFactory();
this->Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
cmGlobalWatcomWMakeGenerator::NewFactory();
this->Generators.push_back(
cmGlobalVisualStudio6Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio7Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio10Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio10IA64Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio10Win64Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio11Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio11Win64Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio11ARMGenerator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio71Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio8Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio9Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio9IA64Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio9Win64Generator::NewFactory());
this->Generators.push_back(
cmGlobalVisualStudio8Win64Generator::NewFactory());
this->Generators.push_back(
cmGlobalBorlandMakefileGenerator::NewFactory());
this->Generators.push_back(
cmGlobalNMakeMakefileGenerator::NewFactory());
this->Generators.push_back(
cmGlobalJOMMakefileGenerator::NewFactory());
this->Generators.push_back(
cmGlobalWatcomWMakeGenerator::NewFactory());
# endif
this->Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
cmGlobalMSYSMakefileGenerator::NewFactory();
this->Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
cmGlobalMinGWMakefileGenerator::NewFactory();
this->Generators.push_back(
cmGlobalMSYSMakefileGenerator::NewFactory());
this->Generators.push_back(
cmGlobalMinGWMakefileGenerator::NewFactory());
#endif
this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
cmGlobalUnixMakefileGenerator3::NewFactory();
this->Generators[cmGlobalNinjaGenerator::GetActualName()] =
cmGlobalNinjaGenerator::NewFactory();
this->Generators.push_back(
cmGlobalUnixMakefileGenerator3::NewFactory());
this->Generators.push_back(
cmGlobalNinjaGenerator::NewFactory());
#ifdef CMAKE_USE_XCODE
this->Generators[cmGlobalXCodeGenerator::GetActualName()] =
cmGlobalXCodeGenerator::NewFactory();
this->Generators.push_back(
cmGlobalXCodeGenerator::NewFactory());
#endif
}
@ -2720,15 +2724,15 @@ void cmake::GetPropertiesDocumentation(std::map<std::string,
void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
{
for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
i != this->Generators.end(); ++i)
for(RegisteredGeneratorsVector::const_iterator i =
this->Generators.begin(); i != this->Generators.end(); ++i)
{
cmDocumentationEntry e;
i->second->GetDocumentation(e);
(*i)->GetDocumentation(e);
v.push_back(e);
}
for(RegisteredExtraGeneratorsMap::const_iterator
i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
for(RegisteredExtraGeneratorsMap::const_iterator i =
this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
{
cmDocumentationEntry e;
cmExternalMakefileProjectGenerator* generator = (i->second)();

View File

@ -397,10 +397,9 @@ protected:
cmExternalMakefileProjectGenerator* (*CreateExtraGeneratorFunctionType)();
typedef std::map<cmStdString,
CreateExtraGeneratorFunctionType> RegisteredExtraGeneratorsMap;
typedef std::map<cmStdString,
cmGlobalGeneratorFactory*> RegisteredGeneratorsMap;
typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector;
RegisteredCommandsMap Commands;
RegisteredGeneratorsMap Generators;
RegisteredGeneratorsVector Generators;
RegisteredExtraGeneratorsMap ExtraGenerators;
void AddDefaultCommands();
void AddDefaultGenerators();