Refactor extra generator registration to use factories

This will allow additional information about the availability
and capabilities of extra generators to be queried without
actually creating them.

Instead of a static NewFactory() method like the main generator
factories have, use a static GetFactory() method to get a pointer to a
statically allocated extra generator factory.  This simplifies memory
management.
This commit is contained in:
Tobias Hunger 2016-07-20 18:28:39 +02:00 committed by Brad King
parent fd59f9ad51
commit a354f60ce0
16 changed files with 282 additions and 241 deletions

View File

@ -33,28 +33,37 @@ std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
return fullName; return fullName;
} }
std::string cmExternalMakefileProjectGenerator::GetGlobalGeneratorName( cmExternalMakefileProjectGeneratorFactory::
const std::string& fullName) cmExternalMakefileProjectGeneratorFactory(const std::string& n,
const std::string& doc)
: Name(n)
, Documentation(doc)
{ {
// at least one global generator must be supported }
assert(!this->SupportedGlobalGenerators.empty());
cmExternalMakefileProjectGeneratorFactory::
if (fullName.empty()) { ~cmExternalMakefileProjectGeneratorFactory()
return ""; {
} }
// if we get only the short name, take the first global generator as default std::string cmExternalMakefileProjectGeneratorFactory::GetName() const
if (fullName == this->GetName()) { {
return this->SupportedGlobalGenerators[0]; return this->Name;
} }
// otherwise search for the matching global generator std::string cmExternalMakefileProjectGeneratorFactory::GetDocumentation() const
for (std::vector<std::string>::const_iterator it = {
this->SupportedGlobalGenerators.begin(); return this->Documentation;
it != this->SupportedGlobalGenerators.end(); ++it) { }
if (this->CreateFullGeneratorName(*it, this->GetName()) == fullName) {
return *it; std::vector<std::string>
} cmExternalMakefileProjectGeneratorFactory::GetSupportedGlobalGenerators() const
} {
return ""; return this->SupportedGlobalGenerators;
}
void cmExternalMakefileProjectGeneratorFactory::AddSupportedGlobalGenerator(
const std::string& base)
{
this->SupportedGlobalGenerators.push_back(base);
} }

View File

@ -35,11 +35,6 @@ class cmExternalMakefileProjectGenerator
public: public:
virtual ~cmExternalMakefileProjectGenerator() {} virtual ~cmExternalMakefileProjectGenerator() {}
///! Get the name for this generator.
virtual std::string GetName() const = 0;
/** Get the documentation entry for this generator. */
virtual void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const = 0;
virtual void EnableLanguage(std::vector<std::string> const& languages, virtual void EnableLanguage(std::vector<std::string> const& languages,
cmMakefile*, bool optional); cmMakefile*, bool optional);
@ -55,8 +50,6 @@ public:
return this->SupportedGlobalGenerators; return this->SupportedGlobalGenerators;
} }
///! Get the name of the global generator for the given full name
std::string GetGlobalGeneratorName(const std::string& fullName);
/** Create a full name from the given global generator name and the /** Create a full name from the given global generator name and the
* extra generator name * extra generator name
*/ */
@ -66,11 +59,59 @@ public:
///! Generate the project files, the Makefiles have already been generated ///! Generate the project files, the Makefiles have already been generated
virtual void Generate() = 0; virtual void Generate() = 0;
void SetName(const std::string& n) { Name = n; }
std::string GetName() const { return Name; }
protected: protected:
///! Contains the names of the global generators support by this generator. ///! Contains the names of the global generators support by this generator.
std::vector<std::string> SupportedGlobalGenerators; std::vector<std::string> SupportedGlobalGenerators;
///! the global generator which creates the makefiles ///! the global generator which creates the makefiles
const cmGlobalGenerator* GlobalGenerator; const cmGlobalGenerator* GlobalGenerator;
std::string Name;
};
class cmExternalMakefileProjectGeneratorFactory
{
public:
cmExternalMakefileProjectGeneratorFactory(const std::string& n,
const std::string& doc);
virtual ~cmExternalMakefileProjectGeneratorFactory();
std::string GetName() const;
std::string GetDocumentation() const;
std::vector<std::string> GetSupportedGlobalGenerators() const;
std::vector<std::string> Aliases;
virtual cmExternalMakefileProjectGenerator*
CreateExternalMakefileProjectGenerator() const = 0;
void AddSupportedGlobalGenerator(const std::string& base);
private:
std::string Name;
std::string Documentation;
std::vector<std::string> SupportedGlobalGenerators;
};
template <class T>
class cmExternalMakefileProjectGeneratorSimpleFactory
: public cmExternalMakefileProjectGeneratorFactory
{
public:
cmExternalMakefileProjectGeneratorSimpleFactory(const std::string& n,
const std::string& doc)
: cmExternalMakefileProjectGeneratorFactory(n, doc)
{
}
cmExternalMakefileProjectGenerator* CreateExternalMakefileProjectGenerator()
const
{
T* p = new T;
p->SetName(GetName());
return p;
}
}; };
#endif #endif

