cmDocumentation.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. // High-level interface for standard documents:
  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, const char* docname=0);
  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, SeeAlso */
  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, 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. void SetSeeAlsoList(const char *data[][3]);
  94. /** Clear all previously added sections of help. */
  95. void ClearSections();
  96. /** Set cmake root so we can find installed files */
  97. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  98. /** Set CMAKE_MODULE_PATH so we can find additional cmake modules */
  99. void SetCMakeModulePath(const char* path) { this->CMakeModulePath = path;}
  100. static Form GetFormFromFilename(const std::string& filename);
  101. /** Add common (to all tools) documentation section(s) */
  102. void addCommonStandardDocSections();
  103. /** Add the CMake standard documentation section(s) */
  104. void addCMakeStandardDocSections();
  105. /** Add the CTest standard documentation section(s) */
  106. void addCTestStandardDocSections();
  107. /** Add the CPack standard documentation section(s) */
  108. void addCPackStandardDocSections();
  109. /**
  110. * Get the documentation of macros and variable documented
  111. * with CMake structured documentation in a CMake script.
  112. * Structured documentation begin with
  113. * ## (double sharp) in column 1 & 2 immediately followed
  114. * by a markup. Those ## are ignored by the legacy module
  115. * documentation parser @see CreateSingleModule.
  116. * Current markup are ##macro, ##param, ##variable and ##end
  117. * which is closing either of the previous ones.
  118. * @param[in] fname the script file name to be parsed for documentation
  119. * @param[in,out] commands the vector of command/macros documentation
  120. * entry found in the script file.
  121. * @param[in,out] the cmake object instance to which variable documentation
  122. * will be attached (using @see cmake::DefineProperty)
  123. * @return the number of documented items (command and variable)
  124. * found in the file.
  125. */
  126. int getStructuredDocFromFile(const char* fname,
  127. std::vector<cmDocumentationEntry>& commands,
  128. cmake* cm,
  129. const char *docSection);
  130. ;
  131. private:
  132. void SetForm(Form f);
  133. void SetDocName(const char* docname);
  134. bool CreateSingleModule(const char* fname,
  135. const char* moduleName,
  136. cmDocumentationSection &sec);
  137. void CreateModuleDocsForDir(cmsys::Directory& dir,
  138. cmDocumentationSection &moduleSection);
  139. bool CreateModulesSection();
  140. bool CreateCustomModulesSection();
  141. void CreateFullDocumentation();
  142. void AddDocumentIntroToPrint(const char* intro[2]);
  143. bool PrintCopyright(std::ostream& os);
  144. bool PrintVersion(std::ostream& os);
  145. bool PrintDocumentationGeneric(std::ostream& os, const char *section);
  146. bool PrintDocumentationList(std::ostream& os, const char *section);
  147. bool PrintDocumentationSingle(std::ostream& os);
  148. bool PrintDocumentationSingleModule(std::ostream& os);
  149. bool PrintDocumentationSingleProperty(std::ostream& os);
  150. bool PrintDocumentationSinglePolicy(std::ostream& os);
  151. bool PrintDocumentationSingleVariable(std::ostream& os);
  152. bool PrintDocumentationUsage(std::ostream& os);
  153. bool PrintDocumentationFull(std::ostream& os);
  154. bool PrintDocumentationModules(std::ostream& os);
  155. bool PrintDocumentationCustomModules(std::ostream& os);
  156. bool PrintDocumentationPolicies(std::ostream& os);
  157. bool PrintDocumentationProperties(std::ostream& os);
  158. bool PrintDocumentationVariables(std::ostream& os);
  159. bool PrintDocumentationCurrentCommands(std::ostream& os);
  160. bool PrintDocumentationCompatCommands(std::ostream& os);
  161. void PrintDocumentationCommand(std::ostream& os,
  162. const cmDocumentationEntry &entry);
  163. const char* GetNameString() const;
  164. const char* GetDocName(bool fallbackToNameString = true) const;
  165. const char* GetDefaultDocName(Type ht) const;
  166. bool IsOption(const char* arg) const;
  167. bool ShowGenerators;
  168. std::string NameString;
  169. std::string DocName;
  170. std::map<std::string,cmDocumentationSection*> AllSections;
  171. std::string SeeAlsoString;
  172. std::string CMakeRoot;
  173. std::string CMakeModulePath;
  174. std::set<std::string> ModulesFound;
  175. std::vector< char* > ModuleStrings;
  176. std::vector<const cmDocumentationSection *> PrintSections;
  177. std::string CurrentArgument;
  178. struct RequestedHelpItem
  179. {
  180. RequestedHelpItem():HelpForm(TextForm), HelpType(None) {}
  181. cmDocumentationEnums::Form HelpForm;
  182. cmDocumentationEnums::Type HelpType;
  183. std::string Filename;
  184. std::string Argument;
  185. };
  186. std::vector<RequestedHelpItem> RequestedHelpItems;
  187. cmDocumentationFormatter* CurrentFormatter;
  188. cmDocumentationFormatterHTML HTMLFormatter;
  189. cmDocumentationFormatterDocbook DocbookFormatter;
  190. cmDocumentationFormatterMan ManFormatter;
  191. cmDocumentationFormatterText TextFormatter;
  192. cmDocumentationFormatterUsage UsageFormatter;
  193. std::vector<std::string> PropertySections;
  194. std::vector<std::string> VariableSections;
  195. };
  196. #endif