cmake: Provide guidance when an invalid -G option is given

Print a list of generators if no generator or an invalid one is
supplied.

Signed-off-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2015-03-29 11:28:30 -07:00 committed by Brad King
parent 4e039a9a98
commit 588dcb33b7
7 changed files with 43 additions and 4 deletions

View File

@ -138,6 +138,8 @@ bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
return this->PrintHelpListVariables(os); return this->PrintHelpListVariables(os);
case cmDocumentation::ListPolicies: case cmDocumentation::ListPolicies:
return this->PrintHelpListPolicies(os); return this->PrintHelpListPolicies(os);
case cmDocumentation::ListGenerators:
return this->PrintHelpListGenerators(os);
case cmDocumentation::Version: case cmDocumentation::Version:
return this->PrintVersion(os); return this->PrintVersion(os);
case cmDocumentation::OldCustomModules: case cmDocumentation::OldCustomModules:
@ -816,6 +818,19 @@ bool cmDocumentation::PrintHelpListPolicies(std::ostream& os)
return true; return true;
} }
//----------------------------------------------------------------------------
bool cmDocumentation::PrintHelpListGenerators(std::ostream& os)
{
std::map<std::string,cmDocumentationSection*>::iterator si;
si = this->AllSections.find("Generators");
if(si != this->AllSections.end())
{
this->Formatter.SetIndent(" ");
this->Formatter.PrintSection(os, *si->second);
}
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmDocumentation::PrintHelpOneVariable(std::ostream& os) bool cmDocumentation::PrintHelpOneVariable(std::ostream& os)
{ {

View File

@ -117,6 +117,7 @@ private:
bool PrintHelpListProperties(std::ostream& os); bool PrintHelpListProperties(std::ostream& os);
bool PrintHelpListVariables(std::ostream& os); bool PrintHelpListVariables(std::ostream& os);
bool PrintHelpListPolicies(std::ostream& os); bool PrintHelpListPolicies(std::ostream& os);
bool PrintHelpListGenerators(std::ostream& os);
bool PrintOldCustomModules(std::ostream& os); bool PrintOldCustomModules(std::ostream& os);
const char* GetNameString() const; const char* GetNameString() const;

View File

@ -26,8 +26,8 @@ public:
/** Types of help provided. */ /** Types of help provided. */
enum Type enum Type
{ {
None, Version, Usage, Help, Full, ListManuals, None, Version, Usage, Help, Full, ListManuals, ListCommands,
ListCommands, ListModules, ListProperties, ListVariables, ListPolicies, ListModules, ListProperties, ListVariables, ListPolicies, ListGenerators,
OneManual, OneCommand, OneModule, OneProperty, OneVariable, OnePolicy, OneManual, OneCommand, OneModule, OneProperty, OneVariable, OnePolicy,
OldCustomModules OldCustomModules
}; };

View File

@ -818,6 +818,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
if(i >= args.size()) if(i >= args.size())
{ {
cmSystemTools::Error("No generator specified for -G"); cmSystemTools::Error("No generator specified for -G");
this->PrintGeneratorList();
return; return;
} }
value = args[i]; value = args[i];
@ -828,6 +829,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
{ {
cmSystemTools::Error("Could not create named generator ", cmSystemTools::Error("Could not create named generator ",
value.c_str()); value.c_str());
this->PrintGeneratorList();
} }
else else
{ {
@ -1961,6 +1963,18 @@ void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
} }
} }
void cmake::PrintGeneratorList()
{
#ifdef CMAKE_BUILD_WITH_CMAKE
cmDocumentation doc;
std::vector<cmDocumentationEntry> generators;
this->GetGeneratorDocumentation(generators);
doc.AppendSection("Generators",generators);
std::cerr << "\n";
doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr);
#endif
}
void cmake::UpdateConversionPathTable() void cmake::UpdateConversionPathTable()
{ {
// Update the path conversion table with any specified file: // Update the path conversion table with any specified file:
@ -2438,6 +2452,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
if(i >= args.size()) if(i >= args.size())
{ {
cmSystemTools::Error("No generator specified for -G"); cmSystemTools::Error("No generator specified for -G");
this->PrintGeneratorList();
return -1; return -1;
} }
value = args[i]; value = args[i];
@ -2448,6 +2463,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
{ {
cmSystemTools::Error("Could not create named generator ", cmSystemTools::Error("Could not create named generator ",
value.c_str()); value.c_str());
this->PrintGeneratorList();
} }
else else
{ {

View File

@ -476,6 +476,9 @@ private:
InstalledFilesMap InstalledFiles; InstalledFilesMap InstalledFiles;
void UpdateConversionPathTable(); void UpdateConversionPathTable();
// Print a list of valid generators to stderr.
void PrintGeneratorList();
}; };
#define CMAKE_STANDARD_OPTIONS_TABLE \ #define CMAKE_STANDARD_OPTIONS_TABLE \

View File

@ -1 +1,3 @@
^CMake Error: Could not create named generator NoSuchGenerator$ ^CMake Error: Could not create named generator NoSuchGenerator
Generators

View File

@ -1 +1,3 @@
^CMake Error: No generator specified for -G$ ^CMake Error: No generator specified for -G
Generators