View File

@ -36,24 +36,30 @@ Discussion:
http://forums.codeblocks.org/index.php/topic,6789.0.html http://forums.codeblocks.org/index.php/topic,6789.0.html
*/ */
void cmExtraCodeBlocksGenerator::GetDocumentation(cmDocumentationEntry& entry,
const std::string&) const
{
entry.Name = this->GetName();
entry.Brief = "Generates CodeBlocks project files.";
}
cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator() cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator()
: cmExternalMakefileProjectGenerator() : cmExternalMakefileProjectGenerator()
{ {
}
cmExternalMakefileProjectGeneratorFactory*
cmExtraCodeBlocksGenerator::GetFactory()
{
static cmExternalMakefileProjectGeneratorSimpleFactory<
cmExtraCodeBlocksGenerator>
factory("CodeBlocks", "Generates CodeBlocks project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
#if defined(_WIN32) #if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("MinGW Makefiles"); factory.AddSupportedGlobalGenerator("MinGW Makefiles");
this->SupportedGlobalGenerators.push_back("NMake Makefiles"); factory.AddSupportedGlobalGenerator("NMake Makefiles");
// disable until somebody actually tests it: // disable until somebody actually tests it:
// this->SupportedGlobalGenerators.push_back("MSYS Makefiles"); // this->AddSupportedGlobalGenerator("MSYS Makefiles");
#endif #endif
this->SupportedGlobalGenerators.push_back("Ninja"); factory.AddSupportedGlobalGenerator("Ninja");
this->SupportedGlobalGenerators.push_back("Unix Makefiles"); factory.AddSupportedGlobalGenerator("Unix Makefiles");
}
return &factory;
} }
void cmExtraCodeBlocksGenerator::Generate() void cmExtraCodeBlocksGenerator::Generate()

View File

@ -28,18 +28,7 @@ class cmExtraCodeBlocksGenerator : public cmExternalMakefileProjectGenerator
public: public:
cmExtraCodeBlocksGenerator(); cmExtraCodeBlocksGenerator();
std::string GetName() const CM_OVERRIDE static cmExternalMakefileProjectGeneratorFactory* GetFactory();
{
return cmExtraCodeBlocksGenerator::GetActualName();
}
static std::string GetActualName() { return "CodeBlocks"; }
static cmExternalMakefileProjectGenerator* New()
{
return new cmExtraCodeBlocksGenerator;
}
/** Get the documentation entry for this generator. */
void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const CM_OVERRIDE;
void Generate() CM_OVERRIDE; void Generate() CM_OVERRIDE;

View File

@ -27,24 +27,30 @@
#include <cmsys/SystemInformation.hxx> #include <cmsys/SystemInformation.hxx>
#include <cmsys/SystemTools.hxx> #include <cmsys/SystemTools.hxx>
void cmExtraCodeLiteGenerator::GetDocumentation(cmDocumentationEntry& entry,
const std::string&) const
{
entry.Name = this->GetName();
entry.Brief = "Generates CodeLite project files.";
}
cmExtraCodeLiteGenerator::cmExtraCodeLiteGenerator() cmExtraCodeLiteGenerator::cmExtraCodeLiteGenerator()
: cmExternalMakefileProjectGenerator() : cmExternalMakefileProjectGenerator()
, ConfigName("NoConfig") , ConfigName("NoConfig")
, CpuCount(2) , CpuCount(2)
{ {
}
cmExternalMakefileProjectGeneratorFactory*
cmExtraCodeLiteGenerator::GetFactory()
{
static cmExternalMakefileProjectGeneratorSimpleFactory<
cmExtraCodeLiteGenerator>
factory("CodeLite", "Generates CodeLite project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
#if defined(_WIN32) #if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("MinGW Makefiles"); factory.AddSupportedGlobalGenerator("MinGW Makefiles");
this->SupportedGlobalGenerators.push_back("NMake Makefiles"); factory.AddSupportedGlobalGenerator("NMake Makefiles");
#endif #endif
this->SupportedGlobalGenerators.push_back("Ninja"); factory.AddSupportedGlobalGenerator("Ninja");
this->SupportedGlobalGenerators.push_back("Unix Makefiles"); factory.AddSupportedGlobalGenerator("Unix Makefiles");
}
return &factory;
} }
void cmExtraCodeLiteGenerator::Generate() void cmExtraCodeLiteGenerator::Generate()

