cmDocumentation.h 7.0 KB

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