From 30bcdafaeff789b20cc8b6e97b8271c0105a93b1 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 06:14:00 +0400 Subject: cmDocumentation: Remove MSVC 6 workaround --- Source/cmDocumentation.h | 28 ++++++++++++++++++++++++++-- Source/cmDocumentationFormatter.h | 34 ---------------------------------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 313be32..ab027d1 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -15,9 +15,33 @@ struct cmDocumentationEntry; /** Class to generate documentation. */ -class cmDocumentation : public cmDocumentationEnums +class cmDocumentation { public: + /** Types of help provided. */ + enum Type + { + None, + Version, + Usage, + Help, + Full, + ListManuals, + ListCommands, + ListModules, + ListProperties, + ListVariables, + ListPolicies, + ListGenerators, + OneManual, + OneCommand, + OneModule, + OneProperty, + OneVariable, + OnePolicy, + OldCustomModules + }; + cmDocumentation(); /** @@ -114,7 +138,7 @@ private: struct RequestedHelpItem { - cmDocumentationEnums::Type HelpType = None; + Type HelpType = None; std::string Filename; std::string Argument; }; diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index cb3038a..98cac9b 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -6,40 +6,6 @@ #include -/** This is just a helper class to make it build with MSVC 6.0. -Actually the enums and internal classes could directly go into -cmDocumentation, but then MSVC6 complains in RequestedHelpItem that -cmDocumentation is an undefined type and so it doesn't know the enums. -Moving the enums to a class which is then already completely parsed helps -against this. */ -class cmDocumentationEnums -{ -public: - /** Types of help provided. */ - enum Type - { - None, - Version, - Usage, - Help, - Full, - ListManuals, - ListCommands, - ListModules, - ListProperties, - ListVariables, - ListPolicies, - ListGenerators, - OneManual, - OneCommand, - OneModule, - OneProperty, - OneVariable, - OnePolicy, - OldCustomModules - }; -}; - class cmDocumentationSection; /** Print documentation in a simple text format. */ -- cgit v0.12 From 049b017c5dfafa26f01dbde87f62d97994665f3c Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 06:17:56 +0400 Subject: cmDocumentation.cxx: Use anonymous namespace instead of `static` --- Source/cmDocumentation.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index d466a12..abb349f 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -16,7 +16,8 @@ #include "cmSystemTools.h" #include "cmVersion.h" -static const char* cmDocumentationStandardOptions[][2] = { +namespace { +const char* cmDocumentationStandardOptions[][2] = { { "-h,-H,--help,-help,-usage,/?", "Print usage information and exit." }, { "--version,-version,/V []", "Print version number and exit." }, { "--help-full []", "Print all help manuals and exit." }, @@ -46,17 +47,18 @@ static const char* cmDocumentationStandardOptions[][2] = { { nullptr, nullptr } }; -static const char* cmDocumentationCPackGeneratorsHeader[][2] = { +const char* cmDocumentationCPackGeneratorsHeader[][2] = { { nullptr, "The following generators are available on this platform:" }, { nullptr, nullptr } }; -static const char* cmDocumentationCMakeGeneratorsHeader[][2] = { +const char* cmDocumentationCMakeGeneratorsHeader[][2] = { { nullptr, "The following generators are available on this platform (* marks " "default):" }, { nullptr, nullptr } }; +} // anonymous namespace cmDocumentation::cmDocumentation() { -- cgit v0.12 From 8ab0168cbca815454c70da37e41d3eec9d52c461 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 06:37:41 +0400 Subject: cmDocumentation.cxx: Use lambda function instead of macro --- Source/cmDocumentation.cxx | 86 ++++++++++++++++++++++------------------------ Source/cmDocumentation.h | 1 - 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index abb349f..1e37f52 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -58,6 +58,12 @@ const char* cmDocumentationCMakeGeneratorsHeader[][2] = { "default):" }, { nullptr, nullptr } }; + +bool isOption(const char* arg) +{ + return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) || + (strcmp(arg, "/?") == 0)); +} } // anonymous namespace cmDocumentation::cmDocumentation() @@ -150,14 +156,6 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os) return result; } -#define GET_OPT_ARGUMENT(target) \ - do { \ - if ((i + 1 < argc) && !this->IsOption(argv[i + 1])) { \ - (target) = argv[i + 1]; \ - i = i + 1; \ - }; \ - } while (false) - void cmDocumentation::WarnFormFromFilename( cmDocumentation::RequestedHelpItem& request, bool& result) { @@ -219,6 +217,14 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, return true; } + auto get_opt_argument = [=](const int nextIdx, std::string& target) -> bool { + if ((nextIdx < argc) && !isOption(argv[nextIdx])) { + target = argv[nextIdx]; + return true; + } + return false; + }; + // Search for supported help options. bool result = false; @@ -232,7 +238,7 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, (strcmp(argv[i], "/?") == 0) || (strcmp(argv[i], "-usage") == 0) || (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-H") == 0)) { help.HelpType = cmDocumentation::Help; - GET_OPT_ARGUMENT(help.Argument); + i += int(get_opt_argument(i + 1, help.Argument)); help.Argument = cmSystemTools::LowerCase(help.Argument); // special case for single command if (!help.Argument.empty()) { @@ -241,25 +247,25 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, } else if (strcmp(argv[i], "--help-properties") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-properties.7"; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-policies") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-policies.7"; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-variables") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-variables.7"; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-modules") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-modules.7"; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-custom-modules") == 0) { - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); cmSystemTools::Message( "Warning: --help-custom-modules no longer supported"); if (help.Filename.empty()) { @@ -273,83 +279,79 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv, } else if (strcmp(argv[i], "--help-commands") == 0) { help.HelpType = cmDocumentation::OneManual; help.Argument = "cmake-commands.7"; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-compatcommands") == 0) { - GET_OPT_ARGUMENT(help.Filename); cmSystemTools::Message( "Warning: --help-compatcommands no longer supported"); return true; } else if (strcmp(argv[i], "--help-full") == 0) { help.HelpType = cmDocumentation::Full; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-html") == 0) { - GET_OPT_ARGUMENT(help.Filename); cmSystemTools::Message("Warning: --help-html no longer supported"); return true; } else if (strcmp(argv[i], "--help-man") == 0) { - GET_OPT_ARGUMENT(help.Filename); cmSystemTools::Message("Warning: --help-man no longer supported"); return true; } else if (strcmp(argv[i], "--help-command") == 0) { help.HelpType = cmDocumentation::OneCommand; - GET_OPT_ARGUMENT(help.Argument); - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Argument)); + i += int(get_opt_argument(i + 1, help.Filename)); help.Argument = cmSystemTools::LowerCase(help.Argument); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-module") == 0) { help.HelpType = cmDocumentation::OneModule; - GET_OPT_ARGUMENT(help.Argument); - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Argument)); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-property") == 0) { help.HelpType = cmDocumentation::OneProperty; - GET_OPT_ARGUMENT(help.Argument); - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Argument)); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-policy") == 0) { help.HelpType = cmDocumentation::OnePolicy; - GET_OPT_ARGUMENT(help.Argument); - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Argument)); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-variable") == 0) { help.HelpType = cmDocumentation::OneVariable; - GET_OPT_ARGUMENT(help.Argument); - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Argument)); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-manual") == 0) { help.HelpType = cmDocumentation::OneManual; - GET_OPT_ARGUMENT(help.Argument); - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Argument)); + i += int(get_opt_argument(i + 1, help.Filename)); this->WarnFormFromFilename(help, result); } else if (strcmp(argv[i], "--help-command-list") == 0) { help.HelpType = cmDocumentation::ListCommands; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } else if (strcmp(argv[i], "--help-module-list") == 0) { help.HelpType = cmDocumentation::ListModules; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } else if (strcmp(argv[i], "--help-property-list") == 0) { help.HelpType = cmDocumentation::ListProperties; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } else if (strcmp(argv[i], "--help-variable-list") == 0) { help.HelpType = cmDocumentation::ListVariables; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } else if (strcmp(argv[i], "--help-policy-list") == 0) { help.HelpType = cmDocumentation::ListPolicies; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } else if (strcmp(argv[i], "--help-manual-list") == 0) { help.HelpType = cmDocumentation::ListManuals; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } else if (strcmp(argv[i], "--copyright") == 0) { - GET_OPT_ARGUMENT(help.Filename); cmSystemTools::Message("Warning: --copyright no longer supported"); return true; } else if ((strcmp(argv[i], "--version") == 0) || (strcmp(argv[i], "-version") == 0) || (strcmp(argv[i], "/V") == 0)) { help.HelpType = cmDocumentation::Version; - GET_OPT_ARGUMENT(help.Filename); + i += int(get_opt_argument(i + 1, help.Filename)); } if (help.HelpType != None) { // This is a help option. See if there is a file name given. @@ -664,12 +666,6 @@ const char* cmDocumentation::GetNameString() const return "CMake"; } -bool cmDocumentation::IsOption(const char* arg) const -{ - return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) || - (strcmp(arg, "/?") == 0)); -} - bool cmDocumentation::PrintOldCustomModules(std::ostream& os) { // CheckOptions abuses the Argument field to give us the file name. diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index ab027d1..4055039 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -126,7 +126,6 @@ private: bool PrintOldCustomModules(std::ostream& os); const char* GetNameString() const; - bool IsOption(const char* arg) const; bool ShowGenerators; -- cgit v0.12 From f074e2bd49d449233205adfaa10ad94947d5f66b Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 06:42:34 +0400 Subject: cmDocumentation: Optimize `std::ostream::operator<<()` calls --- Source/cmDocumentation.cxx | 16 ++++++++-------- Source/cmDocumentationFormatter.cxx | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 1e37f52..77bc7c6 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -469,7 +469,7 @@ void cmDocumentation::PrintNames(std::ostream& os, std::string const& pattern) } std::sort(names.begin(), names.end()); for (std::string const& n : names) { - os << n << "\n"; + os << n << '\n'; } } @@ -505,7 +505,7 @@ bool cmDocumentation::PrintHelpOneManual(std::ostream& os) // Argument was not a manual. Complain. os << "Argument \"" << this->CurrentArgument << "\" to --help-manual is not an available manual. " - << "Use --help-manual-list to see all available manuals.\n"; + "Use --help-manual-list to see all available manuals.\n"; return false; } @@ -524,7 +524,7 @@ bool cmDocumentation::PrintHelpOneCommand(std::ostream& os) // Argument was not a command. Complain. os << "Argument \"" << this->CurrentArgument << "\" to --help-command is not a CMake command. " - << "Use --help-command-list to see all commands.\n"; + "Use --help-command-list to see all commands.\n"; return false; } @@ -557,7 +557,7 @@ bool cmDocumentation::PrintHelpListModules(std::ostream& os) } std::sort(modules.begin(), modules.end()); for (std::string const& m : modules) { - os << m << "\n"; + os << m << '\n'; } return true; } @@ -571,7 +571,7 @@ bool cmDocumentation::PrintHelpOneProperty(std::ostream& os) // Argument was not a property. Complain. os << "Argument \"" << this->CurrentArgument << "\" to --help-property is not a CMake property. " - << "Use --help-property-list to see all properties.\n"; + "Use --help-property-list to see all properties.\n"; return false; } @@ -620,7 +620,7 @@ bool cmDocumentation::PrintHelpOneVariable(std::ostream& os) // Argument was not a variable. Complain. os << "Argument \"" << this->CurrentArgument << "\" to --help-variable is not a defined variable. " - << "Use --help-variable-list to see all defined variables.\n"; + "Use --help-variable-list to see all defined variables.\n"; return false; } @@ -689,7 +689,7 @@ bool cmDocumentation::PrintOldCustomModules(std::ostream& os) } else if ((ext.length() == 2) && (ext[1] >= '1') && (ext[1] <= '9')) { /* clang-format off */ os << - ".TH " << name << " " << ext[1] << " \"" << + ".TH " << name << ' ' << ext[1] << " \"" << cmSystemTools::GetCurrentDateTime("%B %d, %Y") << "\" \"cmake " << cmVersion::GetCMakeVersion() << "\"\n" ".SH NAME\n" @@ -702,7 +702,7 @@ bool cmDocumentation::PrintOldCustomModules(std::ostream& os) ; /* clang-format on */ } else { - os << name << "\n\n" << summary << "\n" << detail; + os << name << "\n\n" << summary << '\n' << detail; } return true; } diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 732637e..fdc6304 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -67,7 +67,7 @@ void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, newline = true; } } - os << "\n"; + os << '\n'; } void cmDocumentationFormatter::PrintParagraph(std::ostream& os, @@ -75,7 +75,7 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os, { os << this->TextIndent; this->PrintColumn(os, text); - os << "\n"; + os << '\n'; } void cmDocumentationFormatter::SetIndent(const char* indent) @@ -111,7 +111,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) os << " "; column += 2; } else { - os << " "; + os << ' '; column += 1; } } else { @@ -127,7 +127,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) if (*r == '\n') { // Text provided a newline. Start a new line. - os << "\n"; + os << '\n'; ++r; column = 0; firstLine = false; @@ -137,7 +137,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) } } else { // Word does not fit on this line. Start a new line. - os << "\n"; + os << '\n'; firstLine = false; if (r > l) { os << this->TextIndent; @@ -160,7 +160,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) void cmDocumentationFormatter::PrintSection( std::ostream& os, cmDocumentationSection const& section) { - os << section.GetName() << "\n"; + os << section.GetName() << '\n'; const std::vector& entries = section.GetEntries(); for (cmDocumentationEntry const& entry : entries) { @@ -169,20 +169,20 @@ void cmDocumentationFormatter::PrintSection( this->TextIndent = " "; int align = static_cast(strlen(this->TextIndent)) - 4; for (int i = static_cast(entry.Name.size()); i < align; ++i) { - os << " "; + os << ' '; } if (entry.Name.size() > strlen(this->TextIndent) - 4) { - os << "\n"; + os << '\n'; os.write(this->TextIndent, strlen(this->TextIndent) - 2); } os << "= "; this->PrintColumn(os, entry.Brief.c_str()); - os << "\n"; + os << '\n'; } else { - os << "\n"; + os << '\n'; this->TextIndent = ""; this->PrintFormatted(os, entry.Brief.c_str()); } } - os << "\n"; + os << '\n'; } -- cgit v0.12 From 3bff44ffd3b37ba1e46205f66ac03d3363fddc51 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 07:33:02 +0400 Subject: cmDocumentationEntry.h: Drop unused constructor --- Source/cmDocumentationEntry.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Source/cmDocumentationEntry.h b/Source/cmDocumentationEntry.h index 89a2899..bad3b59 100644 --- a/Source/cmDocumentationEntry.h +++ b/Source/cmDocumentationEntry.h @@ -13,15 +13,6 @@ struct cmDocumentationEntry std::string Brief; char CustomNamePrefix = ' '; cmDocumentationEntry() = default; - cmDocumentationEntry(const char* doc[2]) - { - if (doc[0]) { - this->Name = doc[0]; - } - if (doc[1]) { - this->Brief = doc[1]; - } - } cmDocumentationEntry(const char* n, const char* b) { if (n) { -- cgit v0.12 From 3be0d77cc4ae10506fb513987067e9515169a401 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 07:55:30 +0400 Subject: cmDocumentationFormatter.h: No need `virtual` methods Can be added later it really need. Also, drop ctor/dtor to make the class trivially destructable. --- Source/cmDocumentationFormatter.cxx | 4 ---- Source/cmDocumentationFormatter.h | 10 +++------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index fdc6304..5773362 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -11,10 +11,6 @@ #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" -cmDocumentationFormatter::cmDocumentationFormatter() = default; - -cmDocumentationFormatter::~cmDocumentationFormatter() = default; - void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) { diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 98cac9b..ca7ad0c 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -12,14 +12,10 @@ class cmDocumentationSection; class cmDocumentationFormatter { public: - cmDocumentationFormatter(); - virtual ~cmDocumentationFormatter(); void PrintFormatted(std::ostream& os, const char* text); - - virtual void PrintSection(std::ostream& os, - cmDocumentationSection const& section); - virtual void PrintPreformatted(std::ostream& os, const char* text); - virtual void PrintParagraph(std::ostream& os, const char* text); + void PrintSection(std::ostream& os, cmDocumentationSection const& section); + void PrintPreformatted(std::ostream& os, const char* text); + void PrintParagraph(std::ostream& os, const char* text); void PrintColumn(std::ostream& os, const char* text); void SetIndent(const char* indent); -- cgit v0.12 From b0fe4036b7ec2aa7540c7080f14c921e9a485ae3 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 08:14:48 +0400 Subject: cmDocumentationFormatter: `PrintPreformatted` accept string Also, make it `const` method cuz it's not modify the state. --- Source/cmDocumentationFormatter.cxx | 28 +++++++++++++++------------- Source/cmDocumentationFormatter.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 5773362..8cf101c 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDocumentationFormatter.h" +#include #include #include #include @@ -10,6 +11,8 @@ #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" +#include "cmStringAlgorithms.h" +#include "cmSystemTools.h" void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) @@ -31,7 +34,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, } } if (!preformatted.empty()) { - this->PrintPreformatted(os, preformatted.c_str()); + this->PrintPreformatted(os, preformatted); } // Other ptrs are treated as paragraphs. @@ -50,20 +53,19 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, } void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, - const char* text) + std::string const& text) const { - bool newline = true; - for (const char* ptr = text; *ptr; ++ptr) { - if (newline && *ptr != '\n') { - os << this->TextIndent; - newline = false; - } - os << *ptr; - if (*ptr == '\n') { - newline = true; - } + assert(this->TextIndent); + + if (this->TextIndent[0]) { + auto indented = text; + cmSystemTools::ReplaceString(indented, "\n", + cmStrCat('\n', this->TextIndent)); + indented.insert(0u, this->TextIndent); + os << indented << '\n'; + } else { + os << text << '\n'; } - os << '\n'; } void cmDocumentationFormatter::PrintParagraph(std::ostream& os, diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index ca7ad0c..6f2ccb4 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -13,8 +13,8 @@ class cmDocumentationFormatter { public: void PrintFormatted(std::ostream& os, const char* text); + void PrintPreformatted(std::ostream& os, std::string const& text) const; void PrintSection(std::ostream& os, cmDocumentationSection const& section); - void PrintPreformatted(std::ostream& os, const char* text); void PrintParagraph(std::ostream& os, const char* text); void PrintColumn(std::ostream& os, const char* text); void SetIndent(const char* indent); -- cgit v0.12 From 5f3f8118363e4e483471733d1a89d6ae6ab179f1 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 08:40:41 +0400 Subject: cmDocumentationFormatter: `TextIndent` member is `std::string` now Was `const char*`. --- Source/cmDocumentationFormatter.cxx | 32 ++++++++++++++------------------ Source/cmDocumentationFormatter.h | 5 +++-- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 8cf101c..c6964d2 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -2,8 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDocumentationFormatter.h" +#include #include -#include #include #include #include @@ -14,6 +14,10 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" +namespace { +const std::string NAME_SIZED_PADDING = " "; +} + void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) { @@ -55,9 +59,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, std::string const& text) const { - assert(this->TextIndent); - - if (this->TextIndent[0]) { + if (!this->TextIndent.empty()) { auto indented = text; cmSystemTools::ReplaceString(indented, "\n", cmStrCat('\n', this->TextIndent)); @@ -76,11 +78,6 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os, os << '\n'; } -void cmDocumentationFormatter::SetIndent(const char* indent) -{ - this->TextIndent = indent; -} - void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) { // Print text arranged in an indented column of fixed width. @@ -88,7 +85,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) long column = 0; bool newSentence = false; bool firstLine = true; - int width = this->TextWidth - static_cast(strlen(this->TextIndent)); + int width = this->TextWidth - static_cast(this->TextIndent.size()); // Loop until the end of the text. while (*l) { @@ -112,10 +109,10 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) os << ' '; column += 1; } - } else { + } else if (!firstLine && !this->TextIndent.empty()) { // First word on line. Print indentation unless this is the // first line. - os << (firstLine ? "" : this->TextIndent); + os << this->TextIndent; } // Print the word. @@ -164,21 +161,20 @@ void cmDocumentationFormatter::PrintSection( for (cmDocumentationEntry const& entry : entries) { if (!entry.Name.empty()) { os << std::setw(2) << std::left << entry.CustomNamePrefix << entry.Name; - this->TextIndent = " "; - int align = static_cast(strlen(this->TextIndent)) - 4; + this->TextIndent = NAME_SIZED_PADDING; + int align = static_cast(this->TextIndent.size()) - 4; for (int i = static_cast(entry.Name.size()); i < align; ++i) { os << ' '; } - if (entry.Name.size() > strlen(this->TextIndent) - 4) { - os << '\n'; - os.write(this->TextIndent, strlen(this->TextIndent) - 2); + if (static_cast(entry.Name.size()) > align) { + os << '\n' << this->TextIndent.substr(0, this->TextIndent.size() - 2); } os << "= "; this->PrintColumn(os, entry.Brief.c_str()); os << '\n'; } else { os << '\n'; - this->TextIndent = ""; + this->TextIndent = {}; this->PrintFormatted(os, entry.Brief.c_str()); } } diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 6f2ccb4..003cf89 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -5,6 +5,7 @@ #include "cmConfigure.h" // IWYU pragma: keep #include +#include class cmDocumentationSection; @@ -17,9 +18,9 @@ public: void PrintSection(std::ostream& os, cmDocumentationSection const& section); void PrintParagraph(std::ostream& os, const char* text); void PrintColumn(std::ostream& os, const char* text); - void SetIndent(const char* indent); + void SetIndent(std::string indent) { this->TextIndent = std::move(indent); } private: int TextWidth = 77; - const char* TextIndent = ""; + std::string TextIndent = {}; }; -- cgit v0.12 From 1d6c8797fc5ec28f548defd9e8e2d3131e6f3036 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 09:11:34 +0400 Subject: cmDocumentationFormatter: Use `std::ostream` padding capabitily MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of manually print spaces to align fields. --- Source/cmDocumentationFormatter.cxx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index c6964d2..527e755 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -160,14 +160,13 @@ void cmDocumentationFormatter::PrintSection( const std::vector& entries = section.GetEntries(); for (cmDocumentationEntry const& entry : entries) { if (!entry.Name.empty()) { - os << std::setw(2) << std::left << entry.CustomNamePrefix << entry.Name; this->TextIndent = NAME_SIZED_PADDING; - int align = static_cast(this->TextIndent.size()) - 4; - for (int i = static_cast(entry.Name.size()); i < align; ++i) { - os << ' '; - } - if (static_cast(entry.Name.size()) > align) { - os << '\n' << this->TextIndent.substr(0, this->TextIndent.size() - 2); + os << std::setw(2) << std::left << entry.CustomNamePrefix + << std::setw( + int(std::max(this->TextIndent.size() - 4, entry.Name.size()))) + << entry.Name; + if (entry.Name.size() > (this->TextIndent.size() - 4)) { + os << '\n' << std::setw(int(this->TextIndent.size() - 2)) << ' '; } os << "= "; this->PrintColumn(os, entry.Brief.c_str()); -- cgit v0.12 From cf39773df94d474f9618f046be8fbc503dc7159d Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 09:40:22 +0400 Subject: cmDocumentationFormatter: Turn `TextIndent` member into `size_t` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of `std::string`. --- Source/cmDocumentation.cxx | 2 +- Source/cmDocumentationFormatter.cxx | 52 +++++++++++++++++++++---------------- Source/cmDocumentationFormatter.h | 4 +-- Source/cmMessenger.cxx | 2 +- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 77bc7c6..e8558fd 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -605,7 +605,7 @@ bool cmDocumentation::PrintHelpListGenerators(std::ostream& os) { const auto si = this->AllSections.find("Generators"); if (si != this->AllSections.end()) { - this->Formatter.SetIndent(" "); + this->Formatter.SetIndent(2u); this->Formatter.PrintSection(os, si->second); } return true; diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 527e755..e2c521d 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -7,17 +7,13 @@ #include #include #include +#include #include #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" -#include "cmStringAlgorithms.h" #include "cmSystemTools.h" -namespace { -const std::string NAME_SIZED_PADDING = " "; -} - void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) { @@ -59,11 +55,11 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, std::string const& text) const { - if (!this->TextIndent.empty()) { + if (this->TextIndent) { auto indented = text; - cmSystemTools::ReplaceString(indented, "\n", - cmStrCat('\n', this->TextIndent)); - indented.insert(0u, this->TextIndent); + auto padding = std::string(this->TextIndent, ' '); + cmSystemTools::ReplaceString(indented, "\n", "\n" + padding); + indented = std::move(padding) + indented; os << indented << '\n'; } else { os << text << '\n'; @@ -73,7 +69,9 @@ void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, void cmDocumentationFormatter::PrintParagraph(std::ostream& os, const char* text) { - os << this->TextIndent; + if (this->TextIndent) { + os << std::string(this->TextIndent, ' '); + } this->PrintColumn(os, text); os << '\n'; } @@ -85,7 +83,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) long column = 0; bool newSentence = false; bool firstLine = true; - int width = this->TextWidth - static_cast(this->TextIndent.size()); + int width = this->TextWidth - static_cast(this->TextIndent); // Loop until the end of the text. while (*l) { @@ -109,10 +107,10 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) os << ' '; column += 1; } - } else if (!firstLine && !this->TextIndent.empty()) { + } else if (!firstLine && this->TextIndent) { // First word on line. Print indentation unless this is the // first line. - os << this->TextIndent; + os << std::string(this->TextIndent, ' '); } // Print the word. @@ -135,7 +133,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) os << '\n'; firstLine = false; if (r > l) { - os << this->TextIndent; + os << std::string(this->TextIndent, ' '); os.write(l, static_cast(r - l)); column = static_cast(r - l); newSentence = (*(r - 1) == '.'); @@ -157,23 +155,31 @@ void cmDocumentationFormatter::PrintSection( { os << section.GetName() << '\n'; - const std::vector& entries = section.GetEntries(); - for (cmDocumentationEntry const& entry : entries) { + const std::size_t PREFIX_SIZE = + sizeof(cmDocumentationEntry::CustomNamePrefix) + 1u; + // length of the "= " literal (see below) + const std::size_t SUFFIX_SIZE = 2u; + // legacy magic number ;-) + const std::size_t NAME_SIZE = 29u; + + const std::size_t PADDING_SIZE = PREFIX_SIZE + SUFFIX_SIZE; + const std::size_t TITLE_SIZE = NAME_SIZE + PADDING_SIZE; + + for (cmDocumentationEntry const& entry : section.GetEntries()) { if (!entry.Name.empty()) { - this->TextIndent = NAME_SIZED_PADDING; - os << std::setw(2) << std::left << entry.CustomNamePrefix - << std::setw( - int(std::max(this->TextIndent.size() - 4, entry.Name.size()))) + this->TextIndent = TITLE_SIZE; + os << std::setw(PREFIX_SIZE) << std::left << entry.CustomNamePrefix + << std::setw(int(std::max(NAME_SIZE, entry.Name.size()))) << entry.Name; - if (entry.Name.size() > (this->TextIndent.size() - 4)) { - os << '\n' << std::setw(int(this->TextIndent.size() - 2)) << ' '; + if (entry.Name.size() > NAME_SIZE) { + os << '\n' << std::setw(int(this->TextIndent - PREFIX_SIZE)) << ' '; } os << "= "; this->PrintColumn(os, entry.Brief.c_str()); os << '\n'; } else { os << '\n'; - this->TextIndent = {}; + this->TextIndent = 0u; this->PrintFormatted(os, entry.Brief.c_str()); } } diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 003cf89..5293033 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -18,9 +18,9 @@ public: void PrintSection(std::ostream& os, cmDocumentationSection const& section); void PrintParagraph(std::ostream& os, const char* text); void PrintColumn(std::ostream& os, const char* text); - void SetIndent(std::string indent) { this->TextIndent = std::move(indent); } + void SetIndent(std::size_t indent) { this->TextIndent = indent; } private: int TextWidth = 77; - std::string TextIndent = {}; + std::size_t TextIndent = 0u; }; diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index 333003b..cae7216 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -107,7 +107,7 @@ static void printMessageText(std::ostream& msg, std::string const& text) { msg << ":\n"; cmDocumentationFormatter formatter; - formatter.SetIndent(" "); + formatter.SetIndent(2u); formatter.PrintFormatted(msg, text.c_str()); } -- cgit v0.12 From bbe854a45af977481772f50873e72ac9ba53805c Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 09:58:56 +0400 Subject: cmDocumentation: Drop useless call to formatter's `SetIndent()` The `cmDocumentationFormatter::PrintSection()` method ignores the currently set indentation level and use it's own. --- Source/cmDocumentation.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index e8558fd..9f9393d 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -605,7 +605,6 @@ bool cmDocumentation::PrintHelpListGenerators(std::ostream& os) { const auto si = this->AllSections.find("Generators"); if (si != this->AllSections.end()) { - this->Formatter.SetIndent(2u); this->Formatter.PrintSection(os, si->second); } return true; -- cgit v0.12 From 84241189f6a68611f79e9a3d78fc0192e1008cb1 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 10:00:53 +0400 Subject: cmDocumentationFormatter: Prevent indentation reset side effect Fix `cmDocumentationFormatter::PrintColumn()` method to eliminate an indentation reset side effect. --- Source/cmDocumentationFormatter.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index e2c521d..8f0976c 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -153,8 +153,6 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) void cmDocumentationFormatter::PrintSection( std::ostream& os, cmDocumentationSection const& section) { - os << section.GetName() << '\n'; - const std::size_t PREFIX_SIZE = sizeof(cmDocumentationEntry::CustomNamePrefix) + 1u; // length of the "= " literal (see below) @@ -165,6 +163,10 @@ void cmDocumentationFormatter::PrintSection( const std::size_t PADDING_SIZE = PREFIX_SIZE + SUFFIX_SIZE; const std::size_t TITLE_SIZE = NAME_SIZE + PADDING_SIZE; + const auto savedIndent = this->TextIndent; + + os << section.GetName() << '\n'; + for (cmDocumentationEntry const& entry : section.GetEntries()) { if (!entry.Name.empty()) { this->TextIndent = TITLE_SIZE; @@ -183,5 +185,8 @@ void cmDocumentationFormatter::PrintSection( this->PrintFormatted(os, entry.Brief.c_str()); } } + os << '\n'; + + this->TextIndent = savedIndent; } -- cgit v0.12 From f27537ec3db3a53a83da9d9824f10f139397476e Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 10:57:00 +0400 Subject: cmDocumentationFormatter: Turn `TextWidth` member into `size_t` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cuz normally required text width can't be negative. It was `int`… --- Source/cmDocumentationFormatter.cxx | 16 +++++++++------- Source/cmDocumentationFormatter.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 8f0976c..85276fc 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -80,10 +80,12 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) { // Print text arranged in an indented column of fixed width. const char* l = text; - long column = 0; bool newSentence = false; bool firstLine = true; - int width = this->TextWidth - static_cast(this->TextIndent); + + assert(this->TextIndent < this->TextWidth); + const std::ptrdiff_t width = this->TextWidth - this->TextIndent; + std::ptrdiff_t column = 0; // Loop until the end of the text. while (*l) { @@ -94,7 +96,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) } // Does it fit on this line? - if (r - l < (width - column - (newSentence ? 1 : 0))) { + if (r - l < width - column - std::ptrdiff_t(newSentence)) { // Word fits on this line. if (r > l) { if (column) { @@ -114,7 +116,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) } // Print the word. - os.write(l, static_cast(r - l)); + os.write(l, r - l); newSentence = (*(r - 1) == '.'); } @@ -126,7 +128,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) firstLine = false; } else { // No provided newline. Continue this line. - column += static_cast(r - l); + column += r - l; } } else { // Word does not fit on this line. Start a new line. @@ -134,8 +136,8 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) firstLine = false; if (r > l) { os << std::string(this->TextIndent, ' '); - os.write(l, static_cast(r - l)); - column = static_cast(r - l); + os.write(l, r - l); + column = r - l; newSentence = (*(r - 1) == '.'); } else { column = 0; diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 5293033..113db1e 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -21,6 +21,6 @@ public: void SetIndent(std::size_t indent) { this->TextIndent = indent; } private: - int TextWidth = 77; + std::size_t TextWidth = 77u; std::size_t TextIndent = 0u; }; -- cgit v0.12 From c802bfc548c82e13c916b7e14fc81daa1c733213 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 11:21:32 +0400 Subject: cmDocumentationFormatter: Eliminate one `if` in the `PrintColumn` loop --- Source/cmDocumentationFormatter.cxx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 85276fc..9d773e9 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -102,13 +102,8 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) if (column) { // Not first word on line. Separate from the previous word // by a space, or two if this is a new sentence. - if (newSentence) { - os << " "; - column += 2; - } else { - os << ' '; - column += 1; - } + os << &(" "[std::size_t(!newSentence)]); + column += 1u + std::ptrdiff_t(newSentence); } else if (!firstLine && this->TextIndent) { // First word on line. Print indentation unless this is the // first line. -- cgit v0.12 From 21c3e2107d101954d6e2e60bbd2d660c6d95a455 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 11:38:45 +0400 Subject: cmDocumentationFormatter: Turn `while ()` into `for ()` loop --- Source/cmDocumentationFormatter.cxx | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 9d773e9..daa78f1 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -14,14 +14,33 @@ #include "cmDocumentationSection.h" #include "cmSystemTools.h" +namespace { +const char* skipSpaces(const char* ptr) +{ + assert(ptr); + for (; *ptr == ' '; ++ptr) { + ; + } + return ptr; +} +const char* skipToSpace(const char* ptr) +{ + assert(ptr); + for (; *ptr && (*ptr != '\n') && (*ptr != ' '); ++ptr) { + ; + } + return ptr; +} +} + void cmDocumentationFormatter::PrintFormatted(std::ostream& os, const char* text) { if (!text) { return; } - const char* ptr = text; - while (*ptr) { + + for (const char* ptr = text; *ptr;) { // Any ptrs starting in a space are treated as preformatted text. std::string preformatted; while (*ptr == ' ') { @@ -79,7 +98,6 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os, void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) { // Print text arranged in an indented column of fixed width. - const char* l = text; bool newSentence = false; bool firstLine = true; @@ -88,13 +106,8 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) std::ptrdiff_t column = 0; // Loop until the end of the text. - while (*l) { - // Parse the next word. - const char* r = l; - while (*r && (*r != '\n') && (*r != ' ')) { - ++r; - } - + for (const char *l = text, *r = skipToSpace(text); *l; + l = skipSpaces(r), r = skipToSpace(l)) { // Does it fit on this line? if (r - l < width - column - std::ptrdiff_t(newSentence)) { // Word fits on this line. @@ -138,12 +151,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) column = 0; } } - // Move to beginning of next word. Skip over whitespace. - l = r; - while (*l == ' ') { - ++l; - } } } -- cgit v0.12 From 3feac60591ea0a4b010c7f21eb9e8854d159d9a0 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 11:58:44 +0400 Subject: cmDocumentationFormatter: All printing methods accept strings --- Source/cmDocumentationFormatter.cxx | 19 ++++++++++--------- Source/cmDocumentationFormatter.h | 6 +++--- Source/cmMessenger.cxx | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index daa78f1..6d170ab 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -34,13 +34,13 @@ const char* skipToSpace(const char* ptr) } void cmDocumentationFormatter::PrintFormatted(std::ostream& os, - const char* text) + std::string const& text) const { - if (!text) { + if (text.empty()) { return; } - for (const char* ptr = text; *ptr;) { + for (const char* ptr = text.c_str(); *ptr;) { // Any ptrs starting in a space are treated as preformatted text. std::string preformatted; while (*ptr == ' ') { @@ -66,7 +66,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, paragraph.append(1, '\n'); } if (!paragraph.empty()) { - this->PrintParagraph(os, paragraph.c_str()); + this->PrintParagraph(os, paragraph); } } } @@ -86,7 +86,7 @@ void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, } void cmDocumentationFormatter::PrintParagraph(std::ostream& os, - const char* text) + std::string const& text) const { if (this->TextIndent) { os << std::string(this->TextIndent, ' '); @@ -95,7 +95,8 @@ void cmDocumentationFormatter::PrintParagraph(std::ostream& os, os << '\n'; } -void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) +void cmDocumentationFormatter::PrintColumn(std::ostream& os, + std::string const& text) const { // Print text arranged in an indented column of fixed width. bool newSentence = false; @@ -106,7 +107,7 @@ void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text) std::ptrdiff_t column = 0; // Loop until the end of the text. - for (const char *l = text, *r = skipToSpace(text); *l; + for (const char *l = text.c_str(), *r = skipToSpace(text.c_str()); *l; l = skipSpaces(r), r = skipToSpace(l)) { // Does it fit on this line? if (r - l < width - column - std::ptrdiff_t(newSentence)) { @@ -182,12 +183,12 @@ void cmDocumentationFormatter::PrintSection( os << '\n' << std::setw(int(this->TextIndent - PREFIX_SIZE)) << ' '; } os << "= "; - this->PrintColumn(os, entry.Brief.c_str()); + this->PrintColumn(os, entry.Brief); os << '\n'; } else { os << '\n'; this->TextIndent = 0u; - this->PrintFormatted(os, entry.Brief.c_str()); + this->PrintFormatted(os, entry.Brief); } } diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index 113db1e..ca942bc 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -13,11 +13,11 @@ class cmDocumentationSection; class cmDocumentationFormatter { public: - void PrintFormatted(std::ostream& os, const char* text); + void PrintFormatted(std::ostream& os, std::string const& text) const; void PrintPreformatted(std::ostream& os, std::string const& text) const; void PrintSection(std::ostream& os, cmDocumentationSection const& section); - void PrintParagraph(std::ostream& os, const char* text); - void PrintColumn(std::ostream& os, const char* text); + void PrintParagraph(std::ostream& os, std::string const& text) const; + void PrintColumn(std::ostream& os, std::string const& text) const; void SetIndent(std::size_t indent) { this->TextIndent = indent; } private: diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index cae7216..ff513be 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -108,7 +108,7 @@ static void printMessageText(std::ostream& msg, std::string const& text) msg << ":\n"; cmDocumentationFormatter formatter; formatter.SetIndent(2u); - formatter.PrintFormatted(msg, text.c_str()); + formatter.PrintFormatted(msg, text); } static void displayMessage(MessageType t, std::ostringstream& msg) -- cgit v0.12 From 09fdfe5afa2983fb2a0297505f257d03227c9823 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 18:15:41 +0400 Subject: cmDocumentationFormatter: Improve `PrintFormatted` Instead of one char at time copy (append), use lines. --- Source/cmDocumentationFormatter.cxx | 88 +++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx index 6d170ab..70ba1fc 100644 --- a/Source/cmDocumentationFormatter.cxx +++ b/Source/cmDocumentationFormatter.cxx @@ -7,12 +7,10 @@ #include #include #include -#include #include #include "cmDocumentationEntry.h" #include "cmDocumentationSection.h" -#include "cmSystemTools.h" namespace { const char* skipSpaces(const char* ptr) @@ -40,33 +38,63 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, return; } - for (const char* ptr = text.c_str(); *ptr;) { - // Any ptrs starting in a space are treated as preformatted text. - std::string preformatted; - while (*ptr == ' ') { - for (char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr) { - preformatted.append(1, ch); - } - if (*ptr) { - ++ptr; - preformatted.append(1, '\n'); - } - } - if (!preformatted.empty()) { - this->PrintPreformatted(os, preformatted); + struct Buffer + { + // clang-format off + using PrinterFn = void (cmDocumentationFormatter::*)( + std::ostream&, std::string const& + ) const; + // clang-format on + std::string collected; + const PrinterFn printer; + }; + // const auto NORMAL_IDX = 0u; + const auto PREFORMATTED_IDX = 1u; + const auto HANDLERS_SIZE = 2u; + Buffer buffers[HANDLERS_SIZE] = { + { {}, &cmDocumentationFormatter::PrintParagraph }, + { {}, &cmDocumentationFormatter::PrintPreformatted } + }; + + const auto padding = std::string(this->TextIndent, ' '); + + for (std::size_t pos = 0u, eol = 0u; pos < text.size(); pos = eol) { + const auto current_idx = std::size_t(text[pos] == ' '); + // size_t(!bool(current_idx)) + const auto other_idx = current_idx ^ 1u; + + // Flush the other buffer if anything has been collected + if (!buffers[other_idx].collected.empty()) { + // NOTE Whatever the other index is, the current buffered + // string expected to be empty. + assert(buffers[current_idx].collected.empty()); + + (this->*buffers[other_idx].printer)(os, buffers[other_idx].collected); + buffers[other_idx].collected.clear(); } - // Other ptrs are treated as paragraphs. - std::string paragraph; - for (char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr) { - paragraph.append(1, ch); + // ATTENTION The previous implementation had called `PrintParagraph()` + // **for every processed (char by char) input line**. + // The method unconditionally append the `\n' character after the + // printed text. To keep the backward-compatible behavior it's needed to + // add the '\n' character to the previously collected line... + if (!buffers[current_idx].collected.empty() && + current_idx != PREFORMATTED_IDX) { + buffers[current_idx].collected += '\n'; } - if (*ptr) { - ++ptr; - paragraph.append(1, '\n'); + + // Lookup EOL + eol = text.find('\n', pos); + if (current_idx == PREFORMATTED_IDX) { + buffers[current_idx].collected.append(padding); } - if (!paragraph.empty()) { - this->PrintParagraph(os, paragraph); + buffers[current_idx].collected.append( + text, pos, eol == std::string::npos ? eol : ++eol - pos); + } + + for (auto& buf : buffers) { + if (!buf.collected.empty()) { + (this->*buf.printer)(os, buf.collected); } } } @@ -74,15 +102,7 @@ void cmDocumentationFormatter::PrintFormatted(std::ostream& os, void cmDocumentationFormatter::PrintPreformatted(std::ostream& os, std::string const& text) const { - if (this->TextIndent) { - auto indented = text; - auto padding = std::string(this->TextIndent, ' '); - cmSystemTools::ReplaceString(indented, "\n", "\n" + padding); - indented = std::move(padding) + indented; - os << indented << '\n'; - } else { - os << text << '\n'; - } + os << text << '\n'; } void cmDocumentationFormatter::PrintParagraph(std::ostream& os, -- cgit v0.12 From 067dcb9efdffab683ce0bd299db7bfb45eaef859 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 19:31:13 +0400 Subject: cmDocumentationSection: Accept `Iterable` instead of `vector` on add --- Source/cmDocumentationSection.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h index 276e520..e1b5454 100644 --- a/Source/cmDocumentationSection.h +++ b/Source/cmDocumentationSection.h @@ -4,11 +4,10 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include #include -#include - #include "cmDocumentationEntry.h" // Low-level interface for custom documents: @@ -45,9 +44,12 @@ public: { this->Entries.push_back(entry); } - void Append(const std::vector& entries) + + template + void Append(const Iterable& entries) { - cm::append(this->Entries, entries); + this->Entries.insert(std::end(this->Entries), std::begin(entries), + std::end(entries)); } /** Append an entry to this section using NULL terminated chars */ @@ -56,10 +58,12 @@ public: /** prepend some documentation to this section */ void Prepend(const char* [][2]); - void Prepend(const std::vector& entries) + + template + void Prepend(const Iterable& entries) { - this->Entries.insert(this->Entries.begin(), entries.begin(), - entries.end()); + this->Entries.insert(std::begin(this->Entries), std::begin(entries), + std::end(entries)); } private: -- cgit v0.12 From ccff0b87a28177cd9f298adc9b650e5143b371f6 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 19:33:09 +0400 Subject: cmDocumentation: Accept `Iterable` instead of `vector` on add entries --- Source/cmDocumentation.cxx | 20 -------------------- Source/cmDocumentation.h | 24 ++++++++++++++++++------ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 9f9393d..93685ad 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -373,14 +373,6 @@ void cmDocumentation::SetSection(const char* name, this->SectionAtName(name) = std::move(section); } -void cmDocumentation::SetSection(const char* name, - std::vector& docs) -{ - cmDocumentationSection sec{ name }; - sec.Append(docs); - this->SetSection(name, std::move(sec)); -} - void cmDocumentation::SetSection(const char* name, const char* docs[][2]) { cmDocumentationSection sec{ name }; @@ -406,24 +398,12 @@ void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) this->SectionAtName(name).Prepend(docs); } -void cmDocumentation::PrependSection(const char* name, - std::vector& docs) -{ - this->SectionAtName(name).Prepend(docs); -} - void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) { this->SectionAtName(name).Append(docs); } void cmDocumentation::AppendSection(const char* name, - std::vector& docs) -{ - this->SectionAtName(name).Append(docs); -} - -void cmDocumentation::AppendSection(const char* name, cmDocumentationEntry& docs) { diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 4055039..de5449a 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "cmDocumentationFormatter.h" @@ -74,19 +75,30 @@ public: /** Set a section of the documentation. Typical sections include Name, Usage, Description, Options */ void SetSection(const char* sectionName, cmDocumentationSection section); - void SetSection(const char* sectionName, - std::vector& docs); + template + void SetSection(const char* sectionName, const Iterable& docs) + { + cmDocumentationSection sec{ sectionName }; + sec.Append(docs); + this->SetSection(sectionName, std::move(sec)); + } void SetSection(const char* sectionName, const char* docs[][2]); void SetSections(std::map sections); /** Add the documentation to the beginning/end of the section */ void PrependSection(const char* sectionName, const char* docs[][2]); - void PrependSection(const char* sectionName, - std::vector& docs); + template + void PrependSection(const char* sectionName, const Iterable& docs) + { + this->SectionAtName(sectionName).Prepend(docs); + } void PrependSection(const char* sectionName, cmDocumentationEntry& docs); void AppendSection(const char* sectionName, const char* docs[][2]); - void AppendSection(const char* sectionName, - std::vector& docs); + template + void AppendSection(const char* sectionName, const Iterable& docs) + { + this->SectionAtName(sectionName).Append(docs); + } void AppendSection(const char* sectionName, cmDocumentationEntry& docs); /** Add common (to all tools) documentation section(s) */ -- cgit v0.12 From 95a3d91e5ce2388b5c0e6ea4e4e3663477975a96 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 20:06:48 +0400 Subject: cmakemain.cxx: Remove always true preprocessor `#if` block --- Source/cmakemain.cxx | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 9f23667..c082b67 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -113,14 +113,12 @@ const char* cmDocumentationOptions[][2] = { { "--compile-no-warning-as-error", "Ignore COMPILE_WARNING_AS_ERROR property and " "CMAKE_COMPILE_WARNING_AS_ERROR variable." }, -# if !defined(CMAKE_BOOTSTRAP) { "--profiling-format=", "Output data for profiling CMake scripts. Supported formats: " "google-trace" }, { "--profiling-output=", "Select an output path for the profiling data enabled through " "--profiling-format." }, -# endif { nullptr, nullptr } }; -- cgit v0.12 From fddc48dd2696a8530f03616f21d98e7dab8bc96f Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 20:17:09 +0400 Subject: ctest.cxx: Use anonymous namespace instead of `static` arrays --- Source/ctest.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 363f473..eba6d82 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -16,16 +16,16 @@ #include "CTest/cmCTestLaunch.h" #include "CTest/cmCTestScriptHandler.h" -static const char* cmDocumentationName[][2] = { +namespace { +const char* cmDocumentationName[][2] = { { nullptr, " ctest - Testing driver provided by CMake." }, { nullptr, nullptr } }; -static const char* cmDocumentationUsage[][2] = { { nullptr, - " ctest [options]" }, - { nullptr, nullptr } }; +const char* cmDocumentationUsage[][2] = { { nullptr, " ctest [options]" }, + { nullptr, nullptr } }; -static const char* cmDocumentationOptions[][2] = { +const char* cmDocumentationOptions[][2] = { { "--preset , --preset=", "Read arguments from a test preset." }, { "--list-presets", "List available test presets." }, @@ -158,6 +158,7 @@ static const char* cmDocumentationOptions[][2] = { "Regard no tests found either as 'error' or 'ignore' it." }, { nullptr, nullptr } }; +} // anonymous namespace // this is a test driver program for cmCTest. int main(int argc, char const* const* argv) -- cgit v0.12 From 9ae6569bfe0d1e68761e8f55b5ea9e905cc0369f Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 20:21:26 +0400 Subject: ctest.cxx: Optimize `std::ostream::operator<<` calls --- Source/ctest.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/ctest.cxx b/Source/ctest.cxx index eba6d82..6310595 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -187,8 +187,7 @@ int main(int argc, char const* const* argv) if (cmSystemTools::GetCurrentWorkingDirectory().empty()) { cmCTestLog(&inst, ERROR_MESSAGE, - "Current working directory cannot be established." - << std::endl); + "Current working directory cannot be established.\n"); return 1; } @@ -200,10 +199,9 @@ int main(int argc, char const* const* argv) cmSystemTools::FileExists("DartTestfile.txt"))) { if (argc == 1) { cmCTestLog(&inst, ERROR_MESSAGE, - "*********************************" - << std::endl - << "No test configuration file found!" << std::endl - << "*********************************" << std::endl); + "*********************************\n" + "No test configuration file found!\n" + "*********************************\n"); } cmDocumentation doc; doc.addCTestStandardDocSections(); -- cgit v0.12 From 8e2a03c07833f8715a498ee11d32f3345985c163 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 20:22:30 +0400 Subject: ctest.cxx: Eliminate redundand trenary operator --- Source/QtDialog/CMakeSetup.cxx | 2 +- Source/cmakemain.cxx | 2 +- Source/ctest.cxx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 591b793..a15ec81 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -91,7 +91,7 @@ int main(int argc, char** argv) doc.AppendSection("Generators", generators); doc.PrependSection("Options", cmDocumentationOptions); - return (doc.PrintRequestedDocumentation(std::cout) ? 0 : 1); + return !doc.PrintRequestedDocumentation(std::cout); } #if defined(Q_OS_MAC) diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index c082b67..3f1fe6c 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -227,7 +227,7 @@ int do_cmake(int ac, char const* const* av) doc.AppendSection("Generators", generators); doc.PrependSection("Options", cmDocumentationOptions); - return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; + return !doc.PrintRequestedDocumentation(std::cout); } #else if (ac == 1) { diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 6310595..9e632df 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -215,7 +215,7 @@ int main(int argc, char const* const* argv) doc.SetSection("Name", cmDocumentationName); doc.SetSection("Usage", cmDocumentationUsage); doc.PrependSection("Options", cmDocumentationOptions); - return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; + return !doc.PrintRequestedDocumentation(std::cout); } } -- cgit v0.12 From 96dcfa6b446e5e94143b2d83c587d09b0d00031f Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 20:31:35 +0400 Subject: ccmake.cxx: Use anonymous namespace instead of `static` --- Source/CursesDialog/ccmake.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index 70ed648..2986265 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -23,12 +23,13 @@ #include "cmSystemTools.h" #include "cmake.h" -static const char* cmDocumentationName[][2] = { +namespace { +const char* cmDocumentationName[][2] = { { nullptr, " ccmake - Curses Interface for CMake." }, { nullptr, nullptr } }; -static const char* cmDocumentationUsage[][2] = { +const char* cmDocumentationUsage[][2] = { { nullptr, " ccmake \n" " ccmake " }, @@ -39,22 +40,18 @@ static const char* cmDocumentationUsage[][2] = { { nullptr, nullptr } }; -static const char* cmDocumentationUsageNote[][2] = { +const char* cmDocumentationUsageNote[][2] = { { nullptr, "Run 'ccmake --help' for more information." }, { nullptr, nullptr } }; -static const char* cmDocumentationOptions[][2] = { - CMAKE_STANDARD_OPTIONS_TABLE, - { nullptr, nullptr } -}; - -cmCursesForm* cmCursesForm::CurrentForm = nullptr; +const char* cmDocumentationOptions[][2] = { CMAKE_STANDARD_OPTIONS_TABLE, + { nullptr, nullptr } }; #ifndef _WIN32 extern "C" { -static void onsig(int /*unused*/) +void onsig(int /*unused*/) { if (cmCursesForm::CurrentForm) { cmCursesForm::CurrentForm->HandleResize(); @@ -63,6 +60,9 @@ static void onsig(int /*unused*/) } } #endif // _WIN32 +} // anonymous namespace + +cmCursesForm* cmCursesForm::CurrentForm = nullptr; int main(int argc, char const* const* argv) { -- cgit v0.12 From 807aa8e35382ab55120ccb1e6ae88523ad7ee5a3 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 21:21:40 +0400 Subject: CMakeSetup.cxx: Use anonymous namespace instead of `static` --- Source/QtDialog/CMakeSetup.cxx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index a15ec81..3113d64 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -22,11 +22,12 @@ #include "cmSystemTools.h" // IWYU pragma: keep #include "cmake.h" -static const char* cmDocumentationName[][2] = { { nullptr, - " cmake-gui - CMake GUI." }, - { nullptr, nullptr } }; +namespace { +const char* cmDocumentationName[][2] = { { nullptr, + " cmake-gui - CMake GUI." }, + { nullptr, nullptr } }; -static const char* cmDocumentationUsage[][2] = { +const char* cmDocumentationUsage[][2] = { { nullptr, " cmake-gui [options]\n" " cmake-gui [options] \n" @@ -36,12 +37,13 @@ static const char* cmDocumentationUsage[][2] = { { nullptr, nullptr } }; -static const char* cmDocumentationOptions[][2] = { +const char* cmDocumentationOptions[][2] = { { "-S ", "Explicitly specify a source directory." }, { "-B ", "Explicitly specify a build directory." }, { "--preset=", "Specify a configure preset." }, { nullptr, nullptr } }; +} // anonymous namespace #if defined(Q_OS_MAC) static int cmOSXInstall(std::string dir); @@ -252,6 +254,7 @@ int main(int argc, char** argv) # include # include "cm_sys_stat.h" + static bool cmOSXInstall(std::string const& dir, std::string const& tool) { if (tool.empty()) { @@ -277,6 +280,7 @@ static bool cmOSXInstall(std::string const& dir, std::string const& tool) << "': " << strerror(err) << "\n"; return false; } + static int cmOSXInstall(std::string dir) { if (!cmHasLiteralSuffix(dir, "/")) { -- cgit v0.12 From 74b735dea8e2255c53f12afea5706ad443d64785 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 21:39:53 +0400 Subject: =?UTF-8?q?cmDocumentation:=20`char*[][2]`=20=E2=86=92=20`cmDocume?= =?UTF-8?q?ntationEntry[N]`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use fixed size arrays of `cmDocumentationEntry` items instead of open arrays of two `char` pointers when describe program options help screens. Also, drop `const char*[][2]` overloads of methods of `cmDocumentation` and `cmDocumentationSection` classes in the sake of generic (template) appenders introduced earlier. --- Source/CMakeLists.txt | 1 - Source/CPack/cpack.cxx | 19 ++++++------------- Source/CursesDialog/ccmake.cxx | 22 ++++++++-------------- Source/QtDialog/CMakeSetup.cxx | 28 +++++++++++++--------------- Source/cmDocumentation.cxx | 36 ++++++++---------------------------- Source/cmDocumentation.h | 3 --- Source/cmDocumentationEntry.h | 2 +- Source/cmDocumentationSection.cxx | 28 ---------------------------- Source/cmDocumentationSection.h | 8 ++++---- Source/cmake.cxx | 27 ++++++++++++++++++++++++++- Source/cmake.h | 35 ++++------------------------------- Source/cmakemain.cxx | 24 ++++++++++-------------- Source/ctest.cxx | 15 +++++++-------- 13 files changed, 87 insertions(+), 161 deletions(-) delete mode 100644 Source/cmDocumentationSection.cxx diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index c268a92..c0709c6 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -196,7 +196,6 @@ add_library( cmDependsCompiler.h cmDocumentation.cxx cmDocumentationFormatter.cxx - cmDocumentationSection.cxx cmDynamicLoader.cxx cmDynamicLoader.h cmELF.h diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index f06946b..efb549f 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -25,7 +25,6 @@ #include "cmConsoleBuf.h" #include "cmDocumentation.h" #include "cmDocumentationEntry.h" -#include "cmDocumentationFormatter.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmState.h" @@ -36,19 +35,14 @@ #include "cmake.h" namespace { -const char* cmDocumentationName[][2] = { - { nullptr, " cpack - Packaging driver provided by CMake." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationName = { + nullptr, " cpack - Packaging driver provided by CMake." }; -const char* cmDocumentationUsage[][2] = { - // clang-format off - { nullptr, " cpack [options]" }, - { nullptr, nullptr } - // clang-format on -}; +const cmDocumentationEntry cmDocumentationUsage = { nullptr, + " cpack [options]" }; -const char* cmDocumentationOptions[][2] = { +const cmDocumentationEntry cmDocumentationOptions[14] = { { "-G ", "Override/define CPACK_GENERATOR" }, { "-C ", "Specify the project configuration" }, { "-D =", "Set a CPack variable." }, @@ -62,8 +56,7 @@ const char* cmDocumentationOptions[][2] = { { "-B ", "Override/define CPACK_PACKAGE_DIRECTORY" }, { "--vendor ", "Override/define CPACK_PACKAGE_VENDOR" }, { "--preset", "Read arguments from a package preset" }, - { "--list-presets", "List available package presets" }, - { nullptr, nullptr } + { "--list-presets", "List available package presets" } }; void cpackProgressCallback(const std::string& message, float /*unused*/) diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index 2986265..d61954a 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -16,7 +16,7 @@ #include "cmCursesMainForm.h" #include "cmCursesStandardIncludes.h" #include "cmDocumentation.h" -#include "cmDocumentationEntry.h" // IWYU pragma: keep +#include "cmDocumentationEntry.h" #include "cmMessageMetadata.h" #include "cmState.h" #include "cmStringAlgorithms.h" @@ -24,12 +24,11 @@ #include "cmake.h" namespace { -const char* cmDocumentationName[][2] = { - { nullptr, " ccmake - Curses Interface for CMake." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationName = { + nullptr, " ccmake - Curses Interface for CMake." }; -const char* cmDocumentationUsage[][2] = { +const cmDocumentationEntry cmDocumentationUsage[2] = { { nullptr, " ccmake \n" " ccmake " }, @@ -37,17 +36,12 @@ const char* cmDocumentationUsage[][2] = { "Specify a source directory to (re-)generate a build system for " "it in the current working directory. Specify an existing build " "directory to re-generate its build system." }, - { nullptr, nullptr } }; -const char* cmDocumentationUsageNote[][2] = { - { nullptr, "Run 'ccmake --help' for more information." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationUsageNote = { + nullptr, "Run 'ccmake --help' for more information." }; -const char* cmDocumentationOptions[][2] = { CMAKE_STANDARD_OPTIONS_TABLE, - { nullptr, nullptr } }; - #ifndef _WIN32 extern "C" { @@ -89,8 +83,8 @@ int main(int argc, char const* const* argv) doc.AppendSection("Usage", cmDocumentationUsageNote); } doc.AppendSection("Generators", generators); - doc.PrependSection("Options", cmDocumentationOptions); - return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; + doc.PrependSection("Options", cmake::CMAKE_STANDARD_OPTIONS_TABLE); + return !doc.PrintRequestedDocumentation(std::cout); } bool debug = false; diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 3113d64..11f7fe6 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -23,25 +23,23 @@ #include "cmake.h" namespace { -const char* cmDocumentationName[][2] = { { nullptr, - " cmake-gui - CMake GUI." }, - { nullptr, nullptr } }; - -const char* cmDocumentationUsage[][2] = { - { nullptr, - " cmake-gui [options]\n" - " cmake-gui [options] \n" - " cmake-gui [options] \n" - " cmake-gui [options] -S -B \n" - " cmake-gui [options] --browse-manual\n" }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationName = { + nullptr, " cmake-gui - CMake GUI." }; -const char* cmDocumentationOptions[][2] = { +const cmDocumentationEntry cmDocumentationUsage = { + nullptr, + " cmake-gui [options]\n" + " cmake-gui [options] \n" + " cmake-gui [options] \n" + " cmake-gui [options] -S -B \n" + " cmake-gui [options] --browse-manual" +}; + +const cmDocumentationEntry cmDocumentationOptions[3] = { { "-S ", "Explicitly specify a source directory." }, { "-B ", "Explicitly specify a build directory." }, - { "--preset=", "Specify a configure preset." }, - { nullptr, nullptr } + { "--preset=", "Specify a configure preset." } }; } // anonymous namespace diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 93685ad..5db8e49 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -17,7 +17,7 @@ #include "cmVersion.h" namespace { -const char* cmDocumentationStandardOptions[][2] = { +const cmDocumentationEntry cmDocumentationStandardOptions[20] = { { "-h,-H,--help,-help,-usage,/?", "Print usage information and exit." }, { "--version,-version,/V []", "Print version number and exit." }, { "--help-full []", "Print all help manuals and exit." }, @@ -43,20 +43,17 @@ const char* cmDocumentationStandardOptions[][2] = { { "--help-variable var []", "Print help for one variable and exit." }, { "--help-variable-list []", "List variables with help available and exit." }, - { "--help-variables []", "Print cmake-variables manual and exit." }, - { nullptr, nullptr } + { "--help-variables []", "Print cmake-variables manual and exit." } }; -const char* cmDocumentationCPackGeneratorsHeader[][2] = { - { nullptr, "The following generators are available on this platform:" }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationCPackGeneratorsHeader = { + nullptr, "The following generators are available on this platform:" }; -const char* cmDocumentationCMakeGeneratorsHeader[][2] = { - { nullptr, - "The following generators are available on this platform (* marks " - "default):" }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationCMakeGeneratorsHeader = { + nullptr, + "The following generators are available on this platform (* marks " + "default):" }; bool isOption(const char* arg) @@ -373,13 +370,6 @@ void cmDocumentation::SetSection(const char* name, this->SectionAtName(name) = std::move(section); } -void cmDocumentation::SetSection(const char* name, const char* docs[][2]) -{ - cmDocumentationSection sec{ name }; - sec.Append(docs); - this->SetSection(name, std::move(sec)); -} - void cmDocumentation::SetSections( std::map sections) { @@ -393,16 +383,6 @@ cmDocumentationSection& cmDocumentation::SectionAtName(const char* name) .first->second; } -void cmDocumentation::PrependSection(const char* name, const char* docs[][2]) -{ - this->SectionAtName(name).Prepend(docs); -} - -void cmDocumentation::AppendSection(const char* name, const char* docs[][2]) -{ - this->SectionAtName(name).Append(docs); -} - void cmDocumentation::AppendSection(const char* name, cmDocumentationEntry& docs) { diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index de5449a..f878acb 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -82,18 +82,15 @@ public: sec.Append(docs); this->SetSection(sectionName, std::move(sec)); } - void SetSection(const char* sectionName, const char* docs[][2]); void SetSections(std::map sections); /** Add the documentation to the beginning/end of the section */ - void PrependSection(const char* sectionName, const char* docs[][2]); template void PrependSection(const char* sectionName, const Iterable& docs) { this->SectionAtName(sectionName).Prepend(docs); } void PrependSection(const char* sectionName, cmDocumentationEntry& docs); - void AppendSection(const char* sectionName, const char* docs[][2]); template void AppendSection(const char* sectionName, const Iterable& docs) { diff --git a/Source/cmDocumentationEntry.h b/Source/cmDocumentationEntry.h index bad3b59..aa97391 100644 --- a/Source/cmDocumentationEntry.h +++ b/Source/cmDocumentationEntry.h @@ -13,7 +13,7 @@ struct cmDocumentationEntry std::string Brief; char CustomNamePrefix = ' '; cmDocumentationEntry() = default; - cmDocumentationEntry(const char* n, const char* b) + cmDocumentationEntry(const char* const n, const char* const b) { if (n) { this->Name = n; diff --git a/Source/cmDocumentationSection.cxx b/Source/cmDocumentationSection.cxx deleted file mode 100644 index 439da1b..0000000 --- a/Source/cmDocumentationSection.cxx +++ /dev/null @@ -1,28 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmDocumentationSection.h" - -void cmDocumentationSection::Append(const char* data[][2]) -{ - int i = 0; - while (data[i][1]) { - this->Entries.emplace_back(data[i][0], data[i][1]); - data += 1; - } -} - -void cmDocumentationSection::Prepend(const char* data[][2]) -{ - std::vector tmp; - int i = 0; - while (data[i][1]) { - tmp.emplace_back(data[i][0], data[i][1]); - data += 1; - } - this->Entries.insert(this->Entries.begin(), tmp.begin(), tmp.end()); -} - -void cmDocumentationSection::Append(const char* n, const char* b) -{ - this->Entries.emplace_back(n, b); -} diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h index e1b5454..b80131d 100644 --- a/Source/cmDocumentationSection.h +++ b/Source/cmDocumentationSection.h @@ -53,12 +53,12 @@ public: } /** Append an entry to this section using NULL terminated chars */ - void Append(const char* [][2]); - void Append(const char* n, const char* b); + void Append(const char* n, const char* b) + { + this->Entries.emplace_back(n, b); + } /** prepend some documentation to this section */ - void Prepend(const char* [][2]); - template void Prepend(const Iterable& entries) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 36c0089..cec3e97 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -40,7 +40,6 @@ #include "cmCommands.h" #include "cmDocumentation.h" #include "cmDocumentationEntry.h" -#include "cmDocumentationFormatter.h" #include "cmDuration.h" #include "cmExternalMakefileProjectGenerator.h" #include "cmFileTimeCache.h" @@ -165,6 +164,32 @@ static void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/, } #endif +cmDocumentationEntry cmake::CMAKE_STANDARD_OPTIONS_TABLE[18] = { + { "-S ", "Explicitly specify a source directory." }, + { "-B ", "Explicitly specify a build directory." }, + { "-C ", "Pre-load a script to populate the cache." }, + { "-D [:]=", "Create or update a cmake cache entry." }, + { "-U ", "Remove matching entries from CMake cache." }, + { "-G ", "Specify a build system generator." }, + { "-T ", "Specify toolset name if supported by generator." }, + { "-A ", "Specify platform name if supported by generator." }, + { "--toolchain ", "Specify toolchain file [CMAKE_TOOLCHAIN_FILE]." }, + { "--install-prefix ", + "Specify install directory [CMAKE_INSTALL_PREFIX]." }, + { "-Wdev", "Enable developer warnings." }, + { "-Wno-dev", "Suppress developer warnings." }, + { "-Werror=dev", "Make developer warnings errors." }, + { "-Wno-error=dev", "Make developer warnings not errors." }, + { "-Wdeprecated", "Enable deprecation warnings." }, + { "-Wno-deprecated", "Suppress deprecation warnings." }, + { "-Werror=deprecated", + "Make deprecated macro and function warnings " + "errors." }, + { "-Wno-error=deprecated", + "Make deprecated macro and function warnings " + "not errors." } +}; + cmake::cmake(Role role, cmState::Mode mode, cmState::ProjectKind projectKind) : CMakeWorkingDirectory(cmSystemTools::GetCurrentWorkingDirectory()) , FileTimeCache(cm::make_unique()) diff --git a/Source/cmake.h b/Source/cmake.h index 6b585a1..325c0c5 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -18,6 +18,7 @@ #include #include +#include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmInstalledFile.h" #include "cmListFileCache.h" @@ -45,7 +46,6 @@ class cmMakefile; class cmMessenger; class cmVariableWatch; struct cmBuildOptions; -struct cmDocumentationEntry; /** \brief Represents a cmake invocation. * @@ -793,37 +793,10 @@ private: #if !defined(CMAKE_BOOTSTRAP) std::unique_ptr ProfilingOutput; #endif -}; -#define CMAKE_STANDARD_OPTIONS_TABLE \ - { "-S ", "Explicitly specify a source directory." }, \ - { "-B ", "Explicitly specify a build directory." }, \ - { "-C ", "Pre-load a script to populate the cache." }, \ - { "-D [:]=", "Create or update a cmake cache entry." }, \ - { "-U ", "Remove matching entries from CMake cache." }, \ - { "-G ", "Specify a build system generator." }, \ - { "-T ", \ - "Specify toolset name if supported by generator." }, \ - { "-A ", \ - "Specify platform name if supported by generator." }, \ - { "--toolchain ", \ - "Specify toolchain file [CMAKE_TOOLCHAIN_FILE]." }, \ - { "--install-prefix ", \ - "Specify install directory [CMAKE_INSTALL_PREFIX]." }, \ - { "-Wdev", "Enable developer warnings." }, \ - { "-Wno-dev", "Suppress developer warnings." }, \ - { "-Werror=dev", "Make developer warnings errors." }, \ - { "-Wno-error=dev", "Make developer warnings not errors." }, \ - { "-Wdeprecated", "Enable deprecation warnings." }, \ - { "-Wno-deprecated", "Suppress deprecation warnings." }, \ - { "-Werror=deprecated", \ - "Make deprecated macro and function warnings " \ - "errors." }, \ - { \ - "-Wno-error=deprecated", \ - "Make deprecated macro and function warnings " \ - "not errors." \ - } +public: + static cmDocumentationEntry CMAKE_STANDARD_OPTIONS_TABLE[18]; +}; #define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes) diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 3f1fe6c..1ca3e55 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -24,7 +24,7 @@ #include "cmBuildOptions.h" #include "cmCommandLineArgument.h" #include "cmConsoleBuf.h" -#include "cmDocumentationEntry.h" // IWYU pragma: keep +#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmMessageMetadata.h" @@ -46,12 +46,11 @@ namespace { #ifndef CMAKE_BOOTSTRAP -const char* cmDocumentationName[][2] = { - { nullptr, " cmake - Cross-Platform Makefile Generator." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationName = { + nullptr, " cmake - Cross-Platform Makefile Generator." }; -const char* cmDocumentationUsage[][2] = { +const cmDocumentationEntry cmDocumentationUsage[2] = { { nullptr, " cmake [options] \n" " cmake [options] \n" @@ -59,17 +58,14 @@ const char* cmDocumentationUsage[][2] = { { nullptr, "Specify a source directory to (re-)generate a build system for " "it in the current working directory. Specify an existing build " - "directory to re-generate its build system." }, - { nullptr, nullptr } + "directory to re-generate its build system." } }; -const char* cmDocumentationUsageNote[][2] = { - { nullptr, "Run 'cmake --help' for more information." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationUsageNote = { + nullptr, "Run 'cmake --help' for more information." }; -const char* cmDocumentationOptions[][2] = { - CMAKE_STANDARD_OPTIONS_TABLE, +const cmDocumentationEntry cmDocumentationOptions[31] = { { "--preset ,--preset=", "Specify a configure preset." }, { "--list-presets[=]", "List available presets." }, { "-E", "CMake command mode." }, @@ -118,8 +114,7 @@ const char* cmDocumentationOptions[][2] = { "google-trace" }, { "--profiling-output=", "Select an output path for the profiling data enabled through " - "--profiling-format." }, - { nullptr, nullptr } + "--profiling-format." } }; #endif @@ -226,6 +221,7 @@ int do_cmake(int ac, char const* const* av) } doc.AppendSection("Generators", generators); doc.PrependSection("Options", cmDocumentationOptions); + doc.PrependSection("Options", cmake::CMAKE_STANDARD_OPTIONS_TABLE); return !doc.PrintRequestedDocumentation(std::cout); } diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 9e632df..d26a0d7 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -11,21 +11,21 @@ #include "cmCTest.h" #include "cmConsoleBuf.h" #include "cmDocumentation.h" +#include "cmDocumentationEntry.h" #include "cmSystemTools.h" #include "CTest/cmCTestLaunch.h" #include "CTest/cmCTestScriptHandler.h" namespace { -const char* cmDocumentationName[][2] = { - { nullptr, " ctest - Testing driver provided by CMake." }, - { nullptr, nullptr } +const cmDocumentationEntry cmDocumentationName = { + nullptr, " ctest - Testing driver provided by CMake." }; -const char* cmDocumentationUsage[][2] = { { nullptr, " ctest [options]" }, - { nullptr, nullptr } }; +const cmDocumentationEntry cmDocumentationUsage = { nullptr, + " ctest [options]" }; -const char* cmDocumentationOptions[][2] = { +const cmDocumentationEntry cmDocumentationOptions[74] = { { "--preset , --preset=", "Read arguments from a test preset." }, { "--list-presets", "List available test presets." }, @@ -155,8 +155,7 @@ const char* cmDocumentationOptions[][2] = { { "--no-compress-output", "Do not compress test output when submitting." }, { "--print-labels", "Print all available test labels." }, { "--no-tests=<[error|ignore]>", - "Regard no tests found either as 'error' or 'ignore' it." }, - { nullptr, nullptr } + "Regard no tests found either as 'error' or 'ignore' it." } }; } // anonymous namespace -- cgit v0.12 From 5ef97a0182e72abd12f19b0d396ff8b77324772f Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 22:03:01 +0400 Subject: cmDocumentation: Drop unused `SetSections` method --- Source/cmDocumentation.cxx | 7 ------- Source/cmDocumentation.h | 1 - 2 files changed, 8 deletions(-) diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 5db8e49..e626f7e 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -370,13 +370,6 @@ void cmDocumentation::SetSection(const char* name, this->SectionAtName(name) = std::move(section); } -void cmDocumentation::SetSections( - std::map sections) -{ - for (auto& s : sections) { - this->SetSection(s.first.c_str(), std::move(s.second)); - } -} cmDocumentationSection& cmDocumentation::SectionAtName(const char* name) { return this->AllSections.emplace(name, cmDocumentationSection{ name }) diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index f878acb..6930986 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -82,7 +82,6 @@ public: sec.Append(docs); this->SetSection(sectionName, std::move(sec)); } - void SetSections(std::map sections); /** Add the documentation to the beginning/end of the section */ template -- cgit v0.12 From e06bd68b36d675465a46196194efa55aecd81d08 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 22:08:25 +0400 Subject: cmDocumentationFormatter: Hide internal methods into `private` section --- Source/cmDocumentationFormatter.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h index ca942bc..e269f6a 100644 --- a/Source/cmDocumentationFormatter.h +++ b/Source/cmDocumentationFormatter.h @@ -13,14 +13,15 @@ class cmDocumentationSection; class cmDocumentationFormatter { public: + void SetIndent(std::size_t indent) { this->TextIndent = indent; } void PrintFormatted(std::ostream& os, std::string const& text) const; - void PrintPreformatted(std::ostream& os, std::string const& text) const; void PrintSection(std::ostream& os, cmDocumentationSection const& section); - void PrintParagraph(std::ostream& os, std::string const& text) const; - void PrintColumn(std::ostream& os, std::string const& text) const; - void SetIndent(std::size_t indent) { this->TextIndent = indent; } private: + void PrintPreformatted(std::ostream& os, std::string const&) const; + void PrintParagraph(std::ostream& os, std::string const&) const; + void PrintColumn(std::ostream& os, std::string const&) const; + std::size_t TextWidth = 77u; std::size_t TextIndent = 0u; }; -- cgit v0.12 From 439d2cf9cb79884747b3d3d56f83b044a108c40a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 23 Aug 2022 22:21:12 +0400 Subject: cmake.cxx: Optimize calls to `std::osteam::operator<<` --- Source/cmake.cxx | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index cec3e97..920687d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1033,7 +1033,7 @@ void cmake::SetArgs(const std::vector& args) std::cout << "Running with debug output on for the 'find' commands " "for package(s)"; for (auto const& v : find_pkgs) { - std::cout << " " << v; + std::cout << ' ' << v; state->SetDebugFindOutputPkgs(v); } std::cout << ".\n"; @@ -1046,7 +1046,7 @@ void cmake::SetArgs(const std::vector& args) std::vector find_vars(cmTokenize(value, ",")); std::cout << "Running with debug output on for the variable(s)"; for (auto const& v : find_vars) { - std::cout << " " << v; + std::cout << ' ' << v; state->SetDebugFindOutputVars(v); } std::cout << ".\n"; @@ -1107,7 +1107,7 @@ void cmake::SetArgs(const std::vector& args) [](std::string const&, cmake* state) -> bool { std::cout << "Not searching for unused variables given on the " - << "command line.\n"; + "command line.\n"; state->SetWarnUnusedCli(false); return true; } }, @@ -1115,7 +1115,7 @@ void cmake::SetArgs(const std::vector& args) "--check-system-vars", CommandArgument::Values::Zero, [](std::string const&, cmake* state) -> bool { std::cout << "Also check system files when warning about unused and " - << "uninitialized variables.\n"; + "uninitialized variables.\n"; state->SetCheckSystemVars(true); return true; } }, @@ -1123,7 +1123,7 @@ void cmake::SetArgs(const std::vector& args) "--compile-no-warning-as-error", CommandArgument::Values::Zero, [](std::string const&, cmake* state) -> bool { std::cout << "Ignoring COMPILE_WARNING_AS_ERROR target property and " - << "CMAKE_COMPILE_WARNING_AS_ERROR variable.\n"; + "CMAKE_COMPILE_WARNING_AS_ERROR variable.\n"; state->SetIgnoreWarningAsError(true); return true; } } @@ -1522,7 +1522,7 @@ void cmake::SetTraceFile(const std::string& file) cmSystemTools::Error(ss.str()); return; } - std::cout << "Trace will be written to " << file << "\n"; + std::cout << "Trace will be written to " << file << '\n'; } void cmake::PrintTraceFormatVersion() @@ -2045,12 +2045,10 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) } std::vector saved; std::ostringstream warning; - /* clang-format off */ warning << "You have changed variables that require your cache to be deleted.\n" - << "Configure will be re-run and you may have to reset some variables.\n" - << "The following variables have changed:\n"; - /* clang-format on */ + "Configure will be re-run and you may have to reset some variables.\n" + "The following variables have changed:\n"; for (auto i = argsSplit.begin(); i != argsSplit.end(); ++i) { SaveCacheEntry save; save.key = *i; @@ -2058,9 +2056,9 @@ int cmake::HandleDeleteCacheVariables(const std::string& var) i++; if (i != argsSplit.end()) { save.value = *i; - warning << *i << "\n"; + warning << *i << '\n'; } else { - warning << "\n"; + warning << '\n'; i -= 1; } cmValue existingValue = this->State->GetCacheEntryValue(save.key); @@ -2462,7 +2460,7 @@ 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"; + std::cout << "-- Building for: " << gen->GetName() << '\n'; #endif this->SetGlobalGenerator(std::move(gen)); } @@ -2621,7 +2619,7 @@ int cmake::Generate() } this->GlobalGenerator->Generate(); if (!this->GraphVizFile.empty()) { - std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl; + std::cout << "Generate graphviz: " << this->GraphVizFile << '\n'; this->GenerateGraphViz(this->GraphVizFile); } if (this->WarnUnusedCli) { @@ -2918,7 +2916,7 @@ void cmake::PrintGeneratorList() cmDocumentation doc; auto generators = this->GetGeneratorsDocumentation(); doc.AppendSection("Generators", generators); - std::cerr << "\n"; + std::cerr << '\n'; doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr); #endif } @@ -2970,7 +2968,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument - << "\n"; + << '\n'; cmSystemTools::Stdout(msg.str()); } return 1; @@ -2990,7 +2988,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument - << "\n"; + << '\n'; cmSystemTools::Stdout(msg.str()); } // There was an error reading the file. Just rerun. @@ -3021,9 +3019,8 @@ int cmake::CheckBuildSystem() for (std::string const& p : products) { if (!(cmSystemTools::FileExists(p) || cmSystemTools::FileIsSymlink(p))) { if (verbose) { - std::ostringstream msg; - msg << "Re-run cmake, missing byproduct: " << p << "\n"; - cmSystemTools::Stdout(msg.str()); + cmSystemTools::Stdout( + cmStrCat("Re-run cmake, missing byproduct: ", p, '\n')); } return 1; } @@ -3088,7 +3085,7 @@ int cmake::CheckBuildSystem() if (verbose) { std::ostringstream msg; msg << "Re-run cmake file: " << out_oldest - << " older than: " << dep_newest << "\n"; + << " older than: " << dep_newest << '\n'; cmSystemTools::Stdout(msg.str()); } return 1; @@ -3264,7 +3261,7 @@ int cmake::GetSystemInformation(std::vector& args) // permissions are questionable or some other process has deleted the // directory std::cerr << "Failed to change to directory " << destPath << " : " - << std::strerror(workdir.GetLastResult()) << std::endl; + << std::strerror(workdir.GetLastResult()) << '\n'; return 1; } std::vector args2; @@ -3332,11 +3329,13 @@ static bool cmakeCheckStampFile(const std::string& stampName) (!ftc.Compare(stampDepends, dep, &result) || result < 0)) { // The stamp depends file is older than this dependency. The // build system is really out of date. + /* clang-format off */ std::cout << "CMake is re-running because " << stampName - << " is out-of-date.\n"; - std::cout << " the file '" << dep << "'\n"; - std::cout << " is newer than '" << stampDepends << "'\n"; - std::cout << " result='" << result << "'\n"; + << " is out-of-date.\n" + " the file '" << dep << "'\n" + " is newer than '" << stampDepends << "'\n" + " result='" << result << "'\n"; + /* clang-format on */ return false; } } @@ -3371,13 +3370,13 @@ static bool cmakeCheckStampList(const std::string& stampList) // If the stamp list does not exist CMake must rerun to generate it. if (!cmSystemTools::FileExists(stampList)) { std::cout << "CMake is re-running because generate.stamp.list " - << "is missing.\n"; + "is missing.\n"; return false; } cmsys::ifstream fin(stampList.c_str()); if (!fin) { std::cout << "CMake is re-running because generate.stamp.list " - << "could not be read.\n"; + "could not be read.\n"; return false; } -- cgit v0.12 From 69918b07e17cce822ad8f11950da476c42e419ee Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 24 Aug 2022 08:41:41 +0400 Subject: cmDocumentationEntry: Drop all user provided ctors for C++ >= 14 There is no need for them cuz: - the last field has a default value - all static instances use 2 arguments convertible to `std::string` - "dynamic" instances used for _Generator_ doc entries access fields diectly using default constructed instance Moreover, compiler may generate move ctor/assign when needed. --- Source/CPack/cpack.cxx | 6 +++--- Source/CursesDialog/ccmake.cxx | 10 ++++++---- Source/QtDialog/CMakeSetup.cxx | 5 +++-- Source/cmDocumentation.cxx | 5 +++-- Source/cmDocumentationEntry.h | 19 +++++++++---------- Source/cmDocumentationSection.h | 6 ------ Source/cmakemain.cxx | 10 ++++++---- Source/ctest.cxx | 6 +++--- 8 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index efb549f..f81c6e8 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -36,11 +36,11 @@ namespace { const cmDocumentationEntry cmDocumentationName = { - nullptr, " cpack - Packaging driver provided by CMake." + {}, + " cpack - Packaging driver provided by CMake." }; -const cmDocumentationEntry cmDocumentationUsage = { nullptr, - " cpack [options]" }; +const cmDocumentationEntry cmDocumentationUsage = { {}, " cpack [options]" }; const cmDocumentationEntry cmDocumentationOptions[14] = { { "-G ", "Override/define CPACK_GENERATOR" }, diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index d61954a..18c1a80 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -25,21 +25,23 @@ namespace { const cmDocumentationEntry cmDocumentationName = { - nullptr, " ccmake - Curses Interface for CMake." + {}, + " ccmake - Curses Interface for CMake." }; const cmDocumentationEntry cmDocumentationUsage[2] = { - { nullptr, + { {}, " ccmake \n" " ccmake " }, - { nullptr, + { {}, "Specify a source directory to (re-)generate a build system for " "it in the current working directory. Specify an existing build " "directory to re-generate its build system." }, }; const cmDocumentationEntry cmDocumentationUsageNote = { - nullptr, "Run 'ccmake --help' for more information." + {}, + "Run 'ccmake --help' for more information." }; #ifndef _WIN32 diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 11f7fe6..50e8e3a 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -24,11 +24,12 @@ namespace { const cmDocumentationEntry cmDocumentationName = { - nullptr, " cmake-gui - CMake GUI." + {}, + " cmake-gui - CMake GUI." }; const cmDocumentationEntry cmDocumentationUsage = { - nullptr, + {}, " cmake-gui [options]\n" " cmake-gui [options] \n" " cmake-gui [options] \n" diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index e626f7e..77c5295 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -47,11 +47,12 @@ const cmDocumentationEntry cmDocumentationStandardOptions[20] = { }; const cmDocumentationEntry cmDocumentationCPackGeneratorsHeader = { - nullptr, "The following generators are available on this platform:" + {}, + "The following generators are available on this platform:" }; const cmDocumentationEntry cmDocumentationCMakeGeneratorsHeader = { - nullptr, + {}, "The following generators are available on this platform (* marks " "default):" }; diff --git a/Source/cmDocumentationEntry.h b/Source/cmDocumentationEntry.h index aa97391..c66b21e 100644 --- a/Source/cmDocumentationEntry.h +++ b/Source/cmDocumentationEntry.h @@ -9,17 +9,16 @@ /** Standard documentation entry for cmDocumentation's formatting. */ struct cmDocumentationEntry { - std::string Name; - std::string Brief; - char CustomNamePrefix = ' '; +#if __cplusplus <= 201103L cmDocumentationEntry() = default; - cmDocumentationEntry(const char* const n, const char* const b) + cmDocumentationEntry(const std::string& name, const std::string& brief) + : Name{ name } + , Brief{ brief } { - if (n) { - this->Name = n; - } - if (b) { - this->Brief = b; - } } +#endif + + std::string Name = {}; + std::string Brief = {}; + char CustomNamePrefix = ' '; }; diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h index b80131d..b5e24fe 100644 --- a/Source/cmDocumentationSection.h +++ b/Source/cmDocumentationSection.h @@ -52,12 +52,6 @@ public: std::end(entries)); } - /** Append an entry to this section using NULL terminated chars */ - void Append(const char* n, const char* b) - { - this->Entries.emplace_back(n, b); - } - /** prepend some documentation to this section */ template void Prepend(const Iterable& entries) diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 1ca3e55..a155787 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -47,22 +47,24 @@ namespace { #ifndef CMAKE_BOOTSTRAP const cmDocumentationEntry cmDocumentationName = { - nullptr, " cmake - Cross-Platform Makefile Generator." + {}, + " cmake - Cross-Platform Makefile Generator." }; const cmDocumentationEntry cmDocumentationUsage[2] = { - { nullptr, + { {}, " cmake [options] \n" " cmake [options] \n" " cmake [options] -S -B " }, - { nullptr, + { {}, "Specify a source directory to (re-)generate a build system for " "it in the current working directory. Specify an existing build " "directory to re-generate its build system." } }; const cmDocumentationEntry cmDocumentationUsageNote = { - nullptr, "Run 'cmake --help' for more information." + {}, + "Run 'cmake --help' for more information." }; const cmDocumentationEntry cmDocumentationOptions[31] = { diff --git a/Source/ctest.cxx b/Source/ctest.cxx index d26a0d7..fa38a65 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -19,11 +19,11 @@ namespace { const cmDocumentationEntry cmDocumentationName = { - nullptr, " ctest - Testing driver provided by CMake." + {}, + " ctest - Testing driver provided by CMake." }; -const cmDocumentationEntry cmDocumentationUsage = { nullptr, - " ctest [options]" }; +const cmDocumentationEntry cmDocumentationUsage = { {}, " ctest [options]" }; const cmDocumentationEntry cmDocumentationOptions[74] = { { "--preset , --preset=", -- cgit v0.12 From 9c06f0dd71f23a903bace0c6fae7869535a5188f Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 25 Oct 2022 08:55:03 +0400 Subject: cmake.cxx: Move `static` functions to an anonymous namespace --- Source/cmake.cxx | 197 +++++++++++++++++++++++++++---------------------------- 1 file changed, 97 insertions(+), 100 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 920687d..0309505 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -149,21 +149,110 @@ auto IgnoreAndTrueLambda = [](std::string const&, cmake*) -> bool { using CommandArgument = cmCommandLineArgument; -} // namespace - -static bool cmakeCheckStampFile(const std::string& stampName); -static bool cmakeCheckStampList(const std::string& stampList); - #ifndef CMAKE_BOOTSTRAP -static void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/, - void* ctx, const char* /*unused*/, - const cmMakefile* /*unused*/) +void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/, + void* ctx, const char* /*unused*/, + const cmMakefile* /*unused*/) { cmake* cm = reinterpret_cast(ctx); cm->MarkCliAsUsed(variable); } #endif +bool cmakeCheckStampFile(const std::string& stampName) +{ + // The stamp file does not exist. Use the stamp dependencies to + // determine whether it is really out of date. This works in + // conjunction with cmLocalVisualStudio7Generator to avoid + // repeatedly re-running CMake when the user rebuilds the entire + // solution. + std::string stampDepends = cmStrCat(stampName, ".depend"); +#if defined(_WIN32) || defined(__CYGWIN__) + cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary); +#else + cmsys::ifstream fin(stampDepends.c_str()); +#endif + if (!fin) { + // The stamp dependencies file cannot be read. Just assume the + // build system is really out of date. + std::cout << "CMake is re-running because " << stampName + << " dependency file is missing.\n"; + return false; + } + + // Compare the stamp dependencies against the dependency file itself. + { + cmFileTimeCache ftc; + std::string dep; + while (cmSystemTools::GetLineFromStream(fin, dep)) { + int result; + if (!dep.empty() && dep[0] != '#' && + (!ftc.Compare(stampDepends, dep, &result) || result < 0)) { + // The stamp depends file is older than this dependency. The + // build system is really out of date. + /* clang-format off */ + std::cout << "CMake is re-running because " << stampName + << " is out-of-date.\n" + " the file '" << dep << "'\n" + " is newer than '" << stampDepends << "'\n" + " result='" << result << "'\n"; + /* clang-format on */ + return false; + } + } + } + + // The build system is up to date. The stamp file has been removed + // by the VS IDE due to a "rebuild" request. Restore it atomically. + std::ostringstream stampTempStream; + stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed(); + std::string stampTemp = stampTempStream.str(); + { + // TODO: Teach cmGeneratedFileStream to use a random temp file (with + // multiple tries in unlikely case of conflict) and use that here. + cmsys::ofstream stamp(stampTemp.c_str()); + stamp << "# CMake generation timestamp file for this directory.\n"; + } + std::string err; + if (cmSystemTools::RenameFile(stampTemp, stampName, + cmSystemTools::Replace::Yes, &err) == + cmSystemTools::RenameResult::Success) { + // CMake does not need to re-run because the stamp file is up-to-date. + return true; + } + cmSystemTools::RemoveFile(stampTemp); + cmSystemTools::Error( + cmStrCat("Cannot restore timestamp \"", stampName, "\": ", err)); + return false; +} + +bool cmakeCheckStampList(const std::string& stampList) +{ + // If the stamp list does not exist CMake must rerun to generate it. + if (!cmSystemTools::FileExists(stampList)) { + std::cout << "CMake is re-running because generate.stamp.list " + "is missing.\n"; + return false; + } + cmsys::ifstream fin(stampList.c_str()); + if (!fin) { + std::cout << "CMake is re-running because generate.stamp.list " + "could not be read.\n"; + return false; + } + + // Check each stamp. + std::string stampName; + while (cmSystemTools::GetLineFromStream(fin, stampName)) { + if (!cmakeCheckStampFile(stampName)) { + return false; + } + } + return true; +} + +} // namespace + cmDocumentationEntry cmake::CMAKE_STANDARD_OPTIONS_TABLE[18] = { { "-S ", "Explicitly specify a source directory." }, { "-B ", "Explicitly specify a build directory." }, @@ -3298,98 +3387,6 @@ int cmake::GetSystemInformation(std::vector& args) return 0; } -static bool cmakeCheckStampFile(const std::string& stampName) -{ - // The stamp file does not exist. Use the stamp dependencies to - // determine whether it is really out of date. This works in - // conjunction with cmLocalVisualStudio7Generator to avoid - // repeatedly re-running CMake when the user rebuilds the entire - // solution. - std::string stampDepends = cmStrCat(stampName, ".depend"); -#if defined(_WIN32) || defined(__CYGWIN__) - cmsys::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary); -#else - cmsys::ifstream fin(stampDepends.c_str()); -#endif - if (!fin) { - // The stamp dependencies file cannot be read. Just assume the - // build system is really out of date. - std::cout << "CMake is re-running because " << stampName - << " dependency file is missing.\n"; - return false; - } - - // Compare the stamp dependencies against the dependency file itself. - { - cmFileTimeCache ftc; - std::string dep; - while (cmSystemTools::GetLineFromStream(fin, dep)) { - int result; - if (!dep.empty() && dep[0] != '#' && - (!ftc.Compare(stampDepends, dep, &result) || result < 0)) { - // The stamp depends file is older than this dependency. The - // build system is really out of date. - /* clang-format off */ - std::cout << "CMake is re-running because " << stampName - << " is out-of-date.\n" - " the file '" << dep << "'\n" - " is newer than '" << stampDepends << "'\n" - " result='" << result << "'\n"; - /* clang-format on */ - return false; - } - } - } - - // The build system is up to date. The stamp file has been removed - // by the VS IDE due to a "rebuild" request. Restore it atomically. - std::ostringstream stampTempStream; - stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed(); - std::string stampTemp = stampTempStream.str(); - { - // TODO: Teach cmGeneratedFileStream to use a random temp file (with - // multiple tries in unlikely case of conflict) and use that here. - cmsys::ofstream stamp(stampTemp.c_str()); - stamp << "# CMake generation timestamp file for this directory.\n"; - } - std::string err; - if (cmSystemTools::RenameFile(stampTemp, stampName, - cmSystemTools::Replace::Yes, &err) == - cmSystemTools::RenameResult::Success) { - // CMake does not need to re-run because the stamp file is up-to-date. - return true; - } - cmSystemTools::RemoveFile(stampTemp); - cmSystemTools::Error( - cmStrCat("Cannot restore timestamp \"", stampName, "\": ", err)); - return false; -} - -static bool cmakeCheckStampList(const std::string& stampList) -{ - // If the stamp list does not exist CMake must rerun to generate it. - if (!cmSystemTools::FileExists(stampList)) { - std::cout << "CMake is re-running because generate.stamp.list " - "is missing.\n"; - return false; - } - cmsys::ifstream fin(stampList.c_str()); - if (!fin) { - std::cout << "CMake is re-running because generate.stamp.list " - "could not be read.\n"; - return false; - } - - // Check each stamp. - std::string stampName; - while (cmSystemTools::GetLineFromStream(fin, stampName)) { - if (!cmakeCheckStampFile(stampName)) { - return false; - } - } - return true; -} - void cmake::IssueMessage(MessageType t, std::string const& text, cmListFileBacktrace const& backtrace) const { -- cgit v0.12 From d7c183f35cf3e149e20c3adc2a03f36a242d10f9 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 26 Oct 2022 13:21:19 +0400 Subject: cpack.cxx: Deduplicate "Generators" section creation code --- Source/CPack/cpack.cxx | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index f81c6e8..e4bf828 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -5,10 +5,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -63,6 +65,23 @@ void cpackProgressCallback(const std::string& message, float /*unused*/) { std::cout << "-- " << message << std::endl; } + +std::vector makeGeneratorDocs( + const cmCPackGeneratorFactory& gf) +{ + const auto& generators = gf.GetGeneratorsList(); + + std::vector docs; + docs.reserve(generators.size()); + + std::transform( + generators.cbegin(), generators.cend(), std::back_inserter(docs), + [](const std::decay::type::value_type& gen) { + return cmDocumentationEntry{ gen.first, gen.second }; + }); + return docs; +} + } // namespace // this is CPack. @@ -536,15 +555,9 @@ int main(int argc, char const* const* argv) << std::endl); // Print out all the valid generators cmDocumentation generatorDocs; - std::vector v; - for (auto const& g : generators.GetGeneratorsList()) { - cmDocumentationEntry e; - e.Name = g.first; - e.Brief = g.second; - v.push_back(std::move(e)); - } - generatorDocs.SetSection("Generators", v); - std::cerr << "\n"; + generatorDocs.SetSection("Generators", + makeGeneratorDocs(generators)); + std::cerr << '\n'; generatorDocs.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr); parsed = false; @@ -611,22 +624,12 @@ int main(int argc, char const* const* argv) */ if (help) { // Construct and print requested documentation. - doc.SetName("cpack"); doc.SetSection("Name", cmDocumentationName); doc.SetSection("Usage", cmDocumentationUsage); doc.PrependSection("Options", cmDocumentationOptions); - - std::vector v; - for (auto const& g : generators.GetGeneratorsList()) { - cmDocumentationEntry e; - e.Name = g.first; - e.Brief = g.second; - v.push_back(std::move(e)); - } - doc.SetSection("Generators", v); - - return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1; + doc.SetSection("Generators", makeGeneratorDocs(generators)); + return !doc.PrintRequestedDocumentation(std::cout); } if (cmSystemTools::GetErrorOccurredFlag()) { -- cgit v0.12 From f6180485bb475bf10a7d14d6bbd87831e58e942a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 26 Oct 2022 13:24:55 +0400 Subject: cpack.cxx: Eliminate redundant `if` --- Source/CPack/cpack.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index e4bf828..d1938fd 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -632,9 +632,5 @@ int main(int argc, char const* const* argv) return !doc.PrintRequestedDocumentation(std::cout); } - if (cmSystemTools::GetErrorOccurredFlag()) { - return 1; - } - - return 0; + return int(cmSystemTools::GetErrorOccurredFlag()); } -- cgit v0.12 From df2047c2acacf233ac67d674cda0faf186382db6 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 26 Oct 2022 13:32:57 +0400 Subject: cpack.cxx: Optimize calls to `std::osteam::operator<<` --- Source/CPack/cpack.cxx | 117 ++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 64 deletions(-) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index d1938fd..c228f07 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -63,7 +63,7 @@ const cmDocumentationEntry cmDocumentationOptions[14] = { void cpackProgressCallback(const std::string& message, float /*unused*/) { - std::cout << "-- " << message << std::endl; + std::cout << "-- " << message << '\n'; } std::vector makeGeneratorDocs( @@ -113,8 +113,7 @@ int main(int argc, char const* const* argv) if (cmSystemTools::GetCurrentWorkingDirectory().empty()) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Current working directory cannot be established." - << std::endl); + "Current working directory cannot be established.\n"); return 1; } @@ -141,14 +140,14 @@ int main(int argc, char const* const* argv) auto const verboseLambda = [&log](const std::string&, cmake*, cmMakefile*) -> bool { log.SetVerbose(true); - cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose" << std::endl); + cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose\n"); return true; }; auto const debugLambda = [&log](const std::string&, cmake*, cmMakefile*) -> bool { log.SetDebug(true); - cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl); + cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug\n"); return true; }; @@ -206,26 +205,25 @@ int main(int argc, char const* const* argv) CommandArgument::setToValue(preset) }, CommandArgument{ "--list-presets", CommandArgument::Values::Zero, CommandArgument::setToTrue(listPresets) }, - CommandArgument{ - "-D", CommandArgument::Values::One, - [&log, &definitions](const std::string& arg, cmake*, - cmMakefile*) -> bool { - std::string value = arg; - size_t pos = value.find_first_of('='); - if (pos == std::string::npos) { - cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Please specify CPack definitions as: KEY=VALUE" - << std::endl); - return false; - } - std::string key = value.substr(0, pos); - value.erase(0, pos + 1); - definitions[key] = value; - cmCPack_Log(&log, cmCPackLog::LOG_DEBUG, - "Set CPack variable: " << key << " to \"" << value << "\"" - << std::endl); - return true; - } }, + CommandArgument{ "-D", CommandArgument::Values::One, + [&log, &definitions](const std::string& arg, cmake*, + cmMakefile*) -> bool { + std::string value = arg; + size_t pos = value.find_first_of('='); + if (pos == std::string::npos) { + cmCPack_Log( + &log, cmCPackLog::LOG_ERROR, + "Please specify CPack definitions as: KEY=VALUE\n"); + return false; + } + std::string key = value.substr(0, pos); + value.erase(0, pos + 1); + definitions[key] = value; + cmCPack_Log(&log, cmCPackLog::LOG_DEBUG, + "Set CPack variable: " << key << " to \"" + << value << "\"\n"); + return true; + } }, }; cmake cminst(cmake::RoleScript, cmState::CPack); @@ -274,8 +272,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Could not read presets from " << workingDirectory << ": " - << cmCMakePresetsGraph::ResultToString(result) - << std::endl); + << cmCMakePresetsGraph::ResultToString(result) << '\n'); return 1; } @@ -288,7 +285,7 @@ int main(int argc, char const* const* argv) if (presetPair == presetsGraph.PackagePresets.end()) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "No such package preset in " << workingDirectory << ": \"" - << preset << '"' << std::endl); + << preset << "\"\n"); presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); return 1; } @@ -296,8 +293,7 @@ int main(int argc, char const* const* argv) if (presetPair->second.Unexpanded.Hidden) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot use hidden package preset in " - << workingDirectory << ": \"" << preset << '"' - << std::endl); + << workingDirectory << ": \"" << preset << "\"\n"); presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); return 1; } @@ -306,7 +302,7 @@ int main(int argc, char const* const* argv) if (!expandedPreset) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Could not evaluate package preset \"" - << preset << "\": Invalid macro expansion" << std::endl); + << preset << "\": Invalid macro expansion\n"); presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); return 1; } @@ -314,8 +310,7 @@ int main(int argc, char const* const* argv) if (!expandedPreset->ConditionResult) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot use disabled package preset in " - << workingDirectory << ": \"" << preset << '"' - << std::endl); + << workingDirectory << ": \"" << preset << "\"\n"); presetsGraph.PrintPackagePresetList(presetGeneratorsPresent); return 1; } @@ -332,7 +327,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "No such configure preset in " << workingDirectory << ": \"" - << expandedPreset->ConfigurePreset << '"' << std::endl); + << expandedPreset->ConfigurePreset << "\"\n"); presetsGraph.PrintConfigurePresetList(); return 1; } @@ -341,7 +336,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot use hidden configure preset in " << workingDirectory << ": \"" - << expandedPreset->ConfigurePreset << '"' << std::endl); + << expandedPreset->ConfigurePreset << "\"\n"); presetsGraph.PrintConfigurePresetList(); return 1; } @@ -351,7 +346,7 @@ int main(int argc, char const* const* argv) cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Could not evaluate configure preset \"" << expandedPreset->ConfigurePreset - << "\": Invalid macro expansion" << std::endl); + << "\": Invalid macro expansion\n"); return 1; } @@ -407,7 +402,7 @@ int main(int argc, char const* const* argv) } cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, - "Read CPack config file: " << cpackConfigFile << std::endl); + "Read CPack config file: " << cpackConfigFile << '\n'); bool cpackConfigFileSpecified = true; if (cpackConfigFile.empty()) { @@ -435,7 +430,7 @@ int main(int argc, char const* const* argv) globalMF.GetModulesFile("CMakeDetermineSystem.cmake"); if (!globalMF.ReadListFile(systemFile)) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Error reading CMakeDetermineSystem.cmake" << std::endl); + "Error reading CMakeDetermineSystem.cmake\n"); return 1; } @@ -443,8 +438,7 @@ int main(int argc, char const* const* argv) globalMF.GetModulesFile("CMakeSystemSpecificInformation.cmake"); if (!globalMF.ReadListFile(systemFile)) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Error reading CMakeSystemSpecificInformation.cmake" - << std::endl); + "Error reading CMakeSystemSpecificInformation.cmake\n"); return 1; } @@ -456,17 +450,17 @@ int main(int argc, char const* const* argv) cpackConfigFile = cmSystemTools::CollapseFullPath(cpackConfigFile); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack configuration file: " << cpackConfigFile - << std::endl); + << '\n'); if (!globalMF.ReadListFile(cpackConfigFile)) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Problem reading CPack config file: \"" - << cpackConfigFile << "\"" << std::endl); + "Problem reading CPack config file: \"" << cpackConfigFile + << "\"\n"); return 1; } } else if (cpackConfigFileSpecified) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot find CPack config file: \"" << cpackConfigFile - << "\"" << std::endl); + << "\"\n"); return 1; } @@ -515,17 +509,17 @@ int main(int argc, char const* const* argv) cmValue genList = globalMF.GetDefinition("CPACK_GENERATOR"); if (!genList) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "CPack generator not specified" << std::endl); + "CPack generator not specified\n"); } else { std::vector generatorsVector = cmExpandedList(*genList); for (std::string const& gen : generatorsVector) { cmMakefile::ScopePushPop raii(&globalMF); cmMakefile* mf = &globalMF; cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, - "Specified generator: " << gen << std::endl); + "Specified generator: " << gen << '\n'); if (!mf->GetDefinition("CPACK_PACKAGE_NAME")) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "CPack project name not specified" << std::endl); + "CPack project name not specified" << '\n'); parsed = false; } if (parsed && @@ -534,13 +528,11 @@ int main(int argc, char const* const* argv) mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") && mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH")))) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "CPack project version not specified" - << std::endl - << "Specify CPACK_PACKAGE_VERSION, or " - "CPACK_PACKAGE_VERSION_MAJOR, " - "CPACK_PACKAGE_VERSION_MINOR, and " - "CPACK_PACKAGE_VERSION_PATCH." - << std::endl); + "CPack project version not specified\n" + "Specify CPACK_PACKAGE_VERSION, or " + "CPACK_PACKAGE_VERSION_MAJOR, " + "CPACK_PACKAGE_VERSION_MINOR, and " + "CPACK_PACKAGE_VERSION_PATCH.\n"); parsed = false; } if (parsed) { @@ -551,8 +543,7 @@ int main(int argc, char const* const* argv) cpackGenerator->SetTraceExpand(cminst.GetTraceExpand()); } else { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Could not create CPack generator: " << gen - << std::endl); + "Could not create CPack generator: " << gen << '\n'); // Print out all the valid generators cmDocumentation generatorDocs; generatorDocs.SetSection("Generators", @@ -565,8 +556,7 @@ int main(int argc, char const* const* argv) if (parsed && !cpackGenerator->Initialize(gen, mf)) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, - "Cannot initialize the generator " << gen - << std::endl); + "Cannot initialize the generator " << gen << '\n'); parsed = false; } @@ -579,17 +569,16 @@ int main(int argc, char const* const* argv) "Please specify build tree of the project that uses CMake " "using CPACK_INSTALL_CMAKE_PROJECTS, specify " "CPACK_INSTALL_COMMANDS, CPACK_INSTALL_SCRIPT, or " - "CPACK_INSTALLED_DIRECTORIES." - << std::endl); + "CPACK_INSTALLED_DIRECTORIES.\n"); parsed = false; } if (parsed) { cmValue projName = mf->GetDefinition("CPACK_PACKAGE_NAME"); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: " << cpackGenerator->GetNameOfClass() - << std::endl); + << '\n'); cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, - "For project: " << *projName << std::endl); + "For project: " << *projName << '\n'); cmValue projVersion = mf->GetDefinition("CPACK_PACKAGE_VERSION"); if (!projVersion) { @@ -600,7 +589,7 @@ int main(int argc, char const* const* argv) cmValue projVersionPatch = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"); std::ostringstream ostr; - ostr << *projVersionMajor << "." << *projVersionMinor << "." + ostr << *projVersionMajor << "." << *projVersionMinor << '.' << *projVersionPatch; mf->AddDefinition("CPACK_PACKAGE_VERSION", ostr.str()); } @@ -609,7 +598,7 @@ int main(int argc, char const* const* argv) if (!res) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error when generating package: " << *projName - << std::endl); + << '\n'); return 1; } } -- cgit v0.12 From 7daadd304f87292cd0ec97525d3738ac96377e8a Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 26 Oct 2022 14:08:27 +0400 Subject: cmake.cxx: Simplify `cmake::AppendExtraGeneratorsDocumentation()` --- Source/cmake.cxx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 0309505..62f926e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2972,21 +2972,14 @@ void cmake::AppendExtraGeneratorsDocumentation( // Aliases: for (std::string const& a : eg->Aliases) { - cmDocumentationEntry e; - e.Name = a; - e.Brief = doc; - v.push_back(std::move(e)); + v.emplace_back(cmDocumentationEntry{ a, doc }); } // Full names: - const std::vector generators = - eg->GetSupportedGlobalGenerators(); - for (std::string const& g : generators) { - cmDocumentationEntry e; - e.Name = - cmExternalMakefileProjectGenerator::CreateFullGeneratorName(g, name); - e.Brief = doc; - v.push_back(std::move(e)); + for (std::string const& g : eg->GetSupportedGlobalGenerators()) { + v.emplace_back(cmDocumentationEntry{ + cmExternalMakefileProjectGenerator::CreateFullGeneratorName(g, name), + doc }); } } } -- cgit v0.12 From e99a4acbcd2f7ec8e5cefbf996af1dfa95e61a27 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 26 Oct 2022 15:08:09 +0400 Subject: cmGlobalGeneratorFactory.h: Simplify returning default values --- Source/cmGlobalGeneratorFactory.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h index d6ababb..e8ed3e0 100644 --- a/Source/cmGlobalGeneratorFactory.h +++ b/Source/cmGlobalGeneratorFactory.h @@ -47,7 +47,7 @@ public: virtual std::string GetDefaultPlatformName() const = 0; }; -template +template class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory { public: @@ -70,13 +70,11 @@ public: /** Get the names of the current registered generators */ std::vector GetGeneratorNames() const override { - std::vector names; - names.push_back(T::GetActualName()); - return names; + return { T::GetActualName() }; } std::vector GetGeneratorNamesWithPlatform() const override { - return std::vector(); + return {}; } /** Determine whether or not this generator supports toolsets */ @@ -89,8 +87,8 @@ public: std::vector GetKnownPlatforms() const override { // default is no platform supported - return std::vector(); + return {}; } - std::string GetDefaultPlatformName() const override { return std::string(); } + std::string GetDefaultPlatformName() const override { return {}; } }; -- cgit v0.12 From 6e3e8827faf0bf2363ecf9035b5573e715e52fb2 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Wed, 26 Oct 2022 15:09:54 +0400 Subject: Refactor: `cmGlobalGeneratorFactory::GetDocumentation` returns entry Before, a documentation entry was in/out parameter. Now it's a normal return value. This also makes possible to eliminate defaulted default ctor for `cmDocumentationEntry` for C++ 11. Also, simplify `cmake::AppendGlobalGeneratorsDocumentation()`. --- Source/cmDocumentationEntry.h | 1 - Source/cmGlobalBorlandMakefileGenerator.cxx | 7 +++---- Source/cmGlobalBorlandMakefileGenerator.h | 3 +-- Source/cmGlobalGeneratorFactory.h | 11 ++++++---- Source/cmGlobalGhsMultiGenerator.cxx | 10 ++++----- Source/cmGlobalGhsMultiGenerator.h | 3 +-- Source/cmGlobalJOMMakefileGenerator.cxx | 8 +++----- Source/cmGlobalJOMMakefileGenerator.h | 3 +-- Source/cmGlobalMSYSMakefileGenerator.cxx | 8 +++----- Source/cmGlobalMSYSMakefileGenerator.h | 3 +-- Source/cmGlobalMinGWMakefileGenerator.cxx | 8 +++----- Source/cmGlobalMinGWMakefileGenerator.h | 3 +-- Source/cmGlobalNMakeMakefileGenerator.cxx | 16 +++++---------- Source/cmGlobalNMakeMakefileGenerator.h | 3 +-- Source/cmGlobalNinjaGenerator.cxx | 13 ++++++------ Source/cmGlobalNinjaGenerator.h | 5 ++--- Source/cmGlobalUnixMakefileGenerator3.cxx | 8 +++----- Source/cmGlobalUnixMakefileGenerator3.h | 3 +-- Source/cmGlobalVisualStudio11Generator.cxx | 9 ++++---- Source/cmGlobalVisualStudio12Generator.cxx | 9 ++++---- Source/cmGlobalVisualStudio14Generator.cxx | 9 ++++---- Source/cmGlobalVisualStudio9Generator.cxx | 9 ++++---- Source/cmGlobalVisualStudioVersionedGenerator.cxx | 25 +++++++++++------------ Source/cmGlobalWatcomWMakeGenerator.cxx | 8 +++----- Source/cmGlobalWatcomWMakeGenerator.h | 3 +-- Source/cmGlobalXCodeGenerator.cxx | 11 +++++----- Source/cmGlobalXCodeGenerator.h | 4 ++-- Source/cmake.cxx | 12 +++++------ 28 files changed, 91 insertions(+), 124 deletions(-) diff --git a/Source/cmDocumentationEntry.h b/Source/cmDocumentationEntry.h index c66b21e..d971836 100644 --- a/Source/cmDocumentationEntry.h +++ b/Source/cmDocumentationEntry.h @@ -10,7 +10,6 @@ struct cmDocumentationEntry { #if __cplusplus <= 201103L - cmDocumentationEntry() = default; cmDocumentationEntry(const std::string& name, const std::string& brief) : Name{ name } , Brief{ brief } diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx index 776ee40..2fd7f8a 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.cxx +++ b/Source/cmGlobalBorlandMakefileGenerator.cxx @@ -60,11 +60,10 @@ cmGlobalBorlandMakefileGenerator::CreateLocalGenerator(cmMakefile* mf) return std::unique_ptr(std::move(lg)); } -void cmGlobalBorlandMakefileGenerator::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalBorlandMakefileGenerator::GetDocumentation() { - entry.Name = cmGlobalBorlandMakefileGenerator::GetActualName(); - entry.Brief = "Generates Borland makefiles."; + return { cmGlobalBorlandMakefileGenerator::GetActualName(), + "Generates Borland makefiles." }; } std::vector diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h index a280b81..049d6ba 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.h +++ b/Source/cmGlobalBorlandMakefileGenerator.h @@ -13,7 +13,6 @@ class cmLocalGenerator; class cmMakefile; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalBorlandMakefileGenerator * \brief Write a Borland makefiles. @@ -38,7 +37,7 @@ public: static std::string GetActualName() { return "Borland Makefiles"; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); //! Create a local generator appropriate to this Global Generator std::unique_ptr CreateLocalGenerator( diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h index e8ed3e0..a935079 100644 --- a/Source/cmGlobalGeneratorFactory.h +++ b/Source/cmGlobalGeneratorFactory.h @@ -4,6 +4,10 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include "cmDocumentationEntry.h" // IWYU pragma: export + +// TODO The following headers are parts of the `cmGlobalGeneratorFactory` +// public API, so could be defined as export to IWYU #include #include @@ -11,7 +15,6 @@ class cmGlobalGenerator; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalGeneratorFactory * \brief Responable for creating cmGlobalGenerator instances @@ -28,7 +31,7 @@ public: const std::string& n, bool allowArch, cmake* cm) const = 0; /** Get the documentation entry for this factory */ - virtual void GetDocumentation(cmDocumentationEntry& entry) const = 0; + virtual cmDocumentationEntry GetDocumentation() const = 0; /** Get the names of the current registered generators */ virtual std::vector GetGeneratorNames() const = 0; @@ -62,9 +65,9 @@ public: } /** Get the documentation entry for this factory */ - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - T::GetDocumentation(entry); + return T::GetDocumentation(); } /** Get the names of the current registered generators */ diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 9c334a5..18c48d7 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -15,7 +15,6 @@ #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" -#include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGhsMultiGpj.h" @@ -58,11 +57,12 @@ cmGlobalGhsMultiGenerator::CreateLocalGenerator(cmMakefile* mf) cm::make_unique(this, mf)); } -void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalGhsMultiGenerator::GetDocumentation() { - entry.Name = GetActualName(); - entry.Brief = - "Generates Green Hills MULTI files (experimental, work-in-progress)."; + return { + GetActualName(), + "Generates Green Hills MULTI files (experimental, work-in-progress)." + }; } void cmGlobalGhsMultiGenerator::ComputeTargetObjectDirectory( diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index aa68d3b..4a79610 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -18,7 +18,6 @@ class cmGeneratorTarget; class cmLocalGenerator; class cmMakefile; class cmake; -struct cmDocumentationEntry; class cmGlobalGhsMultiGenerator : public cmGlobalGenerator { @@ -46,7 +45,7 @@ public: std::string GetName() const override { return GetActualName(); } /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation() - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); /** * Utilized by the generator factory to determine if this generator diff --git a/Source/cmGlobalJOMMakefileGenerator.cxx b/Source/cmGlobalJOMMakefileGenerator.cxx index 1a625cc..f1d4d09 100644 --- a/Source/cmGlobalJOMMakefileGenerator.cxx +++ b/Source/cmGlobalJOMMakefileGenerator.cxx @@ -6,7 +6,6 @@ #include -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmState.h" @@ -36,11 +35,10 @@ void cmGlobalJOMMakefileGenerator::EnableLanguage( this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); } -void cmGlobalJOMMakefileGenerator::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalJOMMakefileGenerator::GetDocumentation() { - entry.Name = cmGlobalJOMMakefileGenerator::GetActualName(); - entry.Brief = "Generates JOM makefiles."; + return { cmGlobalJOMMakefileGenerator::GetActualName(), + "Generates JOM makefiles." }; } void cmGlobalJOMMakefileGenerator::PrintCompilerAdvice(std::ostream& os, diff --git a/Source/cmGlobalJOMMakefileGenerator.h b/Source/cmGlobalJOMMakefileGenerator.h index 332d1cf..5e74875 100644 --- a/Source/cmGlobalJOMMakefileGenerator.h +++ b/Source/cmGlobalJOMMakefileGenerator.h @@ -13,7 +13,6 @@ class cmMakefile; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalJOMMakefileGenerator * \brief Write a JOM makefiles. @@ -39,7 +38,7 @@ public: static std::string GetActualName() { return "NMake Makefiles JOM"; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); /** * Try to determine system information such as shared library diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index d4ff1e0..e543aea 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -4,7 +4,6 @@ #include "cmsys/FStream.hxx" -#include "cmDocumentationEntry.h" #include "cmMakefile.h" #include "cmState.h" #include "cmStringAlgorithms.h" @@ -53,9 +52,8 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage( } } -void cmGlobalMSYSMakefileGenerator::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalMSYSMakefileGenerator::GetDocumentation() { - entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName(); - entry.Brief = "Generates MSYS makefiles."; + return { cmGlobalMSYSMakefileGenerator::GetActualName(), + "Generates MSYS makefiles." }; } diff --git a/Source/cmGlobalMSYSMakefileGenerator.h b/Source/cmGlobalMSYSMakefileGenerator.h index 586487f..a8516a4 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.h +++ b/Source/cmGlobalMSYSMakefileGenerator.h @@ -11,7 +11,6 @@ class cmMakefile; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalMSYSMakefileGenerator * \brief Write a NMake makefiles. @@ -36,7 +35,7 @@ public: static std::string GetActualName() { return "MSYS Makefiles"; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); /** * Try to determine system information such as shared library diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx index 5a7edae..a0a52d3 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.cxx +++ b/Source/cmGlobalMinGWMakefileGenerator.cxx @@ -2,7 +2,6 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGlobalMinGWMakefileGenerator.h" -#include "cmDocumentationEntry.h" #include "cmMakefile.h" #include "cmState.h" #include "cmSystemTools.h" @@ -19,9 +18,8 @@ cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator(cmake* cm) cm->GetState()->SetMinGWMake(true); } -void cmGlobalMinGWMakefileGenerator::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalMinGWMakefileGenerator::GetDocumentation() { - entry.Name = cmGlobalMinGWMakefileGenerator::GetActualName(); - entry.Brief = "Generates a make file for use with mingw32-make."; + return { cmGlobalMinGWMakefileGenerator::GetActualName(), + "Generates a make file for use with mingw32-make." }; } diff --git a/Source/cmGlobalMinGWMakefileGenerator.h b/Source/cmGlobalMinGWMakefileGenerator.h index 92d495c..b39db03 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.h +++ b/Source/cmGlobalMinGWMakefileGenerator.h @@ -11,7 +11,6 @@ class cmMakefile; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalMinGWMakefileGenerator * \brief Write a NMake makefiles. @@ -35,5 +34,5 @@ public: static std::string GetActualName() { return "MinGW Makefiles"; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); }; diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx index eabacf6..cb53850 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.cxx +++ b/Source/cmGlobalNMakeMakefileGenerator.cxx @@ -8,7 +8,6 @@ #include "cmsys/RegularExpression.hxx" -#include "cmDocumentationEntry.h" #include "cmDuration.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -80,11 +79,10 @@ void cmGlobalNMakeMakefileGenerator::CheckNMakeFeatures() cmSystemTools::OP_LESS, this->NMakeVersion, "9"); } -void cmGlobalNMakeMakefileGenerator::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalNMakeMakefileGenerator::GetDocumentation() { - entry.Name = cmGlobalNMakeMakefileGenerator::GetActualName(); - entry.Brief = "Generates NMake makefiles."; + return { cmGlobalNMakeMakefileGenerator::GetActualName(), + "Generates NMake makefiles." }; } void cmGlobalNMakeMakefileGenerator::PrintCompilerAdvice( @@ -128,12 +126,8 @@ void cmGlobalNMakeMakefileGenerator::PrintBuildCommandAdvice(std::ostream& os, if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) { // nmake does not support parallel build level // see https://msdn.microsoft.com/en-us/library/afyyse50.aspx - - /* clang-format off */ - os << - "Warning: NMake does not support parallel builds. " - "Ignoring parallel build command line option.\n"; - /* clang-format on */ + os << "Warning: NMake does not support parallel builds. " + "Ignoring parallel build command line option.\n"; } this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice( diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h index b3574eb..436ebca 100644 --- a/Source/cmGlobalNMakeMakefileGenerator.h +++ b/Source/cmGlobalNMakeMakefileGenerator.h @@ -15,7 +15,6 @@ class cmMakefile; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalNMakeMakefileGenerator * \brief Write a NMake makefiles. @@ -45,7 +44,7 @@ public: } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); /** * Try to determine system information such as shared library diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 395372b..aa1ded0 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -25,7 +25,6 @@ #include "cmsys/FStream.hxx" #include "cmCxxModuleMapper.h" -#include "cmDocumentationEntry.h" #include "cmFileSet.h" #include "cmFortranParser.h" #include "cmGeneratedFileStream.h" @@ -554,10 +553,10 @@ codecvt::Encoding cmGlobalNinjaGenerator::GetMakefileEncoding() const return this->NinjaExpectedEncoding; } -void cmGlobalNinjaGenerator::GetDocumentation(cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalNinjaGenerator::GetDocumentation() { - entry.Name = cmGlobalNinjaGenerator::GetActualName(); - entry.Brief = "Generates build.ninja files."; + return { cmGlobalNinjaGenerator::GetActualName(), + "Generates build.ninja files." }; } // Implemented in all cmGlobaleGenerator sub-classes. @@ -3211,10 +3210,10 @@ cmGlobalNinjaMultiGenerator::cmGlobalNinjaMultiGenerator(cmake* cm) cm->GetState()->SetNinjaMulti(true); } -void cmGlobalNinjaMultiGenerator::GetDocumentation(cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalNinjaMultiGenerator::GetDocumentation() { - entry.Name = cmGlobalNinjaMultiGenerator::GetActualName(); - entry.Brief = "Generates build-.ninja files."; + return { cmGlobalNinjaMultiGenerator::GetActualName(), + "Generates build-.ninja files." }; } std::string cmGlobalNinjaMultiGenerator::ExpandCFGIntDir( diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index dac1c52..1628349 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -35,7 +35,6 @@ class cmMakefile; class cmOutputConverter; class cmStateDirectory; class cmake; -struct cmDocumentationEntry; /** * \class cmGlobalNinjaGenerator @@ -193,7 +192,7 @@ public: /** Get encoding used by generator for ninja files */ codecvt::Encoding GetMakefileEncoding() const override; - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); void EnableLanguage(std::vector const& languages, cmMakefile* mf, bool optional) override; @@ -656,7 +655,7 @@ public: new cmGlobalGeneratorSimpleFactory()); } - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); std::string GetName() const override { diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index bf9e40e..70a9d3e 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -11,7 +11,6 @@ #include #include -#include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" @@ -71,11 +70,10 @@ cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(cmMakefile* mf) cm::make_unique(this, mf)); } -void cmGlobalUnixMakefileGenerator3::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalUnixMakefileGenerator3::GetDocumentation() { - entry.Name = cmGlobalUnixMakefileGenerator3::GetActualName(); - entry.Brief = "Generates standard UNIX makefiles."; + return { cmGlobalUnixMakefileGenerator3::GetActualName(), + "Generates standard UNIX makefiles." }; } void cmGlobalUnixMakefileGenerator3::ComputeTargetObjectDirectory( diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 92e567a..214ba2a 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -24,7 +24,6 @@ class cmLocalUnixMakefileGenerator3; class cmMakefile; class cmMakefileTargetGenerator; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalUnixMakefileGenerator3 * \brief Write a Unix makefiles. @@ -101,7 +100,7 @@ public: bool SupportsCustomCommandDepfile() const override { return true; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); std::unique_ptr CreateLocalGenerator( cmMakefile* mf) override; diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index c53ddf5..75e3df8 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -7,7 +7,6 @@ #include #include -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" #include "cmGlobalVisualStudioGenerator.h" @@ -74,11 +73,11 @@ public: return std::unique_ptr(std::move(ret)); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs11generatorName) + " [arch]"; - entry.Brief = "Deprecated. Generates Visual Studio 2012 project files. " - "Optional [arch] can be \"Win64\" or \"ARM\"."; + return { std::string(vs11generatorName) + " [arch]", + "Deprecated. Generates Visual Studio 2012 project files. " + "Optional [arch] can be \"Win64\" or \"ARM\"." }; } std::vector GetGeneratorNames() const override diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index 600ee0a..7e56a78 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -6,7 +6,6 @@ #include #include -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" #include "cmGlobalVisualStudioGenerator.h" @@ -62,11 +61,11 @@ public: return std::unique_ptr(); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs12generatorName) + " [arch]"; - entry.Brief = "Generates Visual Studio 2013 project files. " - "Optional [arch] can be \"Win64\" or \"ARM\"."; + return { std::string(vs12generatorName) + " [arch]", + "Generates Visual Studio 2013 project files. " + "Optional [arch] can be \"Win64\" or \"ARM\"." }; } std::vector GetGeneratorNames() const override diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 9f94cca..0e05083 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -7,7 +7,6 @@ #include -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" #include "cmGlobalVisualStudioGenerator.h" @@ -64,11 +63,11 @@ public: return std::unique_ptr(); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs14generatorName) + " [arch]"; - entry.Brief = "Generates Visual Studio 2015 project files. " - "Optional [arch] can be \"Win64\" or \"ARM\"."; + return { std::string(vs14generatorName) + " [arch]", + "Generates Visual Studio 2015 project files. " + "Optional [arch] can be \"Win64\" or \"ARM\"." }; } std::vector GetGeneratorNames() const override diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index e03e665..cd0b114 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -6,7 +6,6 @@ #include #include -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" #include "cmGlobalVisualStudioGenerator.h" @@ -62,11 +61,11 @@ public: return std::unique_ptr(std::move(ret)); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs9generatorName) + " [arch]"; - entry.Brief = "Generates Visual Studio 2008 project files. " - "Optional [arch] can be \"Win64\" or \"IA64\"."; + return { std::string(vs9generatorName) + " [arch]", + "Generates Visual Studio 2008 project files. " + "Optional [arch] can be \"Win64\" or \"IA64\"." }; } std::vector GetGeneratorNames() const override diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index be318c1..ee24f05 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -14,7 +14,6 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmGlobalGeneratorFactory.h" #include "cmMakefile.h" @@ -255,11 +254,11 @@ public: return std::unique_ptr(); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs15generatorName) + " [arch]"; - entry.Brief = "Generates Visual Studio 2017 project files. " - "Optional [arch] can be \"Win64\" or \"ARM\"."; + return { std::string(vs15generatorName) + " [arch]", + "Generates Visual Studio 2017 project files. " + "Optional [arch] can be \"Win64\" or \"ARM\"." }; } std::vector GetGeneratorNames() const override @@ -351,11 +350,11 @@ public: return std::unique_ptr(); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs16generatorName); - entry.Brief = "Generates Visual Studio 2019 project files. " - "Use -A option to specify architecture."; + return { std::string(vs16generatorName), + "Generates Visual Studio 2019 project files. " + "Use -A option to specify architecture." }; } std::vector GetGeneratorNames() const override @@ -416,11 +415,11 @@ public: return std::unique_ptr(); } - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - entry.Name = std::string(vs17generatorName); - entry.Brief = "Generates Visual Studio 2022 project files. " - "Use -A option to specify architecture."; + return { std::string(vs17generatorName), + "Generates Visual Studio 2022 project files. " + "Use -A option to specify architecture." }; } std::vector GetGeneratorNames() const override diff --git a/Source/cmGlobalWatcomWMakeGenerator.cxx b/Source/cmGlobalWatcomWMakeGenerator.cxx index fb2a8b6..ed44e6b 100644 --- a/Source/cmGlobalWatcomWMakeGenerator.cxx +++ b/Source/cmGlobalWatcomWMakeGenerator.cxx @@ -4,7 +4,6 @@ #include -#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmState.h" @@ -54,11 +53,10 @@ bool cmGlobalWatcomWMakeGenerator::SetSystemName(std::string const& s, return this->cmGlobalUnixMakefileGenerator3::SetSystemName(s, mf); } -void cmGlobalWatcomWMakeGenerator::GetDocumentation( - cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalWatcomWMakeGenerator::GetDocumentation() { - entry.Name = cmGlobalWatcomWMakeGenerator::GetActualName(); - entry.Brief = "Generates Watcom WMake makefiles."; + return { cmGlobalWatcomWMakeGenerator::GetActualName(), + "Generates Watcom WMake makefiles." }; } std::vector diff --git a/Source/cmGlobalWatcomWMakeGenerator.h b/Source/cmGlobalWatcomWMakeGenerator.h index eb93934..5579120 100644 --- a/Source/cmGlobalWatcomWMakeGenerator.h +++ b/Source/cmGlobalWatcomWMakeGenerator.h @@ -15,7 +15,6 @@ class cmMakefile; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalWatcomWMakeGenerator * \brief Write a NMake makefiles. @@ -39,7 +38,7 @@ public: static std::string GetActualName() { return "Watcom WMake"; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); /** Tell the generator about the target system. */ bool SetSystemName(std::string const& s, cmMakefile* mf) override; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 62e5a1e..0e94de5 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -24,7 +24,6 @@ #include "cmCustomCommandGenerator.h" #include "cmCustomCommandLines.h" #include "cmCustomCommandTypes.h" -#include "cmDocumentationEntry.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" @@ -149,9 +148,9 @@ public: std::unique_ptr CreateGlobalGenerator( const std::string& name, bool allowArch, cmake* cm) const override; - void GetDocumentation(cmDocumentationEntry& entry) const override + cmDocumentationEntry GetDocumentation() const override { - cmGlobalXCodeGenerator::GetDocumentation(entry); + return cmGlobalXCodeGenerator::GetDocumentation(); } std::vector GetGeneratorNames() const override @@ -4864,10 +4863,10 @@ std::string cmGlobalXCodeGenerator::ExpandCFGIntDir( return tmp; } -void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry) +cmDocumentationEntry cmGlobalXCodeGenerator::GetDocumentation() { - entry.Name = cmGlobalXCodeGenerator::GetActualName(); - entry.Brief = "Generate Xcode project files."; + return { cmGlobalXCodeGenerator::GetActualName(), + "Generate Xcode project files." }; } std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake( diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 9ae75fb..856852b 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -14,6 +14,7 @@ #include #include +#include "cmDocumentationEntry.h" #include "cmGlobalGenerator.h" #include "cmTransformDepfile.h" #include "cmValue.h" @@ -28,7 +29,6 @@ class cmMakefile; class cmSourceFile; class cmSourceGroup; class cmake; -struct cmDocumentationEntry; /** \class cmGlobalXCodeGenerator * \brief Write a Unix makefiles. @@ -54,7 +54,7 @@ public: static std::string GetActualName() { return "Xcode"; } /** Get the documentation entry for this generator. */ - static void GetDocumentation(cmDocumentationEntry& entry); + static cmDocumentationEntry GetDocumentation(); //! Create a local generator appropriate to this Global Generator std::unique_ptr CreateLocalGenerator( diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 62f926e..befcb55 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2949,17 +2949,15 @@ void cmake::AppendGlobalGeneratorsDocumentation( std::vector& v) { const auto defaultGenerator = this->EvaluateDefaultGlobalGenerator(); - const std::string defaultName = defaultGenerator->GetName(); - bool foundDefaultOne = false; + const auto defaultName = defaultGenerator->GetName(); + auto foundDefaultOne = false; for (const auto& g : this->Generators) { - cmDocumentationEntry e; - g->GetDocumentation(e); - if (!foundDefaultOne && cmHasPrefix(e.Name, defaultName)) { - e.CustomNamePrefix = '*'; + v.emplace_back(g->GetDocumentation()); + if (!foundDefaultOne && cmHasPrefix(v.back().Name, defaultName)) { + v.back().CustomNamePrefix = '*'; foundDefaultOne = true; } - v.push_back(std::move(e)); } } -- cgit v0.12