View File

@ -36,18 +36,7 @@ protected:
public: public:
cmExtraCodeLiteGenerator(); cmExtraCodeLiteGenerator();
std::string GetName() const CM_OVERRIDE static cmExternalMakefileProjectGeneratorFactory* GetFactory();
{
return cmExtraCodeLiteGenerator::GetActualName();
}
static std::string GetActualName() { return "CodeLite"; }
static cmExternalMakefileProjectGenerator* New()
{
return new cmExtraCodeLiteGenerator;
}
/** Get the documentation entry for this generator. */
void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const CM_OVERRIDE;
void Generate() CM_OVERRIDE; void Generate() CM_OVERRIDE;
void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs); void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);

View File

@ -46,16 +46,6 @@ void AppendDictionary(cmXMLWriter& xml, const char* key, T const& value)
cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator() cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator()
: cmExternalMakefileProjectGenerator() : cmExternalMakefileProjectGenerator()
{ {
// TODO: Verify if __CYGWIN__ should be checked.
//#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("NMake Makefiles");
this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
#endif
this->SupportedGlobalGenerators.push_back("Ninja");
this->SupportedGlobalGenerators.push_back("Unix Makefiles");
this->SupportsVirtualFolders = true; this->SupportsVirtualFolders = true;
this->GenerateLinkedResources = true; this->GenerateLinkedResources = true;
this->SupportsGmakeErrorParser = true; this->SupportsGmakeErrorParser = true;
@ -64,11 +54,26 @@ cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator()
this->CXXEnabled = false; this->CXXEnabled = false;
} }
void cmExtraEclipseCDT4Generator::GetDocumentation(cmDocumentationEntry& entry, cmExternalMakefileProjectGeneratorFactory*
const std::string&) const cmExtraEclipseCDT4Generator::GetFactory()
{ {
entry.Name = this->GetName(); static cmExternalMakefileProjectGeneratorSimpleFactory<
entry.Brief = "Generates Eclipse CDT 4.0 project files."; cmExtraEclipseCDT4Generator>
factory("Eclipse CDT4", "Generates Eclipse CDT 4.0 project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
// TODO: Verify if __CYGWIN__ should be checked.
//#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_WIN32)
factory.AddSupportedGlobalGenerator("NMake Makefiles");
factory.AddSupportedGlobalGenerator("MinGW Makefiles");
// factory.AddSupportedGlobalGenerator("MSYS Makefiles");
#endif
factory.AddSupportedGlobalGenerator("Ninja");
factory.AddSupportedGlobalGenerator("Unix Makefiles");
}
return &factory;
} }
void cmExtraEclipseCDT4Generator::EnableLanguage( void cmExtraEclipseCDT4Generator::EnableLanguage(

View File

@ -35,20 +35,8 @@ public:
cmExtraEclipseCDT4Generator(); cmExtraEclipseCDT4Generator();
static cmExternalMakefileProjectGenerator* New() static cmExternalMakefileProjectGeneratorFactory* GetFactory();
{
return new cmExtraEclipseCDT4Generator;
}
std::string GetName() const CM_OVERRIDE
{
return cmExtraEclipseCDT4Generator::GetActualName();
}
static std::string GetActualName() { return "Eclipse CDT4"; }
void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const CM_OVERRIDE;
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*, void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
bool optional) CM_OVERRIDE; bool optional) CM_OVERRIDE;

View File

