cmDocumentation.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 "cmDocumentationFormatterText.h"
  19. #include "cmDocumentationFormatterUsage.h"
  20. #include "cmDocumentationSection.h"
  21. #include "cmake.h"
  22. namespace cmsys
  23. {
  24. class Directory;
  25. }
  26. /** Class to generate documentation. */
  27. class cmDocumentation: public cmDocumentationEnums
  28. {
  29. public:
  30. cmDocumentation();
  31. ~cmDocumentation();
  32. /**
  33. * An helper type pair for [structured] documented modules.
  34. * The comment of those module contains structure markup
  35. * which makes it possible to retrieve the documentation
  36. * of variables, macros and functions defined in the module.
  37. * - first is the filename of the module
  38. * - second is the section of the doc the module belongs too
  39. */
  40. typedef std::pair<std::string,std::string> documentedModuleSectionPair_t;
  41. /**
  42. * A list of documented module(s).
  43. */
  44. typedef std::list<documentedModuleSectionPair_t> documentedModulesList_t;
  45. // High-level interface for standard documents:
  46. /**
  47. * Check command line arguments for documentation options. Returns
  48. * true if documentation options are found, and false otherwise.
  49. * When true is returned, PrintRequestedDocumentation should be
  50. * called. exitOpt can be used for things like cmake -E, so that
  51. * all arguments after the -E are ignored and not searched for
  52. * help arguments.
  53. */
  54. bool CheckOptions(int argc, const char* const* argv,
  55. const char* exitOpt =0);
  56. /**
  57. * Print help requested on the command line. Call after
  58. * CheckOptions returns true. Returns true on success, and false
  59. * otherwise. Failure can occur when output files specified on the
  60. * command line cannot be written.
  61. */
  62. bool PrintRequestedDocumentation(std::ostream& os);
  63. /** Print help of the given type. */
  64. bool PrintDocumentation(Type ht, std::ostream& os, const char* docname=0);
  65. void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
  66. /** Set the program name for standard document generation. */
  67. void SetName(const char* name);
  68. /** Set a section of the documentation. Typical sections include Name,
  69. Usage, Description, Options, SeeAlso */
  70. void SetSection(const char *sectionName,
  71. cmDocumentationSection *section);
  72. void SetSection(const char *sectionName,
  73. std::vector<cmDocumentationEntry> &docs);
  74. void SetSection(const char *sectionName,
  75. const char *docs[][3]);
  76. void SetSections(std::map<std::string,cmDocumentationSection *>
  77. &sections);
  78. /** Add the documentation to the beginning/end of the section */
  79. void PrependSection(const char *sectionName,
  80. const char *docs[][3]);
  81. void PrependSection(const char *sectionName,
  82. std::vector<cmDocumentationEntry> &docs);
  83. void PrependSection(const char *sectionName,
  84. cmDocumentationEntry &docs);
  85. void AppendSection(const char *sectionName,
  86. const char *docs[][3]);
  87. void AppendSection(const char *sectionName,
  88. std::vector<cmDocumentationEntry> &docs);
  89. void AppendSection(const char *sectionName,
  90. cmDocumentationEntry &docs);
  91. /**
  92. * Print documentation in the given form. All previously added
  93. * sections will be generated.
  94. */
  95. void Print(Form f, int manSection, std::ostream& os);
  96. /**
  97. * Print documentation in the current form. All previously added
  98. * sections will be generated.
  99. */
  100. void Print(std::ostream& os);
  101. /**
  102. * Add a section of documentation. This can be used to generate custom help
  103. * documents.
  104. */
  105. void AddSectionToPrint(const char *section);
  106. void SetSeeAlsoList(const char *data[][3]);
  107. /** Clear all previously added sections of help. */
  108. void ClearSections();
  109. /** Set cmake root so we can find installed files */
  110. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  111. /** Set CMAKE_MODULE_PATH so we can find additional cmake modules */
  112. void SetCMakeModulePath(const char* path) { this->CMakeModulePath = path;}
  113. static Form GetFormFromFilename(const std::string& filename,
  114. int* ManSection);
  115. /** Add common (to all tools) documentation section(s) */
  116. void addCommonStandardDocSections();
  117. /** Add the CMake standard documentation section(s) */
  118. void addCMakeStandardDocSections();
  119. /** Add the CTest standard documentation section(s) */
  120. void addCTestStandardDocSections();
  121. /** Add the CPack standard documentation section(s) */
  122. void addCPackStandardDocSections();
  123. /** Add automatic variables sections */
  124. void addAutomaticVariableSections(const std::string& section);
  125. private:
  126. void SetForm(Form f, int manSection);
  127. void SetDocName(const char* docname);
  128. bool CreateSingleModule(const char* fname,
  129. const char* moduleName,
  130. cmDocumentationSection &sec);
  131. void CreateModuleDocsForDir(cmsys::Directory& dir,
  132. cmDocumentationSection &moduleSection);
  133. bool CreateModulesSection();
  134. bool CreateCustomModulesSection();
  135. void CreateFullDocumentation();
  136. void AddDocumentIntroToPrint(const char* intro[2]);
  137. bool PrintCopyright(std::ostream& os);
  138. bool PrintVersion(std::ostream& os);
  139. bool PrintDocumentationGeneric(std::ostream& os, const char *section);
  140. bool PrintDocumentationList(std::ostream& os, const char *section);
  141. bool PrintDocumentationSingle(std::ostream& os);
  142. bool PrintDocumentationSingleModule(std::ostream& os);
  143. bool PrintDocumentationSingleProperty(std::ostream& os);
  144. bool PrintDocumentationSinglePolicy(std::ostream& os);
  145. bool PrintDocumentationSingleVariable(std::ostream& os);
  146. bool PrintDocumentationUsage(std::ostream& os);
  147. bool PrintDocumentationFull(std::ostream& os);
  148. bool PrintDocumentationModules(std::ostream& os);
  149. bool PrintDocumentationCustomModules(std::ostream& os);
  150. bool PrintDocumentationPolicies(std::ostream& os);
  151. bool PrintDocumentationProperties(std::ostream& os);
  152. bool PrintDocumentationVariables(std::ostream& os);
  153. bool PrintDocumentationCurrentCommands(std::ostream& os);
  154. bool PrintDocumentationCompatCommands(std::ostream& os);
  155. void PrintDocumentationCommand(std::ostream& os,
  156. const cmDocumentationEntry &entry);
  157. const char* GetNameString() const;
  158. const char* GetDocName(bool fallbackToNameString = true) const;
  159. const char* GetDefaultDocName(Type ht) const;
  160. bool IsOption(const char* arg) const;
  161. bool ShowGenerators;
  162. std::string NameString;
  163. std::string DocName;
  164. std::map<std::string,cmDocumentationSection*> AllSections;
  165. std::string SeeAlsoString;
  166. std::string CMakeRoot;
  167. std::string CMakeModulePath;
  168. std::set<std::string> ModulesFound;
  169. std::vector< char* > ModuleStrings;
  170. std::vector<const cmDocumentationSection *> PrintSections;
  171. std::string CurrentArgument;
  172. struct RequestedHelpItem
  173. {
  174. RequestedHelpItem():HelpForm(TextForm), HelpType(None), ManSection(1) {}
  175. cmDocumentationEnums::Form HelpForm;
  176. cmDocumentationEnums::Type HelpType;
  177. std::string Filename;
  178. std::string Argument;
  179. int ManSection;
  180. };
  181. std::vector<RequestedHelpItem> RequestedHelpItems;
  182. cmDocumentationFormatter* CurrentFormatter;
  183. cmDocumentationFormatterHTML HTMLFormatter;
  184. cmDocumentationFormatterDocbook DocbookFormatter;
  185. cmDocumentationFormatterMan ManFormatter;
  186. cmDocumentationFormatterText TextFormatter;
  187. cmDocumentationFormatterUsage UsageFormatter;
  188. std::vector<std::string> PropertySections;
  189. std::vector<std::string> VariableSections;
  190. };
  191. #endif