You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.4 KiB

  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef _cmDocumentation_h
  14. #define _cmDocumentation_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmProperty.h"
  17. #include "cmDocumentationFormatter.h"
  18. #include "cmDocumentationFormatterHTML.h"
  19. #include "cmDocumentationFormatterMan.h"
  20. #include "cmDocumentationFormatterText.h"
  21. #include "cmDocumentationFormatterUsage.h"
  22. #include "cmDocumentationSection.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. // High-level interface for standard documents:
  34. /**
  35. * Check command line arguments for documentation options. Returns
  36. * true if documentation options are found, and false otherwise.
  37. * When true is returned, PrintRequestedDocumentation should be
  38. * called.
  39. */
  40. bool CheckOptions(int argc, const char* const* argv);
  41. /**
  42. * Print help requested on the command line. Call after
  43. * CheckOptions returns true. Returns true on success, and false
  44. * otherwise. Failure can occur when output files specified on the
  45. * command line cannot be written.
  46. */
  47. bool PrintRequestedDocumentation(std::ostream& os);
  48. /** Print help of the given type. */
  49. bool PrintDocumentation(Type ht, std::ostream& os);
  50. /** Set the program name for standard document generation. */
  51. void SetName(const char* name);
  52. /** Set a section of the documentation. Typical sections include Name,
  53. Usage, Description, Options, SeeAlso */
  54. void SetSection(const char *sectionName,
  55. cmDocumentationSection *section);
  56. void SetSection(const char *sectionName,
  57. std::vector<cmDocumentationEntry> &docs);
  58. void SetSection(const char *sectionName,
  59. const char *docs[][3]);
  60. void SetSections(std::map<std::string,cmDocumentationSection *>
  61. &sections);
  62. /** Add the documentation to the beginning/end of the section */
  63. void PrependSection(const char *sectionName,
  64. const char *docs[][3]);
  65. void PrependSection(const char *sectionName,
  66. std::vector<cmDocumentationEntry> &docs);
  67. void PrependSection(const char *sectionName,
  68. cmDocumentationEntry &docs);
  69. void AppendSection(const char *sectionName,
  70. const char *docs[][3]);
  71. void AppendSection(const char *sectionName,
  72. std::vector<cmDocumentationEntry> &docs);
  73. void AppendSection(const char *sectionName,
  74. cmDocumentationEntry &docs);
  75. /**
  76. * Print documentation in the given form. All previously added
  77. * sections will be generated.
  78. */
  79. void Print(Form f, std::ostream& os);
  80. /**
  81. * Print documentation in the current form. All previously added
  82. * sections will be generated.
  83. */
  84. void Print(std::ostream& os);
  85. /**
  86. * Add a section of documentation. This can be used to generate custom help
  87. * documents.
  88. */
  89. void AddSectionToPrint(const char *section);
  90. void SetSeeAlsoList(const char *data[][3]);
  91. /** Clear all previously added sections of help. */
  92. void ClearSections();
  93. /** Set cmake root so we can find installed files */
  94. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  95. /** Set CMAKE_MODULE_PATH so we can find additional cmake modules */
  96. void SetCMakeModulePath(const char* path) { this->CMakeModulePath = path;}
  97. static Form GetFormFromFilename(const std::string& filename);
  98. private:
  99. void SetForm(Form f);
  100. bool CreateSingleModule(const char* fname,
  101. const char* moduleName,
  102. cmDocumentationSection &sec);
  103. void CreateModuleDocsForDir(cmsys::Directory& dir,
  104. cmDocumentationSection &moduleSection);
  105. bool CreateModulesSection();
  106. bool CreateCustomModulesSection();
  107. void CreateFullDocumentation();
  108. bool PrintCopyright(std::ostream& os);
  109. bool PrintVersion(std::ostream& os);
  110. bool PrintDocumentationGeneric(std::ostream& os, const char *section);
  111. bool PrintDocumentationList(std::ostream& os, const char *section);
  112. bool PrintDocumentationSingle(std::ostream& os);
  113. bool PrintDocumentationSingleModule(std::ostream& os);
  114. bool PrintDocumentationSingleProperty(std::ostream& os);
  115. bool PrintDocumentationSingleVariable(std::ostream& os);
  116. bool PrintDocumentationUsage(std::ostream& os);
  117. bool PrintDocumentationFull(std::ostream& os);
  118. bool PrintDocumentationModules(std::ostream& os);
  119. bool PrintDocumentationCustomModules(std::ostream& os);
  120. bool PrintDocumentationProperties(std::ostream& os);
  121. bool PrintDocumentationVariables(std::ostream& os);
  122. bool PrintDocumentationCurrentCommands(std::ostream& os);
  123. bool PrintDocumentationCompatCommands(std::ostream& os);
  124. void PrintDocumentationCommand(std::ostream& os,
  125. const cmDocumentationEntry &entry);
  126. const char* GetNameString() const;
  127. bool IsOption(const char* arg) const;
  128. std::string NameString;
  129. std::map<std::string,cmDocumentationSection*> AllSections;
  130. std::string SeeAlsoString;
  131. std::string CMakeRoot;
  132. std::string CMakeModulePath;
  133. std::set<std::string> ModulesFound;
  134. std::vector< char* > ModuleStrings;
  135. std::vector<const cmDocumentationSection *> PrintSections;
  136. std::string CurrentArgument;
  137. struct RequestedHelpItem
  138. {
  139. RequestedHelpItem():HelpForm(TextForm), HelpType(None) {}
  140. cmDocumentationEnums::Form HelpForm;
  141. cmDocumentationEnums::Type HelpType;
  142. std::string Filename;
  143. std::string Argument;
  144. };
  145. std::vector<RequestedHelpItem> RequestedHelpItems;
  146. cmDocumentationFormatter* CurrentFormatter;
  147. cmDocumentationFormatterHTML HTMLFormatter;
  148. cmDocumentationFormatterMan ManFormatter;
  149. cmDocumentationFormatterText TextFormatter;
  150. cmDocumentationFormatterUsage UsageFormatter;
  151. std::vector<std::string> PropertySections;
  152. std::vector<std::string> VariableSections;
  153. };
  154. #endif