cmDumpDocumentation.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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", "Dump all documentation to stdout. For testing.", 0},
  46. {0,0,0}
  47. };
  48. int DumpHTML(const char* outname)
  49. {
  50. std::ofstream fout(outname);
  51. if(!fout)
  52. {
  53. std::cerr << "failed to open output file: " << outname << "\n";
  54. cmSystemTools::ReportLastSystemError("");
  55. return -1;
  56. }
  57. cmake cmi;
  58. cmDocumentation doc;
  59. std::vector<cmDocumentationEntry> commands;
  60. cmi.GetCommandDocumentation(commands);
  61. cmOStringStream str;
  62. str << "Documentation for Commands of CMake "
  63. << cmVersion::GetCMakeVersion();
  64. doc.AddSection(str.str().c_str(), &commands[0]);
  65. doc.Print(cmDocumentation::HTMLForm, fout);
  66. return 0;
  67. }
  68. int DumpForCoverageToStream(std::ostream& out)
  69. {
  70. cmake cmi;
  71. cmDocumentation doc;
  72. std::vector<cmDocumentationEntry> commands;
  73. std::vector<cmDocumentationEntry> generators;
  74. cmi.GetCommandDocumentation(commands);
  75. cmi.GetGeneratorDocumentation(generators);
  76. doc.SetNameSection(cmDocumentationName);
  77. doc.SetUsageSection(cmDocumentationUsage);
  78. doc.SetDescriptionSection(cmDocumentationDescription);
  79. doc.SetOptionsSection(cmDocumentationOptions);
  80. doc.SetCommandsSection(&commands[0]);
  81. doc.SetGeneratorsSection(&generators[0]);
  82. doc.PrintDocumentation(cmDocumentation::Usage, out);
  83. doc.PrintDocumentation(cmDocumentation::Full, out);
  84. doc.PrintDocumentation(cmDocumentation::HTML, out);
  85. doc.PrintDocumentation(cmDocumentation::Man, out);
  86. return 0;
  87. }
  88. int DumpForCoverage(const char* outname)
  89. {
  90. if(outname)
  91. {
  92. std::ofstream fout(outname);
  93. if(!fout)
  94. {
  95. std::cerr << "failed to open output file: " << outname << "\n";
  96. cmSystemTools::ReportLastSystemError("");
  97. return -1;
  98. }
  99. return DumpForCoverageToStream(fout);
  100. }
  101. else
  102. {
  103. return DumpForCoverageToStream(std::cout);
  104. }
  105. }
  106. int main(int ac, char** av)
  107. {
  108. cmSystemTools::EnableMSVCDebugHook();
  109. const char* outname = "cmake.html";
  110. bool coverage = false;
  111. if(ac > 1)
  112. {
  113. if(strcmp(av[1], "--all-for-coverage") == 0)
  114. {
  115. coverage = true;
  116. if(ac > 2)
  117. {
  118. outname = av[2];
  119. }
  120. else
  121. {
  122. outname = 0;
  123. }
  124. }
  125. else
  126. {
  127. outname = av[1];
  128. }
  129. }
  130. if(coverage)
  131. {
  132. return DumpForCoverage(outname);
  133. }
  134. else
  135. {
  136. return DumpHTML(outname);
  137. }
  138. }