cmDocumentation.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <iosfwd>
  6. #include <map>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "cmDocumentationFormatter.h"
  11. #include "cmDocumentationSection.h"
  12. struct cmDocumentationEntry;
  13. /** Class to generate documentation. */
  14. class cmDocumentation
  15. {
  16. public:
  17. /** Types of help provided. */
  18. enum Type
  19. {
  20. None,
  21. Version,
  22. Usage,
  23. Help,
  24. Full,
  25. ListManuals,
  26. ListCommands,
  27. ListModules,
  28. ListProperties,
  29. ListVariables,
  30. ListPolicies,
  31. ListGenerators,
  32. OneArbitrary,
  33. OneManual,
  34. OneCommand,
  35. OneModule,
  36. OneProperty,
  37. OneVariable,
  38. OnePolicy,
  39. OldCustomModules
  40. };
  41. cmDocumentation();
  42. /**
  43. * Check command line arguments for documentation options. Returns
  44. * true if documentation options are found, and false otherwise.
  45. * When true is returned, PrintRequestedDocumentation should be
  46. * called. exitOpt can be used for things like cmake -E, so that
  47. * all arguments after the -E are ignored and not searched for
  48. * help arguments.
  49. */
  50. bool CheckOptions(int argc, const char* const* argv,
  51. const char* exitOpt = nullptr);
  52. /**
  53. * Print help requested on the command line. Call after
  54. * CheckOptions returns true. Returns true on success, and false
  55. * otherwise. Failure can occur when output files specified on the
  56. * command line cannot be written.
  57. */
  58. bool PrintRequestedDocumentation(std::ostream& os);
  59. /** Print help of the given type. */
  60. bool PrintDocumentation(Type ht, std::ostream& os);
  61. void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
  62. /** Set the program name for standard document generation. */
  63. void SetName(const std::string& name);
  64. /** Set a section of the documentation. Typical sections include Name,
  65. Usage, Description, Options */
  66. void SetSection(const char* sectionName, cmDocumentationSection section);
  67. template <typename Iterable>
  68. void SetSection(const char* sectionName, const Iterable& docs)
  69. {
  70. cmDocumentationSection sec{ sectionName };
  71. sec.Append(docs);
  72. this->SetSection(sectionName, std::move(sec));
  73. }
  74. /** Add the documentation to the beginning/end of the section */
  75. template <typename Iterable>
  76. void PrependSection(const char* sectionName, const Iterable& docs)
  77. {
  78. this->SectionAtName(sectionName).Prepend(docs);
  79. }
  80. void PrependSection(const char* sectionName, cmDocumentationEntry& docs);
  81. template <typename Iterable>
  82. void AppendSection(const char* sectionName, const Iterable& docs)
  83. {
  84. this->SectionAtName(sectionName).Append(docs);
  85. }
  86. void AppendSection(const char* sectionName, cmDocumentationEntry& docs);
  87. /** Add common (to all tools) documentation section(s) */
  88. void addCommonStandardDocSections();
  89. /** Add the CMake standard documentation section(s) */
  90. void addCMakeStandardDocSections();
  91. /** Add the CTest standard documentation section(s) */
  92. void addCTestStandardDocSections();
  93. /** Add the CPack standard documentation section(s) */
  94. void addCPackStandardDocSections();
  95. private:
  96. void GlobHelp(std::vector<std::string>& files, std::string const& pattern);
  97. void PrintNames(std::ostream& os, std::string const& pattern);
  98. bool PrintFiles(std::ostream& os, std::string const& pattern);
  99. bool PrintVersion(std::ostream& os);
  100. bool PrintUsage(std::ostream& os);
  101. bool PrintHelp(std::ostream& os);
  102. bool PrintHelpFull(std::ostream& os);
  103. bool PrintHelpOneArbitrary(std::ostream& os);
  104. bool PrintHelpOneManual(std::ostream& os);
  105. bool PrintHelpOneCommand(std::ostream& os);
  106. bool PrintHelpOneModule(std::ostream& os);
  107. bool PrintHelpOnePolicy(std::ostream& os);
  108. bool PrintHelpOneProperty(std::ostream& os);
  109. bool PrintHelpOneVariable(std::ostream& os);
  110. bool PrintHelpListManuals(std::ostream& os);
  111. bool PrintHelpListCommands(std::ostream& os);
  112. bool PrintHelpListModules(std::ostream& os);
  113. bool PrintHelpListProperties(std::ostream& os);
  114. bool PrintHelpListVariables(std::ostream& os);
  115. bool PrintHelpListPolicies(std::ostream& os);
  116. bool PrintHelpListGenerators(std::ostream& os);
  117. bool PrintOldCustomModules(std::ostream& os);
  118. const char* GetNameString() const;
  119. bool ShowGenerators;
  120. std::string NameString;
  121. std::map<std::string, cmDocumentationSection> AllSections;
  122. cmDocumentationSection& SectionAtName(const char* name);
  123. std::string CurrentArgument;
  124. struct RequestedHelpItem
  125. {
  126. Type HelpType = None;
  127. std::string Filename;
  128. std::string Argument;
  129. };
  130. std::vector<RequestedHelpItem> RequestedHelpItems;
  131. cmDocumentationFormatter Formatter;
  132. static void WarnFormFromFilename(RequestedHelpItem& request, bool& result);
  133. static std::string GeneralizeKeyword(std::string word);
  134. };