cmDumpDocumentation.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // Program extracts documentation describing commands from
  11. // the CMake system.
  12. //
  13. #include "cmake.h"
  14. #include "cmDocumentation.h"
  15. #include "cmVersion.h"
  16. //----------------------------------------------------------------------------
  17. static const char *cmDocumentationName[][3] =
  18. {
  19. {0,
  20. " DumpDocumentation - Dump documentation for CMake.", 0},
  21. {0,0,0}
  22. };
  23. //----------------------------------------------------------------------------
  24. static const char *cmDocumentationUsage[][3] =
  25. {
  26. {0,
  27. " DumpDocumentation [filename]", 0},
  28. {0,0,0}
  29. };
  30. //----------------------------------------------------------------------------
  31. static const char *cmDocumentationDescription[][3] =
  32. {
  33. {0,
  34. "The \"DumpDocumentation\" executable is only available in the build "
  35. "tree. It is used for testing, coverage, and documentation.", 0},
  36. CMAKE_STANDARD_INTRODUCTION,
  37. {0,0,0}
  38. };
  39. //----------------------------------------------------------------------------
  40. static const char *cmDocumentationOptions[][3] =
  41. {
  42. {"--all-for-coverage",
  43. "Dump all documentation to stdout. For testing.", 0},
  44. {0,0,0}
  45. };
  46. int DumpHTML(const char* outname)
  47. {
  48. std::ofstream fout(outname);
  49. if(!fout)
  50. {
  51. std::cerr << "failed to open output file: " << outname << "\n";
  52. cmSystemTools::ReportLastSystemError("");
  53. return -1;
  54. }
  55. cmake cmi;
  56. cmDocumentation doc;
  57. std::vector<cmDocumentationEntry> commands;
  58. cmi.GetCommandDocumentation(commands);
  59. cmOStringStream str;
  60. str << "Documentation for Commands of CMake "
  61. << cmVersion::GetCMakeVersion();
  62. doc.SetSection(str.str().c_str(), commands);
  63. doc.Print(cmDocumentation::HTMLForm, fout);
  64. return 0;
  65. }
  66. int DumpForCoverageToStream(std::ostream& out)
  67. {
  68. cmake cmi;
  69. cmDocumentation doc;
  70. std::vector<cmDocumentationEntry> commands;
  71. std::vector<cmDocumentationEntry> generators;
  72. cmi.GetCommandDocumentation(commands);
  73. cmi.GetGeneratorDocumentation(generators);
  74. doc.SetSection("Name",cmDocumentationName);
  75. doc.SetSection("Usage",cmDocumentationUsage);
  76. doc.SetSection("Description",cmDocumentationDescription);
  77. doc.SetSection("options",cmDocumentationOptions);
  78. doc.SetSection("Commands",commands);
  79. doc.SetSection("Generators",generators);
  80. doc.PrintDocumentation(cmDocumentation::Usage, out);
  81. doc.PrintDocumentation(cmDocumentation::Full, out);
  82. return 0;
  83. }
  84. int DumpForCoverage(const char* outname)
  85. {
  86. if(outname)
  87. {
  88. std::ofstream fout(outname);
  89. if(!fout)
  90. {
  91. std::cerr << "failed to open output file: " << outname << "\n";
  92. cmSystemTools::ReportLastSystemError("");
  93. return -1;
  94. }
  95. return DumpForCoverageToStream(fout);
  96. }
  97. else
  98. {
  99. return DumpForCoverageToStream(std::cout);
  100. }
  101. }
  102. int main(int ac, char** av)
  103. {
  104. cmSystemTools::EnableMSVCDebugHook();
  105. cmSystemTools::FindExecutableDirectory(av[0]);
  106. const char* outname = "cmake.html";
  107. bool coverage = false;
  108. if(ac > 1)
  109. {
  110. if(strcmp(av[1], "--all-for-coverage") == 0)
  111. {
  112. coverage = true;
  113. if(ac > 2)
  114. {
  115. outname = av[2];
  116. }
  117. else
  118. {
  119. outname = 0;
  120. }
  121. }
  122. else
  123. {
  124. outname = av[1];
  125. }
  126. }
  127. if(coverage)
  128. {
  129. return DumpForCoverage(outname);
  130. }
  131. else
  132. {
  133. return DumpHTML(outname);
  134. }
  135. }