cmDumpDocumentation.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. return 0;
  86. }
  87. int DumpForCoverage(const char* outname)
  88. {
  89. if(outname)
  90. {
  91. std::ofstream fout(outname);
  92. if(!fout)
  93. {
  94. std::cerr << "failed to open output file: " << outname << "\n";
  95. cmSystemTools::ReportLastSystemError("");
  96. return -1;
  97. }
  98. return DumpForCoverageToStream(fout);
  99. }
  100. else
  101. {
  102. return DumpForCoverageToStream(std::cout);
  103. }
  104. }
  105. int main(int ac, char** av)
  106. {
  107. cmSystemTools::EnableMSVCDebugHook();
  108. const char* outname = "cmake.html";
  109. bool coverage = false;
  110. if(ac > 1)
  111. {
  112. if(strcmp(av[1], "--all-for-coverage") == 0)
  113. {
  114. coverage = true;
  115. if(ac > 2)
  116. {
  117. outname = av[2];
  118. }
  119. else
  120. {
  121. outname = 0;
  122. }
  123. }
  124. else
  125. {
  126. outname = av[1];
  127. }
  128. }
  129. if(coverage)
  130. {
  131. return DumpForCoverage(outname);
  132. }
  133. else
  134. {
  135. return DumpHTML(outname);
  136. }
  137. }