cmDocumentation.h 4.5 KB

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