cmake/Source/cmDocumentation.cxx

662 lines
22 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDocumentation.h"
2020-02-01 23:06:01 +01:00
#include <algorithm>
#include <cctype>
#include <cstring>
#include <utility>
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
2016-10-30 18:24:19 +01:00
#include "cmDocumentationEntry.h"
#include "cmDocumentationSection.h"
2016-07-09 11:21:54 +02:00
#include "cmRST.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
2014-08-03 19:52:23 +02:00
2023-05-23 16:38:00 +02:00
namespace {
const cmDocumentationEntry cmDocumentationStandardOptions[20] = {
2022-11-16 20:14:03 +01:00
{ "-h,-H,--help,-help,-usage,/?", "Print usage information and exit." },
{ "--version,-version,/V [<file>]", "Print version number and exit." },
{ "--help-full [<file>]", "Print all help manuals and exit." },
{ "--help-manual <man> [<file>]", "Print one help manual and exit." },
{ "--help-manual-list [<file>]", "List help manuals available and exit." },
{ "--help-command <cmd> [<file>]", "Print help for one command and exit." },
{ "--help-command-list [<file>]",
2016-07-09 11:21:54 +02:00
"List commands with help available and exit." },
2022-11-16 20:14:03 +01:00
{ "--help-commands [<file>]", "Print cmake-commands manual and exit." },
{ "--help-module <mod> [<file>]", "Print help for one module and exit." },
{ "--help-module-list [<file>]",
"List modules with help available and exit." },
{ "--help-modules [<file>]", "Print cmake-modules manual and exit." },
{ "--help-policy <cmp> [<file>]", "Print help for one policy and exit." },
{ "--help-policy-list [<file>]",
2016-07-09 11:21:54 +02:00
"List policies with help available and exit." },
2022-11-16 20:14:03 +01:00
{ "--help-policies [<file>]", "Print cmake-policies manual and exit." },
{ "--help-property <prop> [<file>]",
"Print help for one property and exit." },
{ "--help-property-list [<file>]",
2016-07-09 11:21:54 +02:00
"List properties with help available and exit." },
2022-11-16 20:14:03 +01:00
{ "--help-properties [<file>]", "Print cmake-properties manual and exit." },
{ "--help-variable var [<file>]", "Print help for one variable and exit." },
{ "--help-variable-list [<file>]",
2016-07-09 11:21:54 +02:00
"List variables with help available and exit." },
2023-05-23 16:38:00 +02:00
{ "--help-variables [<file>]", "Print cmake-variables manual and exit." }
};
2023-05-23 16:38:00 +02:00
const cmDocumentationEntry cmDocumentationCPackGeneratorsHeader = {
{},
"The following generators are available on this platform:"
};
2023-05-23 16:38:00 +02:00
const cmDocumentationEntry cmDocumentationCMakeGeneratorsHeader = {
{},
"The following generators are available on this platform (* marks "
"default):"
2019-11-11 23:01:05 +01:00
};
2023-05-23 16:38:00 +02:00
bool isOption(const char* arg)
{
return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
(strcmp(arg, "/?") == 0));
}
} // anonymous namespace
cmDocumentation::cmDocumentation()
{
2012-04-19 19:04:21 +03:00
this->addCommonStandardDocSections();
2010-03-17 14:00:29 +02:00
this->ShowGenerators = true;
}
bool cmDocumentation::PrintVersion(std::ostream& os)
{
2016-07-09 11:21:54 +02:00
/* clang-format off */
2014-08-03 19:52:23 +02:00
os <<
this->GetNameString() <<
" version " << cmVersion::GetCMakeVersion() << "\n"
"\n"
"CMake suite maintained and supported by Kitware (kitware.com/cmake).\n"
;
2016-07-09 11:21:54 +02:00
/* clang-format on */
return true;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
{
2016-07-09 11:21:54 +02:00
switch (ht) {
case cmDocumentation::Usage:
2015-04-27 22:25:09 +02:00
return this->PrintUsage(os);
case cmDocumentation::Help:
return this->PrintHelp(os);
2012-02-18 12:40:36 +02:00
case cmDocumentation::Full:
2014-08-03 19:52:23 +02:00
return this->PrintHelpFull(os);
case cmDocumentation::OneManual:
return this->PrintHelpOneManual(os);
case cmDocumentation::OneCommand:
return this->PrintHelpOneCommand(os);
case cmDocumentation::OneModule:
return this->PrintHelpOneModule(os);
case cmDocumentation::OnePolicy:
return this->PrintHelpOnePolicy(os);
case cmDocumentation::OneProperty:
return this->PrintHelpOneProperty(os);
case cmDocumentation::OneVariable:
return this->PrintHelpOneVariable(os);
case cmDocumentation::ListManuals:
return this->PrintHelpListManuals(os);
case cmDocumentation::ListCommands:
return this->PrintHelpListCommands(os);
case cmDocumentation::ListModules:
return this->PrintHelpListModules(os);
case cmDocumentation::ListProperties:
return this->PrintHelpListProperties(os);
case cmDocumentation::ListVariables:
return this->PrintHelpListVariables(os);
case cmDocumentation::ListPolicies:
return this->PrintHelpListPolicies(os);
2015-08-17 11:37:30 +02:00
case cmDocumentation::ListGenerators:
return this->PrintHelpListGenerators(os);
2012-02-18 12:40:36 +02:00
case cmDocumentation::Version:
2014-08-03 19:52:23 +02:00
return this->PrintVersion(os);
case cmDocumentation::OldCustomModules:
return this->PrintOldCustomModules(os);
2016-07-09 11:21:54 +02:00
default:
return false;
}
}
bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
int count = 0;
bool result = true;
2012-02-18 12:40:36 +02:00
// Loop over requested documentation types.
2018-01-26 17:06:56 +01:00
for (RequestedHelpItem const& rhi : this->RequestedHelpItems) {
this->CurrentArgument = rhi.Argument;
// If a file name was given, use it. Otherwise, default to the
// given stream.
2017-07-20 19:35:53 +02:00
cmsys::ofstream fout;
std::ostream* s = &os;
2018-01-26 17:06:56 +01:00
if (!rhi.Filename.empty()) {
fout.open(rhi.Filename.c_str());
2017-07-20 19:35:53 +02:00
s = &fout;
2016-07-09 11:21:54 +02:00
} else if (++count > 1) {
2014-08-03 19:52:23 +02:00
os << "\n\n";
2016-07-09 11:21:54 +02:00
}
2012-02-18 12:40:36 +02:00
// Print this documentation type to the stream.
2018-01-26 17:06:56 +01:00
if (!this->PrintDocumentation(rhi.HelpType, *s) || s->fail()) {
result = false;
2016-07-09 11:21:54 +02:00
}
}
return result;
}
2014-08-03 19:52:23 +02:00
void cmDocumentation::WarnFormFromFilename(
cmDocumentation::RequestedHelpItem& request, bool& result)
{
2014-08-03 19:52:23 +02:00
std::string ext = cmSystemTools::GetFilenameLastExtension(request.Filename);
ext = cmSystemTools::UpperCase(ext);
2016-07-09 11:21:54 +02:00
if ((ext == ".HTM") || (ext == ".HTML")) {
2014-08-03 19:52:23 +02:00
request.HelpType = cmDocumentation::None;
result = true;
cmSystemTools::Message("Warning: HTML help format no longer supported");
2016-07-09 11:21:54 +02:00
} else if (ext == ".DOCBOOK") {
2014-08-03 19:52:23 +02:00
request.HelpType = cmDocumentation::None;
result = true;
cmSystemTools::Message("Warning: Docbook help format no longer supported");
2016-07-09 11:21:54 +02:00
}
// ".1" to ".9" should be manpages
2016-07-09 11:21:54 +02:00
else if ((ext.length() == 2) && (ext[1] >= '1') && (ext[1] <= '9')) {
2014-08-03 19:52:23 +02:00
request.HelpType = cmDocumentation::None;
result = true;
cmSystemTools::Message("Warning: Man help format no longer supported");
2016-07-09 11:21:54 +02:00
}
}
2012-04-19 19:04:21 +03:00
void cmDocumentation::addCommonStandardDocSections()
{
2019-11-11 23:01:05 +01:00
cmDocumentationSection sec{ "Options" };
sec.Append(cmDocumentationStandardOptions);
this->AllSections.emplace("Options", std::move(sec));
2012-04-19 19:04:21 +03:00
}
void cmDocumentation::addCMakeStandardDocSections()
{
2019-11-11 23:01:05 +01:00
cmDocumentationSection sec{ "Generators" };
sec.Append(cmDocumentationCMakeGeneratorsHeader);
this->AllSections.emplace("Generators", std::move(sec));
2012-04-19 19:04:21 +03:00
}
void cmDocumentation::addCTestStandardDocSections()
{
2016-07-09 11:21:54 +02:00
// This is currently done for backward compatibility reason
// We may suppress some of these.
2021-09-14 00:13:48 +02:00
this->addCMakeStandardDocSections();
2012-04-19 19:04:21 +03:00
}
void cmDocumentation::addCPackStandardDocSections()
{
2019-11-11 23:01:05 +01:00
cmDocumentationSection sec{ "Generators" };
sec.Append(cmDocumentationCPackGeneratorsHeader);
this->AllSections.emplace("Generators", std::move(sec));
2012-04-19 19:04:21 +03:00
}
bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
const char* exitOpt)
{
// Providing zero arguments gives usage information.
2016-07-09 11:21:54 +02:00
if (argc == 1) {
RequestedHelpItem help;
help.HelpType = cmDocumentation::Usage;
2018-04-23 21:13:27 +02:00
this->RequestedHelpItems.push_back(std::move(help));
return true;
2016-07-09 11:21:54 +02:00
}
2023-05-23 16:38:00 +02:00
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;
2016-07-09 11:21:54 +02:00
for (int i = 1; i < argc; ++i) {
if (exitOpt && strcmp(argv[i], exitOpt) == 0) {
return result;
2016-07-09 11:21:54 +02:00
}
RequestedHelpItem help;
// Check if this is a supported help option.
2016-07-09 11:21:54 +02:00
if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0) ||
(strcmp(argv[i], "/?") == 0) || (strcmp(argv[i], "-usage") == 0) ||
(strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "-H") == 0)) {
2015-04-27 22:25:09 +02:00
help.HelpType = cmDocumentation::Help;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
help.Argument = cmSystemTools::LowerCase(help.Argument);
// special case for single command
2016-07-09 11:21:54 +02:00
if (!help.Argument.empty()) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneCommand;
}
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-properties") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneManual;
help.Argument = "cmake-properties.7";
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-policies") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneManual;
help.Argument = "cmake-policies.7";
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-variables") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneManual;
help.Argument = "cmake-variables.7";
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-modules") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneManual;
help.Argument = "cmake-modules.7";
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-custom-modules") == 0) {
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
cmSystemTools::Message(
"Warning: --help-custom-modules no longer supported");
2016-07-09 11:21:54 +02:00
if (help.Filename.empty()) {
2014-08-03 19:52:23 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
// Avoid breaking old project builds completely by at least generating
// the output file. Abuse help.Argument to give the file name to
// PrintOldCustomModules without disrupting our internal API.
help.HelpType = cmDocumentation::OldCustomModules;
help.Argument = cmSystemTools::GetFilenameName(help.Filename);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-commands") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneManual;
help.Argument = "cmake-commands.7";
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-compatcommands") == 0) {
2014-08-03 19:52:23 +02:00
cmSystemTools::Message(
"Warning: --help-compatcommands no longer supported");
return true;
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-full") == 0) {
help.HelpType = cmDocumentation::Full;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-html") == 0) {
2014-08-03 19:52:23 +02:00
cmSystemTools::Message("Warning: --help-html no longer supported");
return true;
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-man") == 0) {
2014-08-03 19:52:23 +02:00
cmSystemTools::Message("Warning: --help-man no longer supported");
return true;
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-command") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneCommand;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
i += int(get_opt_argument(i + 1, help.Filename));
help.Argument = cmSystemTools::LowerCase(help.Argument);
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-module") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneModule;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-property") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneProperty;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-policy") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OnePolicy;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-variable") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneVariable;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-manual") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::OneManual;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Argument));
i += int(get_opt_argument(i + 1, help.Filename));
2014-08-03 19:52:23 +02:00
this->WarnFormFromFilename(help, result);
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-command-list") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::ListCommands;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-module-list") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::ListModules;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-property-list") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::ListProperties;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-variable-list") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::ListVariables;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-policy-list") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::ListPolicies;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--help-manual-list") == 0) {
2014-08-03 19:52:23 +02:00
help.HelpType = cmDocumentation::ListManuals;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
} else if (strcmp(argv[i], "--copyright") == 0) {
2014-08-03 19:52:23 +02:00
cmSystemTools::Message("Warning: --copyright no longer supported");
return true;
2016-07-09 11:21:54 +02:00
} else if ((strcmp(argv[i], "--version") == 0) ||
(strcmp(argv[i], "-version") == 0) ||
(strcmp(argv[i], "/V") == 0)) {
help.HelpType = cmDocumentation::Version;
2023-05-23 16:38:00 +02:00
i += int(get_opt_argument(i + 1, help.Filename));
2016-07-09 11:21:54 +02:00
}
if (help.HelpType != None) {
// This is a help option. See if there is a file name given.
result = true;
2018-04-23 21:13:27 +02:00
this->RequestedHelpItems.push_back(std::move(help));
}
2016-07-09 11:21:54 +02:00
}
return result;
}
2015-04-27 22:25:09 +02:00
void cmDocumentation::SetName(const std::string& name)
{
2015-04-27 22:25:09 +02:00
this->NameString = name;
}
2016-07-09 11:21:54 +02:00
void cmDocumentation::SetSection(const char* name,
2019-11-11 23:01:05 +01:00
cmDocumentationSection section)
{
2019-11-11 23:01:05 +01:00
this->SectionAtName(name) = std::move(section);
}
2019-11-11 23:01:05 +01:00
cmDocumentationSection& cmDocumentation::SectionAtName(const char* name)
{
return this->AllSections.emplace(name, cmDocumentationSection{ name })
.first->second;
}
2016-07-09 11:21:54 +02:00
void cmDocumentation::AppendSection(const char* name,
cmDocumentationEntry& docs)
{
std::vector<cmDocumentationEntry> docsVec;
docsVec.push_back(docs);
2016-07-09 11:21:54 +02:00
this->AppendSection(name, docsVec);
}
2016-07-09 11:21:54 +02:00
void cmDocumentation::PrependSection(const char* name,
cmDocumentationEntry& docs)
{
std::vector<cmDocumentationEntry> docsVec;
docsVec.push_back(docs);
2016-07-09 11:21:54 +02:00
this->PrependSection(name, docsVec);
}
2014-08-03 19:52:23 +02:00
void cmDocumentation::GlobHelp(std::vector<std::string>& files,
std::string const& pattern)
{
2014-08-03 19:52:23 +02:00
cmsys::Glob gl;
std::string findExpr =
cmSystemTools::GetCMakeRoot() + "/Help/" + pattern + ".rst";
2016-07-09 11:21:54 +02:00
if (gl.FindFiles(findExpr)) {
2014-08-03 19:52:23 +02:00
files = gl.GetFiles();
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
void cmDocumentation::PrintNames(std::ostream& os, std::string const& pattern)
{
2014-08-03 19:52:23 +02:00
std::vector<std::string> files;
this->GlobHelp(files, pattern);
std::vector<std::string> names;
2018-01-26 17:06:56 +01:00
for (std::string const& f : files) {
2014-08-03 19:52:23 +02:00
std::string line;
2018-01-26 17:06:56 +01:00
cmsys::ifstream fin(f.c_str());
2016-07-09 11:21:54 +02:00
while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
if (!line.empty() && (isalnum(line[0]) || line[0] == '<')) {
2014-08-03 19:52:23 +02:00
names.push_back(line);
break;
}
}
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
std::sort(names.begin(), names.end());
2018-01-26 17:06:56 +01:00
for (std::string const& n : names) {
2023-05-23 16:38:00 +02:00
os << n << '\n';
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
bool cmDocumentation::PrintFiles(std::ostream& os, std::string const& pattern)
{
2014-08-03 19:52:23 +02:00
bool found = false;
std::vector<std::string> files;
this->GlobHelp(files, pattern);
std::sort(files.begin(), files.end());
cmRST r(os, cmSystemTools::GetCMakeRoot() + "/Help");
2018-01-26 17:06:56 +01:00
for (std::string const& f : files) {
found = r.ProcessFile(f) || found;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
return found;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpFull(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
return this->PrintFiles(os, "index");
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpOneManual(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
std::string mname = this->CurrentArgument;
std::string::size_type mlen = mname.length();
2016-07-09 11:21:54 +02:00
if (mlen > 3 && mname[mlen - 3] == '(' && mname[mlen - 1] == ')') {
mname = mname.substr(0, mlen - 3) + "." + mname[mlen - 2];
}
if (this->PrintFiles(os, "manual/" + mname) ||
this->PrintFiles(os, "manual/" + mname + ".[0-9]")) {
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
// Argument was not a manual. Complain.
2015-04-27 22:25:09 +02:00
os << "Argument \"" << this->CurrentArgument
2014-08-03 19:52:23 +02:00
<< "\" to --help-manual is not an available manual. "
2023-05-23 16:38:00 +02:00
"Use --help-manual-list to see all available manuals.\n";
return false;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpListManuals(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
this->PrintNames(os, "manual/*");
return true;
}
bool cmDocumentation::PrintHelpOneCommand(std::ostream& os)
{
std::string cname = cmSystemTools::LowerCase(this->CurrentArgument);
2016-07-09 11:21:54 +02:00
if (this->PrintFiles(os, "command/" + cname)) {
return true;
2016-07-09 11:21:54 +02:00
}
// Argument was not a command. Complain.
2015-04-27 22:25:09 +02:00
os << "Argument \"" << this->CurrentArgument
2014-08-03 19:52:23 +02:00
<< "\" to --help-command is not a CMake command. "
2023-05-23 16:38:00 +02:00
"Use --help-command-list to see all commands.\n";
return false;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpListCommands(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
this->PrintNames(os, "command/*");
return true;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpOneModule(std::ostream& os)
{
std::string mname = this->CurrentArgument;
2016-07-09 11:21:54 +02:00
if (this->PrintFiles(os, "module/" + mname)) {
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
// Argument was not a module. Complain.
2015-04-27 22:25:09 +02:00
os << "Argument \"" << this->CurrentArgument
2014-08-03 19:52:23 +02:00
<< "\" to --help-module is not a CMake module.\n";
return false;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpListModules(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
std::vector<std::string> files;
this->GlobHelp(files, "module/*");
std::vector<std::string> modules;
2018-01-26 17:06:56 +01:00
for (std::string const& f : files) {
std::string module = cmSystemTools::GetFilenameName(f);
2016-07-09 11:21:54 +02:00
modules.push_back(module.substr(0, module.size() - 4));
}
2014-08-03 19:52:23 +02:00
std::sort(modules.begin(), modules.end());
2018-01-26 17:06:56 +01:00
for (std::string const& m : modules) {
2023-05-23 16:38:00 +02:00
os << m << '\n';
2016-07-09 11:21:54 +02:00
}
return true;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpOneProperty(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
std::string pname = cmSystemTools::HelpFileName(this->CurrentArgument);
2016-07-09 11:21:54 +02:00
if (this->PrintFiles(os, "prop_*/" + pname)) {
2014-08-03 19:52:23 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
// Argument was not a property. Complain.
2015-04-27 22:25:09 +02:00
os << "Argument \"" << this->CurrentArgument
2014-08-03 19:52:23 +02:00
<< "\" to --help-property is not a CMake property. "
2023-05-23 16:38:00 +02:00
"Use --help-property-list to see all properties.\n";
2014-08-03 19:52:23 +02:00
return false;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpListProperties(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
this->PrintNames(os, "prop_*/*");
return true;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpOnePolicy(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
std::string pname = this->CurrentArgument;
std::vector<std::string> files;
2016-07-09 11:21:54 +02:00
if (this->PrintFiles(os, "policy/" + pname)) {
2014-08-03 19:52:23 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
// Argument was not a policy. Complain.
2015-04-27 22:25:09 +02:00
os << "Argument \"" << this->CurrentArgument
2014-08-03 19:52:23 +02:00
<< "\" to --help-policy is not a CMake policy.\n";
return false;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpListPolicies(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
this->PrintNames(os, "policy/*");
return true;
}
2015-08-17 11:37:30 +02:00
bool cmDocumentation::PrintHelpListGenerators(std::ostream& os)
{
2019-11-11 23:01:05 +01:00
const auto si = this->AllSections.find("Generators");
2016-07-09 11:21:54 +02:00
if (si != this->AllSections.end()) {
2019-11-11 23:01:05 +01:00
this->Formatter.PrintSection(os, si->second);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
return true;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpOneVariable(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
std::string vname = cmSystemTools::HelpFileName(this->CurrentArgument);
2016-07-09 11:21:54 +02:00
if (this->PrintFiles(os, "variable/" + vname)) {
2014-08-03 19:52:23 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
// Argument was not a variable. Complain.
2015-04-27 22:25:09 +02:00
os << "Argument \"" << this->CurrentArgument
2014-08-03 19:52:23 +02:00
<< "\" to --help-variable is not a defined variable. "
2023-05-23 16:38:00 +02:00
"Use --help-variable-list to see all defined variables.\n";
2014-08-03 19:52:23 +02:00
return false;
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintHelpListVariables(std::ostream& os)
{
2014-08-03 19:52:23 +02:00
this->PrintNames(os, "variable/*");
return true;
}
2015-04-27 22:25:09 +02:00
bool cmDocumentation::PrintUsage(std::ostream& os)
{
2019-11-11 23:01:05 +01:00
const auto si = this->AllSections.find("Usage");
2016-07-09 11:21:54 +02:00
if (si != this->AllSections.end()) {
2019-11-11 23:01:05 +01:00
this->Formatter.PrintSection(os, si->second);
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
return true;
}
bool cmDocumentation::PrintHelp(std::ostream& os)
{
2019-11-11 23:01:05 +01:00
auto si = this->AllSections.find("Usage");
2016-07-09 11:21:54 +02:00
if (si != this->AllSections.end()) {
2019-11-11 23:01:05 +01:00
this->Formatter.PrintSection(os, si->second);
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
si = this->AllSections.find("Options");
2016-07-09 11:21:54 +02:00
if (si != this->AllSections.end()) {
2019-11-11 23:01:05 +01:00
this->Formatter.PrintSection(os, si->second);
2016-07-09 11:21:54 +02:00
}
if (this->ShowGenerators) {
2014-08-03 19:52:23 +02:00
si = this->AllSections.find("Generators");
2016-07-09 11:21:54 +02:00
if (si != this->AllSections.end()) {
2019-11-11 23:01:05 +01:00
this->Formatter.PrintSection(os, si->second);
}
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
return true;
}
const char* cmDocumentation::GetNameString() const
{
2016-07-09 11:21:54 +02:00
if (!this->NameString.empty()) {
return this->NameString.c_str();
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
return "CMake";
}
2014-08-03 19:52:23 +02:00
bool cmDocumentation::PrintOldCustomModules(std::ostream& os)
{
// CheckOptions abuses the Argument field to give us the file name.
std::string filename = this->CurrentArgument;
std::string ext = cmSystemTools::UpperCase(
cmSystemTools::GetFilenameLastExtension(filename));
std::string name = cmSystemTools::GetFilenameWithoutLastExtension(filename);
const char* summary = "cmake --help-custom-modules no longer supported\n";
const char* detail =
"CMake versions prior to 3.0 exposed their internal module help page\n"
"generation functionality through the --help-custom-modules option.\n"
"CMake versions 3.0 and above use other means to generate their module\n"
"help pages so this functionality is no longer available to be exposed.\n"
"\n"
2016-07-09 11:21:54 +02:00
"This file was generated as a placeholder to provide this information.\n";
if ((ext == ".HTM") || (ext == ".HTML")) {
2014-08-03 19:52:23 +02:00
os << "<html><title>" << name << "</title><body>\n"
2016-07-09 11:21:54 +02:00
<< summary << "<p/>\n"
<< detail << "</body></html>\n";
} else if ((ext.length() == 2) && (ext[1] >= '1') && (ext[1] <= '9')) {
/* clang-format off */
2014-08-03 19:52:23 +02:00
os <<
2023-05-23 16:38:00 +02:00
".TH " << name << ' ' << ext[1] << " \"" <<
2014-08-03 19:52:23 +02:00
cmSystemTools::GetCurrentDateTime("%B %d, %Y") <<
"\" \"cmake " << cmVersion::GetCMakeVersion() << "\"\n"
".SH NAME\n"
".PP\n" <<
name << " \\- " << summary <<
"\n"
".SH DESCRIPTION\n"
".PP\n" <<
detail
;
2016-07-09 11:21:54 +02:00
/* clang-format on */
} else {
2023-05-23 16:38:00 +02:00
os << name << "\n\n" << summary << '\n' << detail;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
return true;
}