cmDumpDocumentation.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // Program extracts documentation describing commands from
  14. // the CMake system.
  15. //
  16. #include "cmake.h"
  17. #include "cmDocumentation.h"
  18. //----------------------------------------------------------------------------
  19. static const cmDocumentationEntry cmDocumentationName[] =
  20. {
  21. {0,
  22. " DumpDocumentation - Dump documentation for CMake.", 0},
  23. {0,0,0}
  24. };
  25. //----------------------------------------------------------------------------
  26. static const cmDocumentationEntry cmDocumentationUsage[] =
  27. {
  28. {0,
  29. " DumpDocumentation [filename]", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const cmDocumentationEntry cmDocumentationDescription[] =
  34. {
  35. {0,
  36. "The \"DumpDocumentation\" executable is only available in the build "
  37. "tree. It is used for testing, coverage, and documentation.", 0},
  38. CMAKE_STANDARD_INTRODUCTION,
  39. {0,0,0}
  40. };
  41. //----------------------------------------------------------------------------
  42. static const cmDocumentationEntry cmDocumentationOptions[] =
  43. {
  44. {"--all-for-coverage", "Dump all documentation to stdout. For testing.", 0},
  45. {0,0,0}
  46. };
  47. int DumpHTML(const char* outname)
  48. {
  49. std::ofstream fout(outname);
  50. if(!fout)
  51. {
  52. std::cerr << "failed to open output file: " << outname << "\n";
  53. cmSystemTools::ReportLastSystemError("");
  54. return -1;
  55. }
  56. cmake cmi;
  57. cmDocumentation doc;
  58. std::vector<cmDocumentationEntry> commands;
  59. cmi.GetCommandDocumentation(commands);
  60. doc.AddSection("Documentation for Commands of CMake " CMake_VERSION_FULL,
  61. &commands[0]);
  62. doc.Print(cmDocumentation::HTMLForm, fout);
  63. return 0;
  64. }
  65. int DumpForCoverageToStream(std::ostream& out)
  66. {
  67. cmake cmi;
  68. cmDocumentation doc;
  69. std::vector<cmDocumentationEntry> commands;
  70. std::vector<cmDocumentationEntry> generators;
  71. cmi.GetCommandDocumentation(commands);
  72. cmi.GetGeneratorDocumentation(generators);
  73. doc.SetNameSection(cmDocumentationName);
  74. doc.SetUsageSection(cmDocumentationUsage);
  75. doc.SetDescriptionSection(cmDocumentationDescription);
  76. doc.SetOptionsSection(cmDocumentationOptions);
  77. doc.SetCommandsSection(&commands[0]);
  78. doc.SetGeneratorsSection(&generators[0]);
  79. doc.PrintDocumentation(cmDocumentation::Usage, out);
  80. doc.PrintDocumentation(cmDocumentation::Full, out);
  81. doc.PrintDocumentation(cmDocumentation::HTML, out);
  82. doc.PrintDocumentation(cmDocumentation::Man, out);
  83. return 0;
  84. }
  85. int DumpForCoverage(const char* outname)
  86. {
  87. if(outname)
  88. {
  89. std::ofstream fout(outname);
  90. if(!fout)
  91. {
  92. std::cerr << "failed to open output file: " << outname << "\n";
  93. cmSystemTools::ReportLastSystemError("");
  94. return -1;
  95. }
  96. return DumpForCoverageToStream(fout);
  97. }
  98. else
  99. {
  100. return DumpForCoverageToStream(std::cout);
  101. }
  102. }
  103. int main(int ac, char** av)
  104. {
  105. cmSystemTools::EnableMSVCDebugHook();
  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. }