@ -22,24 +22,28 @@
#include <cmsys/SystemTools.hxx> #include <cmsys/SystemTools.hxx>
void cmExtraKateGenerator::GetDocumentation(cmDocumentationEntry& entry,
const std::string&) const
{
entry.Name = this->GetName();
entry.Brief = "Generates Kate project files.";
}
cmExtraKateGenerator::cmExtraKateGenerator() cmExtraKateGenerator::cmExtraKateGenerator()
: cmExternalMakefileProjectGenerator() : cmExternalMakefileProjectGenerator()
{ {
}
cmExternalMakefileProjectGeneratorFactory* cmExtraKateGenerator::GetFactory()
{
static cmExternalMakefileProjectGeneratorSimpleFactory<cmExtraKateGenerator>
factory("Kate", "Generates Kate project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
#if defined(_WIN32) #if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("MinGW Makefiles"); factory.AddSupportedGlobalGenerator("MinGW Makefiles");
this->SupportedGlobalGenerators.push_back("NMake Makefiles"); factory.AddSupportedGlobalGenerator("NMake Makefiles");
// disable until somebody actually tests it: // disable until somebody actually tests it:
// this->SupportedGlobalGenerators.push_back("MSYS Makefiles"); // factory.AddSupportedGlobalGenerator("MSYS Makefiles");
#endif #endif
this->SupportedGlobalGenerators.push_back("Ninja"); factory.AddSupportedGlobalGenerator("Ninja");
this->SupportedGlobalGenerators.push_back("Unix Makefiles"); factory.AddSupportedGlobalGenerator("Unix Makefiles");
}
return &factory;
} }
void cmExtraKateGenerator::Generate() void cmExtraKateGenerator::Generate()

View File

@ -26,18 +26,7 @@ class cmExtraKateGenerator : public cmExternalMakefileProjectGenerator
public: public:
cmExtraKateGenerator(); cmExtraKateGenerator();
std::string GetName() const CM_OVERRIDE static cmExternalMakefileProjectGeneratorFactory* GetFactory();
{
return cmExtraKateGenerator::GetActualName();
}
static std::string GetActualName() { return "Kate"; }
static cmExternalMakefileProjectGenerator* New()
{
return new cmExtraKateGenerator;
}
/** Get the documentation entry for this generator. */
void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const CM_OVERRIDE;
void Generate() CM_OVERRIDE; void Generate() CM_OVERRIDE;

View File

@ -38,24 +38,30 @@ http://www.sublimetext.com/docs/2/projects.html
http://sublimetext.info/docs/en/reference/build_systems.html http://sublimetext.info/docs/en/reference/build_systems.html
*/ */
void cmExtraSublimeTextGenerator::GetDocumentation(cmDocumentationEntry& entry, cmExternalMakefileProjectGeneratorFactory*
const std::string&) const cmExtraSublimeTextGenerator::GetFactory()
{ {
entry.Name = this->GetName(); static cmExternalMakefileProjectGeneratorSimpleFactory<
entry.Brief = "Generates Sublime Text 2 project files."; cmExtraSublimeTextGenerator>
factory("Sublime Text 2", "Generates Sublime Text 2 project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
#if defined(_WIN32)
factory.AddSupportedGlobalGenerator("MinGW Makefiles");
factory.AddSupportedGlobalGenerator("NMake Makefiles");
// disable until somebody actually tests it:
// factory.AddSupportedGlobalGenerator("MSYS Makefiles");
#endif
factory.AddSupportedGlobalGenerator("Ninja");
factory.AddSupportedGlobalGenerator("Unix Makefiles");
}
return &factory;
} }
cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator() cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
: cmExternalMakefileProjectGenerator() : cmExternalMakefileProjectGenerator()
{ {
#if defined(_WIN32)
this->SupportedGlobalGenerators.push_back("MinGW Makefiles");
this->SupportedGlobalGenerators.push_back("NMake Makefiles");
// disable until somebody actually tests it:
// this->SupportedGlobalGenerators.push_back("MSYS Makefiles");
#endif
this->SupportedGlobalGenerators.push_back("Ninja");
this->SupportedGlobalGenerators.push_back("Unix Makefiles");
} }
void cmExtraSublimeTextGenerator::Generate() void cmExtraSublimeTextGenerator::Generate()

View File

