Commit dfd5ae7d authored by Artur Ryt's avatar Artur Ryt Committed by Brad King

Help: Mark default CMake generator with asterisk

Required extracting default generator evaluation
to explicit function, as Visual Studio generators
get validated during their construction.

Fixes: #18544
parent 6023fe7f
Pipeline #128021 passed with stage
......@@ -43,11 +43,18 @@ static const char* cmDocumentationStandardOptions[][2] = {
{ nullptr, nullptr }
};
static const char* cmDocumentationGeneratorsHeader[][2] = {
static const char* cmDocumentationCPackGeneratorsHeader[][2] = {
{ nullptr, "The following generators are available on this platform:" },
{ nullptr, nullptr }
};
static const char* cmDocumentationCMakeGeneratorsHeader[][2] = {
{ nullptr,
"The following generators are available on this platform (* marks "
"default):" },
{ nullptr, nullptr }
};
cmDocumentation::cmDocumentation()
{
this->addCommonStandardDocSections();
......@@ -178,7 +185,7 @@ void cmDocumentation::addCommonStandardDocSections()
void cmDocumentation::addCMakeStandardDocSections()
{
cmDocumentationSection sec{ "Generators" };
sec.Append(cmDocumentationGeneratorsHeader);
sec.Append(cmDocumentationCMakeGeneratorsHeader);
this->AllSections.emplace("Generators", std::move(sec));
}
......@@ -191,7 +198,9 @@ void cmDocumentation::addCTestStandardDocSections()
void cmDocumentation::addCPackStandardDocSections()
{
addCMakeStandardDocSections();
cmDocumentationSection sec{ "Generators" };
sec.Append(cmDocumentationCPackGeneratorsHeader);
this->AllSections.emplace("Generators", std::move(sec));
}
bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
......
......@@ -12,6 +12,7 @@ struct cmDocumentationEntry
{
std::string Name;
std::string Brief;
char CustomNamePrefix = ' ';
cmDocumentationEntry() {}
cmDocumentationEntry(const char* doc[2])
{
......
......@@ -5,6 +5,7 @@
#include "cmDocumentationEntry.h"
#include "cmDocumentationSection.h"
#include <iomanip>
#include <ostream>
#include <string.h>
#include <string>
......@@ -168,7 +169,7 @@ void cmDocumentationFormatter::PrintSection(
const std::vector<cmDocumentationEntry>& entries = section.GetEntries();
for (cmDocumentationEntry const& entry : entries) {
if (!entry.Name.empty()) {
os << " " << entry.Name;
os << std::setw(2) << std::left << entry.CustomNamePrefix << entry.Name;
this->TextIndent = " ";
int align = static_cast<int>(strlen(this->TextIndent)) - 4;
for (int i = static_cast<int>(entry.Name.size()); i < align; ++i) {
......
......@@ -1519,7 +1519,7 @@ int cmake::ActualConfigure()
return 0;
}
void cmake::CreateDefaultGlobalGenerator()
std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator()
{
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
std::string found;
......@@ -1572,11 +1572,20 @@ void cmake::CreateDefaultGlobalGenerator()
if (!gen) {
gen = new cmGlobalNMakeMakefileGenerator(this);
}
this->SetGlobalGenerator(gen);
std::cout << "-- Building for: " << gen->GetName() << "\n";
return std::unique_ptr<cmGlobalGenerator>(gen);
#else
this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3(this));
return cm::make_unique<cmGlobalUnixMakefileGenerator3>(this);
#endif
}
void cmake::CreateDefaultGlobalGenerator()
{
auto gen = this->EvaluateDefaultGlobalGenerator();
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
// This print could be unified for all platforms
std::cout << "-- Building for: " << gen->GetName() << "\n";
#endif
this->SetGlobalGenerator(gen.release());
}
void cmake::PreLoadCMakeFiles()
......@@ -1927,9 +1936,18 @@ void cmake::SetIsInTryCompile(bool b)
void cmake::AppendGlobalGeneratorsDocumentation(
std::vector<cmDocumentationEntry>& v)
{
const auto defaultGenerator = this->EvaluateDefaultGlobalGenerator();
const std::string defaultName = defaultGenerator->GetName();
bool foundDefaultOne = false;
for (cmGlobalGeneratorFactory* g : this->Generators) {
cmDocumentationEntry e;
g->GetDocumentation(e);
if (!foundDefaultOne &&
cmSystemTools::StringStartsWith(e.Name, defaultName.c_str())) {
e.CustomNamePrefix = '*';
foundDefaultOne = true;
}
v.push_back(std::move(e));
}
}
......
......@@ -531,6 +531,7 @@ private:
// Print a list of valid generators to stderr.
void PrintGeneratorList();
std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
void CreateDefaultGlobalGenerator();
void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
......
......@@ -276,6 +276,10 @@ def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
index = cmakeoutput.index('\nGenerators\n\n')
cmakeGenerators = []
for line in cmakeoutput[index + 12:].splitlines():
if not line:
continue
if line[0] == '*': # default generator marker
line = ' ' + line[1:]
if not line.startswith(' '):
continue
if line.startswith(' '):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment