cmDocumentation.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "cmStandardIncludes.h"
  13. #include "cmProperty.h"
  14. #include "cmDocumentationFormatter.h"
  15. #include "cmDocumentationFormatterHTML.h"
  16. #include "cmDocumentationFormatterDocbook.h"
  17. #include "cmDocumentationFormatterMan.h"
  18. #include "cmDocumentationFormatterRST.h"
  19. #include "cmDocumentationFormatterText.h"
  20. #include "cmDocumentationFormatterUsage.h"
  21. #include "cmDocumentationSection.h"
  22. #include "cmake.h"
  23. namespace cmsys
  24. {
  25. class Directory;
  26. }
  27. /** Class to generate documentation. */
  28. class cmDocumentation: public cmDocumentationEnums
  29. {
  30. public:
  31. cmDocumentation();
  32. ~cmDocumentation();
  33. /**
  34. * Check command line arguments for documentation options. Returns
  35. * true if documentation options are found, and false otherwise.
  36. * When true is returned, PrintRequestedDocumentation should be
  37. * called. exitOpt can be used for things like cmake -E, so that
  38. * all arguments after the -E are ignored and not searched for
  39. * help arguments.
  40. */
  41. bool CheckOptions(int argc, const char* const* argv,
  42. const char* exitOpt =0);
  43. /**
  44. * Print help requested on the command line. Call after
  45. * CheckOptions returns true. Returns true on success, and false
  46. * otherwise. Failure can occur when output files specified on the
  47. * command line cannot be written.
  48. */
  49. bool PrintRequestedDocumentation(std::ostream& os);
  50. /** Print help of the given type. */
  51. bool PrintDocumentation(Type ht, std::ostream& os);
  52. void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
  53. /** Set the program name for standard document generation. */
  54. void SetName(const char* name);
  55. /** Set a section of the documentation. Typical sections include Name,
  56. Usage, Description, Options */
  57. void SetSection(const char *sectionName,
  58. cmDocumentationSection *section);
  59. void SetSection(const char *sectionName,
  60. std::vector<cmDocumentationEntry> &docs);
  61. void SetSection(const char *sectionName,
  62. const char *docs[][3]);
  63. void SetSections(std::map<std::string,cmDocumentationSection *>
  64. &sections);
  65. /** Add the documentation to the beginning/end of the section */
  66. void PrependSection(const char *sectionName,
  67. const char *docs[][3]);
  68. void PrependSection(const char *sectionName,
  69. std::vector<cmDocumentationEntry> &docs);
  70. void PrependSection(const char *sectionName,
  71. cmDocumentationEntry &docs);
  72. void AppendSection(const char *sectionName,
  73. const char *docs[][3]);
  74. void AppendSection(const char *sectionName,
  75. std::vector<cmDocumentationEntry> &docs);
  76. void AppendSection(const char *sectionName,
  77. cmDocumentationEntry &docs);
  78. /**
  79. * Print documentation in the given form. All previously added
  80. * sections will be generated.
  81. */
  82. void Print(Form f, int manSection, std::ostream& os);
  83. /**
  84. * Print documentation in the current form. All previously added
  85. * sections will be generated.
  86. */
  87. void Print(std::ostream& os);
  88. /**
  89. * Add a section of documentation. This can be used to generate custom help
  90. * documents.
  91. */
  92. void AddSectionToPrint(const char *section);
  93. /** Clear all previously added sections of help. */
  94. void ClearSections();
  95. /** Set cmake root so we can find installed files */
  96. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  97. static Form GetFormFromFilename(const std::string& filename,
  98. int* ManSection);
  99. /** Add common (to all tools) documentation section(s) */
  100. void addCommonStandardDocSections();
  101. /** Add the CMake standard documentation section(s) */
  102. void addCMakeStandardDocSections();
  103. /** Add the CTest standard documentation section(s) */
  104. void addCTestStandardDocSections();
  105. /** Add the CPack standard documentation section(s) */
  106. void addCPackStandardDocSections();
  107. private:
  108. void SetForm(Form f, int manSection);
  109. void GlobHelp(std::vector<std::string>& files, std::string const& pattern);
  110. void PrintNames(std::ostream& os, std::string const& pattern);
  111. bool PrintFiles(std::ostream& os, std::string const& pattern);
  112. bool PrintVersion(std::ostream& os);
  113. bool PrintHelpOneManual(std::ostream& os);
  114. bool PrintHelpOneCommand(std::ostream& os);
  115. bool PrintHelpOneModule(std::ostream& os);
  116. bool PrintHelpOnePolicy(std::ostream& os);
  117. bool PrintHelpOneProperty(std::ostream& os);
  118. bool PrintHelpOneVariable(std::ostream& os);
  119. bool PrintHelpListManuals(std::ostream& os);
  120. bool PrintHelpListCommands(std::ostream& os);
  121. bool PrintHelpListModules(std::ostream& os);
  122. bool PrintHelpListProperties(std::ostream& os);
  123. bool PrintHelpListVariables(std::ostream& os);
  124. bool PrintHelpListPolicies(std::ostream& os);
  125. bool PrintDocumentationUsage(std::ostream& os);
  126. const char* GetNameString() const;
  127. bool IsOption(const char* arg) const;
  128. bool ShowGenerators;
  129. std::string NameString;
  130. std::map<std::string,cmDocumentationSection*> AllSections;
  131. std::string CMakeRoot;
  132. std::vector<const cmDocumentationSection *> PrintSections;
  133. std::string CurrentArgument;
  134. struct RequestedHelpItem
  135. {
  136. RequestedHelpItem():HelpForm(TextForm), HelpType(None), ManSection(1) {}
  137. cmDocumentationEnums::Form HelpForm;
  138. cmDocumentationEnums::Type HelpType;
  139. std::string Filename;
  140. std::string Argument;
  141. int ManSection;
  142. };
  143. std::vector<RequestedHelpItem> RequestedHelpItems;
  144. cmDocumentationFormatter* CurrentFormatter;
  145. cmDocumentationFormatterHTML HTMLFormatter;
  146. cmDocumentationFormatterDocbook DocbookFormatter;
  147. cmDocumentationFormatterMan ManFormatter;
  148. cmDocumentationFormatterRST RSTFormatter;
  149. cmDocumentationFormatterText TextFormatter;
  150. cmDocumentationFormatterUsage UsageFormatter;
  151. };
  152. #endif