@ -27,22 +27,10 @@ class cmGeneratorTarget;
class cmExtraSublimeTextGenerator : public cmExternalMakefileProjectGenerator class cmExtraSublimeTextGenerator : public cmExternalMakefileProjectGenerator
{ {
public: public:
static cmExternalMakefileProjectGeneratorFactory* GetFactory();
typedef std::map<std::string, std::vector<std::string> > MapSourceFileFlags; typedef std::map<std::string, std::vector<std::string> > MapSourceFileFlags;
cmExtraSublimeTextGenerator(); cmExtraSublimeTextGenerator();
std::string GetName() const CM_OVERRIDE
{
return cmExtraSublimeTextGenerator::GetActualName();
}
static std::string GetActualName() { return "Sublime Text 2"; }
static cmExternalMakefileProjectGenerator* New()
{
return new cmExtraSublimeTextGenerator;
}
/** Get the documentation entry for this generator. */
void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const CM_OVERRIDE;
void Generate() CM_OVERRIDE; void Generate() CM_OVERRIDE;
private: private:

View File

@ -25,20 +25,28 @@
#include <cmsys/FStream.hxx> #include <cmsys/FStream.hxx>
#include <cmsys/SystemTools.hxx> #include <cmsys/SystemTools.hxx>
void cmGlobalKdevelopGenerator::GetDocumentation(cmDocumentationEntry& entry,
const std::string&) const
{
entry.Name = this->GetName();
entry.Brief = "Generates KDevelop 3 project files.";
}
cmGlobalKdevelopGenerator::cmGlobalKdevelopGenerator() cmGlobalKdevelopGenerator::cmGlobalKdevelopGenerator()
: cmExternalMakefileProjectGenerator() : cmExternalMakefileProjectGenerator()
{ {
this->SupportedGlobalGenerators.push_back("Unix Makefiles"); }
cmExternalMakefileProjectGeneratorFactory*
cmGlobalKdevelopGenerator::GetFactory()
{
static cmExternalMakefileProjectGeneratorSimpleFactory<
cmGlobalKdevelopGenerator>
factory("KDevelop3", "Generates KDevelop 3 project files.");
if (factory.GetSupportedGlobalGenerators().empty()) {
factory.AddSupportedGlobalGenerator("Unix Makefiles");
#ifdef CMAKE_USE_NINJA #ifdef CMAKE_USE_NINJA
this->SupportedGlobalGenerators.push_back("Ninja"); factory.AddSupportedGlobalGenerator("Ninja");
#endif #endif
factory.Aliases.push_back("KDevelop3");
}
return &factory;
} }
void cmGlobalKdevelopGenerator::Generate() void cmGlobalKdevelopGenerator::Generate()

View File

@ -33,18 +33,7 @@ class cmGlobalKdevelopGenerator : public cmExternalMakefileProjectGenerator
public: public:
cmGlobalKdevelopGenerator(); cmGlobalKdevelopGenerator();
std::string GetName() const CM_OVERRIDE static cmExternalMakefileProjectGeneratorFactory* GetFactory();
{
return cmGlobalKdevelopGenerator::GetActualName();
}
static std::string GetActualName() { return "KDevelop3"; }
static cmExternalMakefileProjectGenerator* New()
{
return new cmGlobalKdevelopGenerator;
}
/** Get the documentation entry for this generator. */
void GetDocumentation(cmDocumentationEntry& entry,
const std::string& fullName) const CM_OVERRIDE;
void Generate() CM_OVERRIDE; void Generate() CM_OVERRIDE;

View File

@ -793,53 +793,21 @@ int cmake::AddCMakePaths()
return 1; return 1;
} }
void cmake::AddExtraGenerator(const std::string& name,
CreateExtraGeneratorFunctionType newFunction)
{
cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
const std::vector<std::string>& supportedGlobalGenerators =
extraGenerator->GetSupportedGlobalGenerators();
for (std::vector<std::string>::const_iterator it =
supportedGlobalGenerators.begin();
it != supportedGlobalGenerators.end(); ++it) {
std::string fullName =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(*it, name);
this->ExtraGenerators[fullName] = newFunction;
}
delete extraGenerator;
}
void cmake::AddDefaultExtraGenerators() void cmake::AddDefaultExtraGenerators()
{ {
#if defined(CMAKE_BUILD_WITH_CMAKE) #if defined(CMAKE_BUILD_WITH_CMAKE)
#if defined(_WIN32) && !defined(__CYGWIN__) this->ExtraGenerators.push_back(cmExtraCodeBlocksGenerator::GetFactory());
// e.g. kdevelop4 ? this->ExtraGenerators.push_back(cmExtraCodeLiteGenerator::GetFactory());
#endif this->ExtraGenerators.push_back(cmExtraSublimeTextGenerator::GetFactory());
this->ExtraGenerators.push_back(cmExtraKateGenerator::GetFactory());
this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
&cmExtraCodeBlocksGenerator::New);
this->AddExtraGenerator(cmExtraCodeLiteGenerator::GetActualName(),
&cmExtraCodeLiteGenerator::New);
this->AddExtraGenerator(cmExtraSublimeTextGenerator::GetActualName(),
&cmExtraSublimeTextGenerator::New);
this->AddExtraGenerator(cmExtraKateGenerator::GetActualName(),
&cmExtraKateGenerator::New);
#ifdef CMAKE_USE_ECLIPSE #ifdef CMAKE_USE_ECLIPSE
this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(), this->ExtraGenerators.push_back(cmExtraEclipseCDT4Generator::GetFactory());
&cmExtraEclipseCDT4Generator::New);
#endif #endif
#ifdef CMAKE_USE_KDEVELOP #ifdef CMAKE_USE_KDEVELOP
this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(), this->ExtraGenerators.push_back(cmGlobalKdevelopGenerator::GetFactory());
&cmGlobalKdevelopGenerator::New);
// for kdevelop also add the generator with just the name of the
// extra generator, since it was this way since cmake 2.2
this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()] =
&cmGlobalKdevelopGenerator::New;
#endif #endif
#endif #endif
} }
@ -856,32 +824,74 @@ void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators)
info.supportsToolset = (*i)->SupportsToolset(); info.supportsToolset = (*i)->SupportsToolset();
info.supportsPlatform = (*i)->SupportsPlatform(); info.supportsPlatform = (*i)->SupportsPlatform();
info.name = names[j]; info.name = names[j];
info.isAlias = false;
generators.push_back(info); generators.push_back(info);
} }
} }
for (RegisteredExtraGeneratorsMap::const_iterator for (RegisteredExtraGeneratorsVector::const_iterator
i = this->ExtraGenerators.begin(), i = this->ExtraGenerators.begin(),
e = this->ExtraGenerators.end(); e = this->ExtraGenerators.end();
i != e; ++i) { i != e; ++i) {
GeneratorInfo info; const std::vector<std::string> genList =
info.name = i->first; (*i)->GetSupportedGlobalGenerators();
info.supportsToolset = false; for (std::vector<std::string>::const_iterator gen = genList.begin();
info.supportsPlatform = false; gen != genList.end(); ++gen) {
generators.push_back(info); GeneratorInfo info;
info.name = cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
(*i)->GetName(), *gen);
info.supportsPlatform = false;
info.supportsToolset = false;
info.isAlias = false;
generators.push_back(info);
}
for (std::vector<std::string>::const_iterator a = (*i)->Aliases.begin();
a != (*i)->Aliases.end(); ++a) {
GeneratorInfo info;
info.name = *a;
info.supportsPlatform = false;
info.supportsToolset = false;
info.isAlias = true;
generators.push_back(info);
}
} }
} }
static std::pair<cmExternalMakefileProjectGenerator*, std::string>
createExtraGenerator(
const std::vector<cmExternalMakefileProjectGeneratorFactory*>& in,
const std::string& name)
{
for (std::vector<cmExternalMakefileProjectGeneratorFactory*>::const_iterator
i = in.begin();
i != in.end(); ++i) {
const std::vector<std::string> generators =
(*i)->GetSupportedGlobalGenerators();
if ((*i)->GetName() == name) { // Match aliases
return std::make_pair((*i)->CreateExternalMakefileProjectGenerator(),
generators.at(0));
}
for (std::vector<std::string>::const_iterator g = generators.begin();
g != generators.end(); ++g) {
const std::string fullName =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
*g, (*i)->GetName());
if (fullName == name) {
return std::make_pair((*i)->CreateExternalMakefileProjectGenerator(),
*g);
}
}
}
return std::make_pair(
static_cast<cmExternalMakefileProjectGenerator*>(CM_NULLPTR), name);
}
cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname) cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
{ {
cmExternalMakefileProjectGenerator* extraGenerator = CM_NULLPTR; std::pair<cmExternalMakefileProjectGenerator*, std::string> extra =
std::string name = gname; createExtraGenerator(this->ExtraGenerators, gname);
RegisteredExtraGeneratorsMap::const_iterator extraGenIt = cmExternalMakefileProjectGenerator* extraGenerator = extra.first;
this->ExtraGenerators.find(name); const std::string name = extra.second;
if (extraGenIt != this->ExtraGenerators.end()) {
extraGenerator = (extraGenIt->second)();
name = extraGenerator->GetGlobalGeneratorName(name);
}
cmGlobalGenerator* generator = CM_NULLPTR; cmGlobalGenerator* generator = CM_NULLPTR;
for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin(); for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
@ -1651,15 +1661,32 @@ void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
(*i)->GetDocumentation(e); (*i)->GetDocumentation(e);
v.push_back(e); v.push_back(e);
} }
for (RegisteredExtraGeneratorsMap::const_iterator i = for (RegisteredExtraGeneratorsVector::const_iterator i =
this->ExtraGenerators.begin(); this->ExtraGenerators.begin();
i != this->ExtraGenerators.end(); ++i) { i != this->ExtraGenerators.end(); ++i) {
cmDocumentationEntry e; const std::string doc = (*i)->GetDocumentation();
cmExternalMakefileProjectGenerator* generator = (i->second)(); const std::string name = (*i)->GetName();
generator->GetDocumentation(e, i->first);
e.Name = i->first; // Aliases:
delete generator; for (std::vector<std::string>::const_iterator a = (*i)->Aliases.begin();
v.push_back(e); a != (*i)->Aliases.end(); ++a) {
cmDocumentationEntry e;
e.Name = *a;
e.Brief = doc;
v.push_back(e);
}
// Full names:
const std::vector<std::string> generators =
(*i)->GetSupportedGlobalGenerators();
for (std::vector<std::string>::const_iterator g = generators.begin();
g != generators.end(); ++g) {
cmDocumentationEntry e;
e.Name =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(*g, name);
e.Brief = doc;
v.push_back(e);
}
} }
} }

