Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmDumpDocumentation.cxx
blobd5db8ccb0f1e151f17c1ecd0b53105286dac6c22
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmDumpDocumentation.cxx,v $
5 Language: C++
6 Date: $Date: 2007/12/13 22:56:49 $
7 Version: $Revision: 1.20 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 // Program extracts documentation describing commands from
18 // the CMake system.
19 //
20 #include "cmake.h"
22 #include "cmDocumentation.h"
23 #include "cmVersion.h"
25 //----------------------------------------------------------------------------
26 static const char *cmDocumentationName[][3] =
28 {0,
29 " DumpDocumentation - Dump documentation for CMake.", 0},
30 {0,0,0}
33 //----------------------------------------------------------------------------
34 static const char *cmDocumentationUsage[][3] =
36 {0,
37 " DumpDocumentation [filename]", 0},
38 {0,0,0}
41 //----------------------------------------------------------------------------
42 static const char *cmDocumentationDescription[][3] =
44 {0,
45 "The \"DumpDocumentation\" executable is only available in the build "
46 "tree. It is used for testing, coverage, and documentation.", 0},
47 CMAKE_STANDARD_INTRODUCTION,
48 {0,0,0}
51 //----------------------------------------------------------------------------
52 static const char *cmDocumentationOptions[][3] =
54 {"--all-for-coverage",
55 "Dump all documentation to stdout. For testing.", 0},
56 {0,0,0}
60 int DumpHTML(const char* outname)
62 std::ofstream fout(outname);
63 if(!fout)
65 std::cerr << "failed to open output file: " << outname << "\n";
66 cmSystemTools::ReportLastSystemError("");
67 return -1;
70 cmake cmi;
71 cmDocumentation doc;
72 std::vector<cmDocumentationEntry> commands;
73 cmi.GetCommandDocumentation(commands);
74 cmOStringStream str;
75 str << "Documentation for Commands of CMake "
76 << cmVersion::GetCMakeVersion();
77 doc.SetSection(str.str().c_str(), commands);
78 doc.Print(cmDocumentation::HTMLForm, fout);
80 return 0;
83 int DumpForCoverageToStream(std::ostream& out)
85 cmake cmi;
86 cmDocumentation doc;
87 std::vector<cmDocumentationEntry> commands;
88 std::vector<cmDocumentationEntry> generators;
89 cmi.GetCommandDocumentation(commands);
90 cmi.GetGeneratorDocumentation(generators);
91 doc.SetSection("Name",cmDocumentationName);
92 doc.SetSection("Usage",cmDocumentationUsage);
93 doc.SetSection("Description",cmDocumentationDescription);
94 doc.SetSection("options",cmDocumentationOptions);
95 doc.SetSection("Commands",commands);
96 doc.SetSection("Generators",generators);
97 doc.PrintDocumentation(cmDocumentation::Usage, out);
98 doc.PrintDocumentation(cmDocumentation::Full, out);
99 return 0;
102 int DumpForCoverage(const char* outname)
104 if(outname)
106 std::ofstream fout(outname);
107 if(!fout)
109 std::cerr << "failed to open output file: " << outname << "\n";
110 cmSystemTools::ReportLastSystemError("");
111 return -1;
113 return DumpForCoverageToStream(fout);
115 else
117 return DumpForCoverageToStream(std::cout);
121 int main(int ac, char** av)
123 cmSystemTools::EnableMSVCDebugHook();
124 cmSystemTools::FindExecutableDirectory(av[0]);
125 const char* outname = "cmake.html";
126 bool coverage = false;
127 if(ac > 1)
129 if(strcmp(av[1], "--all-for-coverage") == 0)
131 coverage = true;
132 if(ac > 2)
134 outname = av[2];
136 else
138 outname = 0;
141 else
143 outname = av[1];
147 if(coverage)
149 return DumpForCoverage(outname);
151 else
153 return DumpHTML(outname);