cmDumpDocumentation.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. "CMake reads ... ", 0},
  37. {0,0,0}
  38. };
  39. //----------------------------------------------------------------------------
  40. static const cmDocumentationEntry cmDocumentationOptions[] =
  41. {
  42. {"--all-for-coverage", "Dump all documentation to stdout. For testing.", 0},
  43. {0,0,0}
  44. };
  45. int DumpHTML(const char* outname)
  46. {
  47. std::ofstream fout(outname);
  48. if(!fout)
  49. {
  50. std::cerr << "failed to open output file: " << outname << "\n";
  51. return -1;
  52. }
  53. cmake cmi;
  54. cmDocumentation doc;
  55. std::vector<cmDocumentationEntry> commands;
  56. cmi.GetCommandDocumentation(commands);
  57. doc.AddSection("Documentation for Commands of CMake " CMake_VERSION_STRING,
  58. &commands[0]);
  59. doc.Print(cmDocumentation::HTMLForm, fout);
  60. return 0;
  61. }
  62. int DumpForCoverage()
  63. {
  64. cmake cmi;
  65. cmDocumentation doc;
  66. std::vector<cmDocumentationEntry> commands;
  67. cmi.GetCommandDocumentation(commands);
  68. doc.SetNameSection(cmDocumentationName);
  69. doc.SetUsageSection(cmDocumentationUsage);
  70. doc.SetDescriptionSection(cmDocumentationDescription);
  71. doc.SetOptionsSection(cmDocumentationOptions);
  72. doc.SetCommandsSection(&commands[0]);
  73. doc.PrintDocumentation(cmDocumentation::Usage, std::cout);
  74. doc.PrintDocumentation(cmDocumentation::Full, std::cout);
  75. doc.PrintDocumentation(cmDocumentation::HTML, std::cout);
  76. doc.PrintDocumentation(cmDocumentation::Man, std::cout);
  77. return 0;
  78. }
  79. int main(int ac, char** av)
  80. {
  81. cmSystemTools::EnableMSVCDebugHook();
  82. const char* outname = "cmake.html";
  83. bool coverage = false;
  84. if(ac > 1)
  85. {
  86. if(strcmp(av[1], "--all-for-coverage") == 0)
  87. {
  88. coverage = true;
  89. }
  90. else
  91. {
  92. outname = av[1];
  93. }
  94. }
  95. if(coverage)
  96. {
  97. return DumpForCoverage();
  98. }
  99. else
  100. {
  101. return DumpHTML(outname);
  102. }
  103. }