cmDocumentation.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /**
  63. * Print documentation in the given form. All previously added
  64. * sections will be generated.
  65. */
  66. void Print(Form f, std::ostream& os);
  67. /**
  68. * Print documentation in the current form. All previously added
  69. * sections will be generated.
  70. */
  71. void Print(std::ostream& os);
  72. /**
  73. * Add a section of documentation. This can be used to generate custom help
  74. * documents.
  75. */
  76. void AddSectionToPrint(const char *section);
  77. void SetSeeAlsoList(const char *data[][3]);
  78. /** Clear all previously added sections of help. */
  79. void ClearSections();
  80. /** Set cmake root so we can find installed files */
  81. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  82. /** Set CMAKE_MODULE_PATH so we can find additional cmake modules */
  83. void SetCMakeModulePath(const char* path) { this->CMakeModulePath = path;}
  84. static Form GetFormFromFilename(const std::string& filename);
  85. private:
  86. void SetForm(Form f);
  87. bool CreateSingleModule(const char* fname,
  88. const char* moduleName,
  89. cmDocumentationSection &sec);
  90. void CreateModuleDocsForDir(cmsys::Directory& dir,
  91. cmDocumentationSection &moduleSection);
  92. bool CreateModulesSection();
  93. bool CreateCustomModulesSection();
  94. void CreateFullDocumentation();
  95. bool PrintCopyright(std::ostream& os);
  96. bool PrintVersion(std::ostream& os);
  97. bool PrintDocumentationGeneric(std::ostream& os, const char *section);
  98. bool PrintDocumentationList(std::ostream& os, const char *section);
  99. bool PrintDocumentationSingle(std::ostream& os);
  100. bool PrintDocumentationSingleModule(std::ostream& os);
  101. bool PrintDocumentationSingleProperty(std::ostream& os);
  102. bool PrintDocumentationUsage(std::ostream& os);
  103. bool PrintDocumentationFull(std::ostream& os);
  104. bool PrintDocumentationModules(std::ostream& os);
  105. bool PrintDocumentationCustomModules(std::ostream& os);
  106. bool PrintDocumentationProperties(std::ostream& os);
  107. bool PrintDocumentationCurrentCommands(std::ostream& os);
  108. bool PrintDocumentationCompatCommands(std::ostream& os);
  109. void PrintDocumentationCommand(std::ostream& os,
  110. const cmDocumentationEntry &entry);
  111. const char* GetNameString() const;
  112. bool IsOption(const char* arg) const;
  113. std::string NameString;
  114. std::map<std::string,cmDocumentationSection*> AllSections;
  115. std::string SeeAlsoString;
  116. std::string CMakeRoot;
  117. std::string CMakeModulePath;
  118. std::set<std::string> ModulesFound;
  119. std::vector< char* > ModuleStrings;
  120. std::vector<const cmDocumentationSection *> PrintSections;
  121. std::string CurrentArgument;
  122. struct RequestedHelpItem
  123. {
  124. RequestedHelpItem():HelpForm(TextForm), HelpType(None) {}
  125. cmDocumentationEnums::Form HelpForm;
  126. cmDocumentationEnums::Type HelpType;
  127. std::string Filename;
  128. std::string Argument;
  129. };
  130. std::vector<RequestedHelpItem> RequestedHelpItems;
  131. cmDocumentationFormatter* CurrentFormatter;
  132. cmDocumentationFormatterHTML HTMLFormatter;
  133. cmDocumentationFormatterMan ManFormatter;
  134. cmDocumentationFormatterText TextFormatter;
  135. cmDocumentationFormatterUsage UsageFormatter;
  136. };
  137. #endif