cmDumpDocumentation.cxx 4.0 KB

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