cmDocumentation.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef _cmDocumentation_h
  4. #define _cmDocumentation_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmDocumentationFormatter.h"
  7. #include "cmDocumentationSection.h"
  8. #include <iosfwd>
  9. #include <map>
  10. #include <string>
  11. #include <vector>
  12. struct cmDocumentationEntry;
  13. /** Class to generate documentation. */
  14. class cmDocumentation : public cmDocumentationEnums
  15. {
  16. public:
  17. cmDocumentation();
  18. /**
  19. * Check command line arguments for documentation options. Returns
  20. * true if documentation options are found, and false otherwise.
  21. * When true is returned, PrintRequestedDocumentation should be
  22. * called. exitOpt can be used for things like cmake -E, so that
  23. * all arguments after the -E are ignored and not searched for
  24. * help arguments.
  25. */
  26. bool CheckOptions(int argc, const char* const* argv,
  27. const char* exitOpt = nullptr);
  28. /**
  29. * Print help requested on the command line. Call after
  30. * CheckOptions returns true. Returns true on success, and false
  31. * otherwise. Failure can occur when output files specified on the
  32. * command line cannot be written.
  33. */
  34. bool PrintRequestedDocumentation(std::ostream& os);
  35. /** Print help of the given type. */
  36. bool PrintDocumentation(Type ht, std::ostream& os);
  37. void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
  38. /** Set the program name for standard document generation. */
  39. void SetName(const std::string& name);
  40. /** Set a section of the documentation. Typical sections include Name,
  41. Usage, Description, Options */
  42. void SetSection(const char* sectionName, cmDocumentationSection section);
  43. void SetSection(const char* sectionName,
  44. std::vector<cmDocumentationEntry>& docs);
  45. void SetSection(const char* sectionName, const char* docs[][2]);
  46. void SetSections(std::map<std::string, cmDocumentationSection> sections);
  47. /** Add the documentation to the beginning/end of the section */
  48. void PrependSection(const char* sectionName, const char* docs[][2]);
  49. void PrependSection(const char* sectionName,
  50. std::vector<cmDocumentationEntry>& docs);
  51. void PrependSection(const char* sectionName, cmDocumentationEntry& docs);
  52. void AppendSection(const char* sectionName, const char* docs[][2]);
  53. void AppendSection(const char* sectionName,
  54. std::vector<cmDocumentationEntry>& docs);
  55. void AppendSection(const char* sectionName, cmDocumentationEntry& docs);
  56. /** Add common (to all tools) documentation section(s) */
  57. void addCommonStandardDocSections();
  58. /** Add the CMake standard documentation section(s) */
  59. void addCMakeStandardDocSections();
  60. /** Add the CTest standard documentation section(s) */
  61. void addCTestStandardDocSections();
  62. /** Add the CPack standard documentation section(s) */
  63. void addCPackStandardDocSections();
  64. private:
  65. void GlobHelp(std::vector<std::string>& files, std::string const& pattern);
  66. void PrintNames(std::ostream& os, std::string const& pattern);
  67. bool PrintFiles(std::ostream& os, std::string const& pattern);
  68. bool PrintVersion(std::ostream& os);
  69. bool PrintUsage(std::ostream& os);
  70. bool PrintHelp(std::ostream& os);
  71. bool PrintHelpFull(std::ostream& os);
  72. bool PrintHelpOneManual(std::ostream& os);
  73. bool PrintHelpOneCommand(std::ostream& os);
  74. bool PrintHelpOneModule(std::ostream& os);
  75. bool PrintHelpOnePolicy(std::ostream& os);
  76. bool PrintHelpOneProperty(std::ostream& os);
  77. bool PrintHelpOneVariable(std::ostream& os);
  78. bool PrintHelpListManuals(std::ostream& os);
  79. bool PrintHelpListCommands(std::ostream& os);
  80. bool PrintHelpListModules(std::ostream& os);
  81. bool PrintHelpListProperties(std::ostream& os);
  82. bool PrintHelpListVariables(std::ostream& os);
  83. bool PrintHelpListPolicies(std::ostream& os);
  84. bool PrintHelpListGenerators(std::ostream& os);
  85. bool PrintOldCustomModules(std::ostream& os);
  86. const char* GetNameString() const;
  87. bool IsOption(const char* arg) const;
  88. bool ShowGenerators;
  89. std::string NameString;
  90. std::map<std::string, cmDocumentationSection> AllSections;
  91. cmDocumentationSection& SectionAtName(const char* name);
  92. std::string CurrentArgument;
  93. struct RequestedHelpItem
  94. {
  95. cmDocumentationEnums::Type HelpType = None;
  96. std::string Filename;
  97. std::string Argument;
  98. };
  99. std::vector<RequestedHelpItem> RequestedHelpItems;
  100. cmDocumentationFormatter Formatter;
  101. static void WarnFormFromFilename(RequestedHelpItem& request, bool& result);
  102. };
  103. #endif