From 7408cd39298dfce442d7aa539a90a227433865d5 Mon Sep 17 00:00:00 2001 From: Artur Ryt Date: Fri, 30 Nov 2018 19:00:57 +0100 Subject: cmake: Return generator docs directly The GetGeneratorDocumentation() function was not accurately named and required the vector to populate to be passed as a function argument. This commit makes the slightly renamed function return by value, making it a true getter as implied by its name. Some minor refactoring of the implementation also makes the steps of populating the vector clearer. --- Source/CursesDialog/ccmake.cxx | 5 ++--- Source/QtDialog/CMakeSetup.cxx | 3 +-- Source/cmake.cxx | 19 ++++++++++++++++--- Source/cmake.h | 5 ++++- Source/cmakemain.cxx | 6 ++---- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index 6dc692e..44789b0 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -5,7 +5,7 @@ #include "cmCursesMainForm.h" #include "cmCursesStandardIncludes.h" #include "cmDocumentation.h" -#include "cmDocumentationEntry.h" +#include "cmDocumentationEntry.h" // IWYU pragma: keep #include "cmState.h" #include "cmSystemTools.h" #include "cmake.h" @@ -88,8 +88,7 @@ int main(int argc, char const* const* argv) hcm.SetHomeDirectory(""); hcm.SetHomeOutputDirectory(""); hcm.AddCMakePaths(); - std::vector generators; - hcm.GetGeneratorDocumentation(generators); + auto generators = hcm.GetGeneratorsDocumentation(); doc.SetName("ccmake"); doc.SetSection("Name", cmDocumentationName); doc.SetSection("Usage", cmDocumentationUsage); diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index b4307bb..9f4e48e 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -69,8 +69,7 @@ int main(int argc, char** argv) hcm.SetHomeOutputDirectory(""); hcm.AddCMakePaths(); - std::vector generators; - hcm.GetGeneratorDocumentation(generators); + auto generators = hcm.GetGeneratorsDocumentation(); doc.SetName("cmake"); doc.SetSection("Name", cmDocumentationName); doc.SetSection("Usage", cmDocumentationUsage); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 9fcfbde..c53b597 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1924,13 +1924,19 @@ void cmake::SetIsInTryCompile(bool b) this->State->SetIsInTryCompile(b); } -void cmake::GetGeneratorDocumentation(std::vector& v) +void cmake::AppendGlobalGeneratorsDocumentation( + std::vector& v) { for (cmGlobalGeneratorFactory* g : this->Generators) { cmDocumentationEntry e; g->GetDocumentation(e); v.push_back(std::move(e)); } +} + +void cmake::AppendExtraGeneratorsDocumentation( + std::vector& v) +{ for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) { const std::string doc = eg->GetDocumentation(); const std::string name = eg->GetName(); @@ -1956,12 +1962,19 @@ void cmake::GetGeneratorDocumentation(std::vector& v) } } +std::vector cmake::GetGeneratorsDocumentation() +{ + std::vector v; + this->AppendGlobalGeneratorsDocumentation(v); + this->AppendExtraGeneratorsDocumentation(v); + return v; +} + void cmake::PrintGeneratorList() { #ifdef CMAKE_BUILD_WITH_CMAKE cmDocumentation doc; - std::vector generators; - this->GetGeneratorDocumentation(generators); + auto generators = this->GetGeneratorsDocumentation(); doc.AppendSection("Generators", generators); std::cerr << "\n"; doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr); diff --git a/Source/cmake.h b/Source/cmake.h index cd8c622..1586845 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -292,7 +292,7 @@ public: cmVariableWatch* GetVariableWatch() { return this->VariableWatch; } #endif - void GetGeneratorDocumentation(std::vector&); + std::vector GetGeneratorsDocumentation(); ///! Set/Get a property of this target file void SetProperty(const std::string& prop, const char* value); @@ -533,6 +533,9 @@ private: void CreateDefaultGlobalGenerator(); + void AppendGlobalGeneratorsDocumentation(std::vector&); + void AppendExtraGeneratorsDocumentation(std::vector&); + /** * Convert a message type between a warning and an error, based on the state * of the error output CMake variables, in the cache. diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 84d1414..c1c9537 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -2,7 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmAlgorithms.h" -#include "cmDocumentationEntry.h" +#include "cmDocumentationEntry.h" // IWYU pragma: keep #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmState.h" @@ -227,9 +227,7 @@ int do_cmake(int ac, char const* const* av) std::vector args(av, av + ac); hcm.SetCacheArgs(args); - std::vector generators; - - hcm.GetGeneratorDocumentation(generators); + auto generators = hcm.GetGeneratorsDocumentation(); doc.SetName("cmake"); doc.SetSection("Name", cmDocumentationName); -- cgit v0.12 From 6023fe7ff22848bc29ee67395eeb10f066758c06 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Sun, 2 Dec 2018 14:50:55 +1100 Subject: ccmake: Append rather than replace Generators section of docs Using SetSection() discards the heading line populated by addCMakeStandardDocSections(), whereas AppendSection() preserves it. This also makes the code used for ccmake consistent with that used for cmake and cmake-gui. --- Source/CursesDialog/ccmake.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index 44789b0..ec3cd9f 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -95,7 +95,7 @@ int main(int argc, char const* const* argv) if (argc == 1) { doc.AppendSection("Usage", cmDocumentationUsageNote); } - doc.SetSection("Generators", generators); + doc.AppendSection("Generators", generators); doc.PrependSection("Options", cmDocumentationOptions); return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; } -- cgit v0.12 From dfd5ae7da71ed9330eca7e352b8f9b42babdf3dd Mon Sep 17 00:00:00 2001 From: Artur Ryt Date: Fri, 30 Nov 2018 19:43:22 +0100 Subject: 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 --- Source/cmDocumentation.cxx | 15 ++++++++++++--- Source/cmDocumentationEntry.h | 1 + Source/cmDocumentationFormatter.cxx | 3 ++- Source/cmake.cxx | 26 ++++++++++++++++++++++---- Source/cmake.h | 1 + Tests/Server/cmakelib.py | 4 ++++ 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 6a817b4..d4628fa 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -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, diff --git a/Source/cmDocumentationEntry.h b/Source/cmDocumentationEntry.h index ea43b88..ca323cc 100644 --- a/Source/cmDocumentationEntry.h +++ b/Source/cmDocumentationEntry.h @@ -12,6 +12,7 @@ struct cmDocumentationEntry { std::string Name; std::string Brief; + char CustomNamePrefix = ' '; cmDocumentationEntry() {} cmDocumentationEntry(const char* doc[2]) { diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 678e408..e573c04 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -5,6 +5,7 @@ #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" +#include #include #include #include @@ -168,7 +169,7 @@ void cmDocumentationFormatter::PrintSection( const std::vector& 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(strlen(this->TextIndent)) - 4; for (int i = static_cast(entry.Name.size()); i < align; ++i) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index c53b597..619fd3e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1519,7 +1519,7 @@ int cmake::ActualConfigure() return 0; } -void cmake::CreateDefaultGlobalGenerator() +std::unique_ptr 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(gen); #else - this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3(this)); + return cm::make_unique(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& 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)); } } diff --git a/Source/cmake.h b/Source/cmake.h index 1586845..31cd97d 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -531,6 +531,7 @@ private: // Print a list of valid generators to stderr. void PrintGeneratorList(); + std::unique_ptr EvaluateDefaultGlobalGenerator(); void CreateDefaultGlobalGenerator(); void AppendGlobalGeneratorsDocumentation(std::vector&); diff --git a/Tests/Server/cmakelib.py b/Tests/Server/cmakelib.py index edb5af6..546ae4c 100644 --- a/Tests/Server/cmakelib.py +++ b/Tests/Server/cmakelib.py @@ -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(' '): -- cgit v0.12