cmDumpDocumentation.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. return -1;
  54. }
  55. cmake cmi;
  56. cmDocumentation doc;
  57. std::vector<cmDocumentationEntry> commands;
  58. cmi.GetCommandDocumentation(commands);
  59. doc.AddSection("Documentation for Commands of CMake " CMake_VERSION_FULL,
  60. &commands[0]);
  61. doc.Print(cmDocumentation::HTMLForm, fout);
  62. return 0;
  63. }
  64. int DumpForCoverageToStream(std::ostream& out)
  65. {
  66. cmake cmi;
  67. cmDocumentation doc;
  68. std::vector<cmDocumentationEntry> commands;
  69. std::vector<cmDocumentationEntry> generators;
  70. cmi.GetCommandDocumentation(commands);
  71. cmi.GetGeneratorDocumentation(generators);
  72. doc.SetNameSection(cmDocumentationName);
  73. doc.SetUsageSection(cmDocumentationUsage);
  74. doc.SetDescriptionSection(cmDocumentationDescription);
  75. doc.SetOptionsSection(cmDocumentationOptions);
  76. doc.SetCommandsSection(&commands[0]);
  77. doc.SetGeneratorsSection(&generators[0]);
  78. doc.PrintDocumentation(cmDocumentation::Usage, out);
  79. doc.PrintDocumentation(cmDocumentation::Full, out);
  80. doc.PrintDocumentation(cmDocumentation::HTML, out);
  81. doc.PrintDocumentation(cmDocumentation::Man, 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. return -1;
  93. }
  94. return DumpForCoverageToStream(fout);
  95. }
  96. else
  97. {
  98. return DumpForCoverageToStream(std::cout);
  99. }
  100. }
  101. int main(int ac, char** av)
  102. {
  103. cmSystemTools::EnableMSVCDebugHook();
  104. const char* outname = "cmake.html";
  105. bool coverage = false;
  106. if(ac > 1)
  107. {
  108. if(strcmp(av[1], "--all-for-coverage") == 0)
  109. {
  110. coverage = true;
  111. if(ac > 2)
  112. {
  113. outname = av[2];
  114. }
  115. else
  116. {
  117. outname = 0;
  118. }
  119. }
  120. else
  121. {
  122. outname = av[1];
  123. }
  124. }
  125. if(coverage)
  126. {
  127. return DumpForCoverage(outname);
  128. }
  129. else
  130. {
  131. return DumpHTML(outname);
  132. }
  133. }