cmDocumentation.h 4.9 KB

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