View File

@ -27,7 +27,7 @@ class cmLocalGenerator;
class cmMakefile; class cmMakefile;
class cmVariableWatch; class cmVariableWatch;
class cmFileTimeComparison; class cmFileTimeComparison;
class cmExternalMakefileProjectGenerator; class cmExternalMakefileProjectGeneratorFactory;
class cmDocumentationSection; class cmDocumentationSection;
class cmTarget; class cmTarget;
class cmGeneratedFileStream; class cmGeneratedFileStream;
@ -105,6 +105,7 @@ public:
std::string name; std::string name;
bool supportsToolset; bool supportsToolset;
bool supportsPlatform; bool supportsPlatform;
bool isAlias;
}; };
typedef std::map<std::string, cmInstalledFile> InstalledFilesMap; typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
@ -416,18 +417,14 @@ protected:
void InitializeProperties(); void InitializeProperties();
int HandleDeleteCacheVariables(const std::string& var); int HandleDeleteCacheVariables(const std::string& var);
typedef cmExternalMakefileProjectGenerator* (
*CreateExtraGeneratorFunctionType)();
typedef std::map<std::string, CreateExtraGeneratorFunctionType>
RegisteredExtraGeneratorsMap;
typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector; typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector;
RegisteredGeneratorsVector Generators; RegisteredGeneratorsVector Generators;
RegisteredExtraGeneratorsMap ExtraGenerators; typedef std::vector<cmExternalMakefileProjectGeneratorFactory*>
RegisteredExtraGeneratorsVector;
RegisteredExtraGeneratorsVector ExtraGenerators;
void AddDefaultCommands(); void AddDefaultCommands();
void AddDefaultGenerators(); void AddDefaultGenerators();
void AddDefaultExtraGenerators(); void AddDefaultExtraGenerators();
void AddExtraGenerator(const std::string& name,
CreateExtraGeneratorFunctionType newFunction);
cmGlobalGenerator* GlobalGenerator; cmGlobalGenerator* GlobalGenerator;
std::map<std::string, DiagLevel> DiagLevels; std::map<std::string, DiagLevel> DiagLevels;