cmDocumentation.cxx 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  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. #include "cmDocumentation.h"
  14. #include "cmSystemTools.h"
  15. #include "cmVersion.h"
  16. #include <cmsys/Directory.hxx>
  17. //----------------------------------------------------------------------------
  18. static const char *cmDocumentationStandardOptions[][3] =
  19. {
  20. {"--copyright [file]", "Print the CMake copyright and exit.",
  21. "If a file is specified, the copyright is written into it."},
  22. {"--help", "Print usage information and exit.",
  23. "Usage describes the basic command line interface and its options."},
  24. {"--help-full [file]", "Print full help and exit.",
  25. "Full help displays most of the documentation provided by the UNIX "
  26. "man page. It is provided for use on non-UNIX platforms, but is "
  27. "also convenient if the man page is not installed. If a file is "
  28. "specified, the help is written into it."},
  29. {"--help-html [file]", "Print full help in HTML format.",
  30. "This option is used by CMake authors to help produce web pages. "
  31. "If a file is specified, the help is written into it."},
  32. {"--help-man [file]", "Print full help as a UNIX man page and exit.",
  33. "This option is used by the cmake build to generate the UNIX man page. "
  34. "If a file is specified, the help is written into it."},
  35. {"--version [file]", "Show program name/version banner and exit.",
  36. "If a file is specified, the version is written into it."},
  37. {0,0,0}
  38. };
  39. //----------------------------------------------------------------------------
  40. static const char *cmModulesDocumentationDescription[][3] =
  41. {
  42. {0,
  43. " CMake Modules - Modules coming with CMake, the Cross-Platform Makefile "
  44. "Generator.", 0},
  45. // CMAKE_DOCUMENTATION_OVERVIEW,
  46. {0,
  47. "This is the documentation for the modules and scripts coming with CMake. "
  48. "Using these modules you can check the computer system for "
  49. "installed software packages, features of the compiler and the "
  50. "existance of headers to name just a few.", 0},
  51. {0,0,0}
  52. };
  53. //----------------------------------------------------------------------------
  54. static const char *cmCustomModulesDocumentationDescription[][3] =
  55. {
  56. {0,
  57. " Custom CMake Modules - Additional Modules for CMake.", 0},
  58. // CMAKE_DOCUMENTATION_OVERVIEW,
  59. {0,
  60. "This is the documentation for additional modules and scripts for CMake. "
  61. "Using these modules you can check the computer system for "
  62. "installed software packages, features of the compiler and the "
  63. "existance of headers to name just a few.", 0},
  64. {0,0,0}
  65. };
  66. //----------------------------------------------------------------------------
  67. static const char *cmPropertiesDocumentationDescription[][3] =
  68. {
  69. {0,
  70. " CMake Properties - Properties supported by CMake, "
  71. "the Cross-Platform Makefile Generator.", 0},
  72. // CMAKE_DOCUMENTATION_OVERVIEW,
  73. {0,
  74. "This is the documentation for the properties supported by CMake. "
  75. "Properties can have different scopes. They can either be assigned to a "
  76. "source file, a directory, a target or globally to CMake. By modifying the "
  77. "values of properties the behaviour of the buildsystem can be customized.",
  78. 0},
  79. {0,0,0}
  80. };
  81. //----------------------------------------------------------------------------
  82. static const char *cmCompatCommandsDocumentationDescription[][3] =
  83. {
  84. {0,
  85. " CMake Compatibility Listfile Commands - "
  86. "Obsolete commands supported by CMake for compatibility.", 0},
  87. // CMAKE_DOCUMENTATION_OVERVIEW,
  88. {0,
  89. "This is the documentation for now obsolete listfile commands from previous "
  90. "CMake versions, which are still supported for compatibility reasons. You "
  91. "should instead use the newer, faster and shinier new commands. ;-)", 0},
  92. {0,0,0}
  93. };
  94. //----------------------------------------------------------------------------
  95. static const char *cmDocumentationModulesHeader[][3] =
  96. {
  97. {0,
  98. "The following modules are provided with CMake. "
  99. "They can be used with INCLUDE(ModuleName).", 0},
  100. {0,0,0}
  101. };
  102. //----------------------------------------------------------------------------
  103. static const char *cmDocumentationCustomModulesHeader[][3] =
  104. {
  105. {0,
  106. "The following modules are also available for CMake. "
  107. "They can be used with INCLUDE(ModuleName).", 0},
  108. {0,0,0}
  109. };
  110. //----------------------------------------------------------------------------
  111. static const char *cmDocumentationGeneratorsHeader[][3] =
  112. {
  113. {0,
  114. "The following generators are available on this platform:", 0},
  115. {0,0,0}
  116. };
  117. //----------------------------------------------------------------------------
  118. static const char *cmDocumentationStandardSeeAlso[][3] =
  119. {
  120. {0,
  121. "The following resources are available to get help using CMake:", 0},
  122. {"Home Page",
  123. "http://www.cmake.org",
  124. "The primary starting point for learning about CMake."},
  125. {"Frequently Asked Questions",
  126. "http://www.cmake.org/Wiki/CMake_FAQ",
  127. "A Wiki is provided containing answers to frequently asked questions. "},
  128. {"Online Documentation",
  129. "http://www.cmake.org/HTML/Documentation.html",
  130. "Links to available documentation may be found on this web page."},
  131. {"Mailing List",
  132. "http://www.cmake.org/HTML/MailingLists.html",
  133. "For help and discussion about using cmake, a mailing list is provided at "
  134. "[email protected]. "
  135. "The list is member-post-only but one may sign up on the CMake web page. "
  136. "Please first read the full documentation at "
  137. "http://www.cmake.org before posting questions to the list."},
  138. {0,
  139. "Summary of helpful links:\n"
  140. " Home: http://www.cmake.org\n"
  141. " Docs: http://www.cmake.org/HTML/Documentation.html\n"
  142. " Mail: http://www.cmake.org/HTML/MailingLists.html\n"
  143. " FAQ: http://www.cmake.org/Wiki/CMake_FAQ\n"
  144. , 0},
  145. {0,0,0}
  146. };
  147. //----------------------------------------------------------------------------
  148. static const char *cmDocumentationCopyright[][3] =
  149. {
  150. {0,
  151. "Copyright (c) 2002 Kitware, Inc., Insight Consortium. "
  152. "All rights reserved.", 0},
  153. {0,
  154. "Redistribution and use in source and binary forms, with or without "
  155. "modification, are permitted provided that the following conditions are "
  156. "met:", 0},
  157. {"",
  158. "Redistributions of source code must retain the above copyright notice, "
  159. "this list of conditions and the following disclaimer.", 0},
  160. {"",
  161. "Redistributions in binary form must reproduce the above copyright "
  162. "notice, this list of conditions and the following disclaimer in the "
  163. "documentation and/or other materials provided with the distribution.",
  164. 0},
  165. {"",
  166. "The names of Kitware, Inc., the Insight Consortium, or the names of "
  167. "any consortium members, or of any contributors, may not be used to "
  168. "endorse or promote products derived from this software without "
  169. "specific prior written permission.", 0},
  170. {"",
  171. "Modified source versions must be plainly marked as such, and must "
  172. "not be misrepresented as being the original software.", 0},
  173. {0,
  174. "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "
  175. "``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "
  176. "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR "
  177. "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR "
  178. "CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, "
  179. "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, "
  180. "PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR "
  181. "PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF "
  182. "LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING "
  183. "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS "
  184. "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", 0},
  185. {0, 0, 0}
  186. };
  187. //----------------------------------------------------------------------------
  188. cmDocumentation::cmDocumentation()
  189. :CurrentFormatter(0)
  190. {
  191. this->SetForm(TextForm);
  192. cmDocumentationSection *sec;
  193. sec = new cmDocumentationSection("Author","AUTHOR");
  194. sec->Append(cmDocumentationEntry
  195. (0,
  196. "This manual page was generated by the \"--help-man\" option.",
  197. 0));
  198. this->AllSections["Author"] = sec;
  199. sec = new cmDocumentationSection("Copyright","COPYRIGHT");
  200. sec->Append(cmDocumentationCopyright);
  201. this->AllSections["Copyright"] = sec;
  202. sec = new cmDocumentationSection("See Also","SEE ALSO");
  203. sec->Append(cmDocumentationStandardSeeAlso);
  204. this->AllSections["Standard See Also"] = sec;
  205. sec = new cmDocumentationSection("Options","OPTIONS");
  206. sec->Append(cmDocumentationStandardOptions);
  207. this->AllSections["Options"] = sec;
  208. sec = new cmDocumentationSection("Properties","PROPERTIES");
  209. sec->Append(cmPropertiesDocumentationDescription);
  210. this->AllSections["Properties Description"] = sec;
  211. sec = new cmDocumentationSection("Generators","GENERATORS");
  212. sec->Append(cmDocumentationGeneratorsHeader);
  213. this->AllSections["Generators"] = sec;
  214. sec = new cmDocumentationSection("Compatibility Commands",
  215. "COMPATIBILITY COMMANDS");
  216. sec->Append(cmCompatCommandsDocumentationDescription);
  217. this->AllSections["Compatibility Commands"] = sec;
  218. this->PropertySections.push_back("Properties of Global Scope");
  219. this->PropertySections.push_back("Properties on Directories");
  220. this->PropertySections.push_back("Properties on Targets");
  221. this->PropertySections.push_back("Properties on Tests");
  222. this->PropertySections.push_back("Properties on Source Files");
  223. this->VariableSections.push_back("Variables that Provide Information");
  224. this->VariableSections.push_back("Variables That Change Behavior");
  225. this->VariableSections.push_back("Variables That Describe the System");
  226. this->VariableSections.push_back("Variables that Control the Build");
  227. this->VariableSections.push_back("Variables for Languages");
  228. }
  229. //----------------------------------------------------------------------------
  230. cmDocumentation::~cmDocumentation()
  231. {
  232. for(std::vector< char* >::iterator i = this->ModuleStrings.begin();
  233. i != this->ModuleStrings.end(); ++i)
  234. {
  235. delete [] *i;
  236. }
  237. for(std::map<std::string,cmDocumentationSection *>::iterator i =
  238. this->AllSections.begin();
  239. i != this->AllSections.end(); ++i)
  240. {
  241. delete i->second;
  242. }
  243. }
  244. //----------------------------------------------------------------------------
  245. bool cmDocumentation::PrintCopyright(std::ostream& os)
  246. {
  247. cmDocumentationSection *sec = this->AllSections["Copyright"];
  248. const std::vector<cmDocumentationEntry> &entries = sec->GetEntries();
  249. for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
  250. op != entries.end(); ++op)
  251. {
  252. if(op->Name.size())
  253. {
  254. os << " * ";
  255. this->TextFormatter.SetIndent(" ");
  256. this->TextFormatter.PrintColumn(os, op->Brief.c_str());
  257. }
  258. else
  259. {
  260. this->TextFormatter.SetIndent("");
  261. this->TextFormatter.PrintColumn(os, op->Brief.c_str());
  262. }
  263. os << "\n";
  264. }
  265. return true;
  266. }
  267. //----------------------------------------------------------------------------
  268. bool cmDocumentation::PrintVersion(std::ostream& os)
  269. {
  270. os << this->GetNameString() << " version "
  271. << cmVersion::GetCMakeVersion() << "\n";
  272. return true;
  273. }
  274. //----------------------------------------------------------------------------
  275. void cmDocumentation::AddSectionToPrint(const char *section)
  276. {
  277. if (this->AllSections.find(section) != this->AllSections.end())
  278. {
  279. this->PrintSections.push_back(this->AllSections[section]);
  280. }
  281. }
  282. //----------------------------------------------------------------------------
  283. void cmDocumentation::ClearSections()
  284. {
  285. this->PrintSections.erase(this->PrintSections.begin(),
  286. this->PrintSections.end());
  287. this->ModulesFound.clear();
  288. }
  289. //----------------------------------------------------------------------------
  290. bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
  291. {
  292. if ((this->CurrentFormatter->GetForm() != HTMLForm)
  293. && (this->CurrentFormatter->GetForm() != ManForm))
  294. {
  295. this->PrintVersion(os);
  296. }
  297. switch (ht)
  298. {
  299. case cmDocumentation::Usage:
  300. return this->PrintDocumentationUsage(os);
  301. case cmDocumentation::Single:
  302. return this->PrintDocumentationSingle(os);
  303. case cmDocumentation::SingleModule:
  304. return this->PrintDocumentationSingleModule(os);
  305. case cmDocumentation::SingleProperty:
  306. return this->PrintDocumentationSingleProperty(os);
  307. case cmDocumentation::SingleVariable:
  308. return this->PrintDocumentationSingleVariable(os);
  309. case cmDocumentation::List:
  310. this->PrintDocumentationList(os,"Commands");
  311. this->PrintDocumentationList(os,"Compatibility Commands");
  312. return true;
  313. case cmDocumentation::ModuleList:
  314. this->PrintDocumentationList(os,"Modules");
  315. return true;
  316. case cmDocumentation::PropertyList:
  317. this->PrintDocumentationList(os,"Properties Description");
  318. for (std::vector<std::string>::iterator i =
  319. this->PropertySections.begin();
  320. i != this->PropertySections.end(); ++i)
  321. {
  322. this->PrintDocumentationList(os,i->c_str());
  323. }
  324. return true;
  325. case cmDocumentation::VariableList:
  326. for (std::vector<std::string>::iterator i =
  327. this->VariableSections.begin();
  328. i != this->VariableSections.end(); ++i)
  329. {
  330. this->PrintDocumentationList(os,i->c_str());
  331. }
  332. return true;
  333. case cmDocumentation::Full:
  334. return this->PrintDocumentationFull(os);
  335. case cmDocumentation::Modules:
  336. return this->PrintDocumentationModules(os);
  337. case cmDocumentation::CustomModules:
  338. return this->PrintDocumentationCustomModules(os);
  339. case cmDocumentation::Properties:
  340. return this->PrintDocumentationProperties(os);
  341. case cmDocumentation::Variables:
  342. return this->PrintDocumentationVariables(os);
  343. case cmDocumentation::Commands:
  344. return this->PrintDocumentationCurrentCommands(os);
  345. case cmDocumentation::CompatCommands:
  346. return this->PrintDocumentationCompatCommands(os);
  347. case cmDocumentation::Copyright:
  348. return this->PrintCopyright(os);
  349. case cmDocumentation::Version:
  350. return true;
  351. default: return false;
  352. }
  353. }
  354. //----------------------------------------------------------------------------
  355. bool cmDocumentation::CreateModulesSection()
  356. {
  357. cmDocumentationSection *sec =
  358. new cmDocumentationSection("Standard CMake Modules", "MODULES");
  359. this->AllSections["Modules"] = sec;
  360. std::string cmakeModules = this->CMakeRoot;
  361. cmakeModules += "/Modules";
  362. cmsys::Directory dir;
  363. dir.Load(cmakeModules.c_str());
  364. if (dir.GetNumberOfFiles() > 0)
  365. {
  366. sec->Append(cmDocumentationModulesHeader[0]);
  367. sec->Append(cmModulesDocumentationDescription);
  368. this->CreateModuleDocsForDir(dir, *this->AllSections["Modules"]);
  369. }
  370. return true;
  371. }
  372. //----------------------------------------------------------------------------
  373. bool cmDocumentation::CreateCustomModulesSection()
  374. {
  375. bool sectionHasHeader = false;
  376. std::vector<std::string> dirs;
  377. cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
  378. for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
  379. dirIt != dirs.end();
  380. ++dirIt)
  381. {
  382. cmsys::Directory dir;
  383. dir.Load(dirIt->c_str());
  384. if (dir.GetNumberOfFiles() > 0)
  385. {
  386. if (!sectionHasHeader)
  387. {
  388. cmDocumentationSection *sec =
  389. new cmDocumentationSection("Custom CMake Modules","CUSTOM MODULES");
  390. this->AllSections["Custom CMake Modules"] = sec;
  391. sec->Append(cmDocumentationCustomModulesHeader[0]);
  392. sec->Append(cmCustomModulesDocumentationDescription);
  393. sectionHasHeader = true;
  394. }
  395. this->CreateModuleDocsForDir
  396. (dir, *this->AllSections["Custom CMake Modules"]);
  397. }
  398. }
  399. return true;
  400. }
  401. //----------------------------------------------------------------------------
  402. void cmDocumentation
  403. ::CreateModuleDocsForDir(cmsys::Directory& dir,
  404. cmDocumentationSection &moduleSection)
  405. {
  406. // sort the files alphabetically, so the docs for one module are easier
  407. // to find than if they are in random order
  408. std::vector<std::string> sortedFiles;
  409. for(unsigned int i = 0; i < dir.GetNumberOfFiles(); ++i)
  410. {
  411. sortedFiles.push_back(dir.GetFile(i));
  412. }
  413. std::sort(sortedFiles.begin(), sortedFiles.end());
  414. for(std::vector<std::string>::const_iterator fname = sortedFiles.begin();
  415. fname!=sortedFiles.end(); ++fname)
  416. {
  417. if(fname->length() > 6)
  418. {
  419. if(fname->substr(fname->length()-6, 6) == ".cmake")
  420. {
  421. std::string moduleName = fname->substr(0, fname->length()-6);
  422. // this check is to avoid creating documentation for the modules with
  423. // the same name in multiple directories of CMAKE_MODULE_PATH
  424. if (this->ModulesFound.find(moduleName) == this->ModulesFound.end())
  425. {
  426. this->ModulesFound.insert(moduleName);
  427. std::string path = dir.GetPath();
  428. path += "/";
  429. path += (*fname);
  430. this->CreateSingleModule(path.c_str(), moduleName.c_str(),
  431. moduleSection);
  432. }
  433. }
  434. }
  435. }
  436. }
  437. //----------------------------------------------------------------------------
  438. bool cmDocumentation::CreateSingleModule(const char* fname,
  439. const char* moduleName,
  440. cmDocumentationSection &moduleSection)
  441. {
  442. std::ifstream fin(fname);
  443. if(!fin)
  444. {
  445. std::cerr << "Internal error: can not open module." << fname << std::endl;
  446. return false;
  447. }
  448. std::string line;
  449. std::string text;
  450. std::string brief;
  451. brief = " ";
  452. bool newParagraph = true;
  453. while ( fin && cmSystemTools::GetLineFromStream(fin, line) )
  454. {
  455. if(line.size() && line[0] == '#')
  456. {
  457. // blank line
  458. if(line.size() <= 2)
  459. {
  460. text += "\n";
  461. newParagraph = true;
  462. }
  463. else if(line[2] == '-')
  464. {
  465. brief = line.c_str()+4;
  466. }
  467. else
  468. {
  469. // two spaces
  470. if(line[1] == ' ' && line[2] == ' ')
  471. {
  472. if(!newParagraph)
  473. {
  474. text += "\n";
  475. newParagraph = true;
  476. }
  477. // Skip #, and leave space for preformatted
  478. text += line.c_str()+1;
  479. text += "\n";
  480. }
  481. else if(line[1] == ' ')
  482. {
  483. if(!newParagraph)
  484. {
  485. text += " ";
  486. }
  487. newParagraph = false;
  488. // skip # and space
  489. text += line.c_str()+2;
  490. }
  491. else
  492. {
  493. if(!newParagraph)
  494. {
  495. text += " ";
  496. }
  497. newParagraph = false;
  498. // skip #
  499. text += line.c_str()+1;
  500. }
  501. }
  502. }
  503. else
  504. {
  505. if(text.length() < 2 && brief.length() == 1)
  506. {
  507. return false;
  508. }
  509. char* pname = strcpy(new char[strlen(moduleName)+1], moduleName);
  510. char* ptext = strcpy(new char[text.length()+1], text.c_str());
  511. this->ModuleStrings.push_back(pname);
  512. this->ModuleStrings.push_back(ptext);
  513. char* pbrief = strcpy(new char[brief.length()+1], brief.c_str());
  514. this->ModuleStrings.push_back(pbrief);
  515. moduleSection.Append(pname, pbrief, ptext);
  516. return true;
  517. }
  518. }
  519. return true;
  520. }
  521. //----------------------------------------------------------------------------
  522. bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
  523. {
  524. bool result = true;
  525. // Loop over requested documentation types.
  526. for(std::vector<RequestedHelpItem>::const_iterator
  527. i = this->RequestedHelpItems.begin();
  528. i != this->RequestedHelpItems.end();
  529. ++i)
  530. {
  531. this->SetForm(i->HelpForm);
  532. this->CurrentArgument = i->Argument;
  533. // If a file name was given, use it. Otherwise, default to the
  534. // given stream.
  535. std::ofstream* fout = 0;
  536. std::ostream* s = &os;
  537. if(i->Filename.length() > 0)
  538. {
  539. fout = new std::ofstream(i->Filename.c_str(), std::ios::out);
  540. if(fout)
  541. {
  542. s = fout;
  543. }
  544. else
  545. {
  546. result = false;
  547. }
  548. }
  549. // Print this documentation type to the stream.
  550. if(!this->PrintDocumentation(i->HelpType, *s) || !*s)
  551. {
  552. result = false;
  553. }
  554. // Close the file if we wrote one.
  555. if(fout)
  556. {
  557. delete fout;
  558. }
  559. }
  560. return result;
  561. }
  562. #define GET_OPT_ARGUMENT(target) \
  563. if((i+1 < argc) && !this->IsOption(argv[i+1])) \
  564. { \
  565. target = argv[i+1]; \
  566. i = i+1; \
  567. };
  568. cmDocumentation::Form cmDocumentation::GetFormFromFilename(
  569. const std::string& filename)
  570. {
  571. std::string ext = cmSystemTools::GetFilenameExtension(filename);
  572. ext = cmSystemTools::UpperCase(ext);
  573. if ((ext == ".HTM") || (ext == ".HTML"))
  574. {
  575. return cmDocumentation::HTMLForm;
  576. }
  577. // ".1" to ".9" should be manpages
  578. if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
  579. {
  580. return cmDocumentation::ManForm;
  581. }
  582. return cmDocumentation::TextForm;
  583. }
  584. //----------------------------------------------------------------------------
  585. bool cmDocumentation::CheckOptions(int argc, const char* const* argv)
  586. {
  587. // Providing zero arguments gives usage information.
  588. if(argc == 1)
  589. {
  590. RequestedHelpItem help;
  591. help.HelpType = cmDocumentation::Usage;
  592. help.HelpForm = cmDocumentation::UsageForm;
  593. this->RequestedHelpItems.push_back(help);
  594. return true;
  595. }
  596. // Search for supported help options.
  597. bool result = false;
  598. for(int i=1; i < argc; ++i)
  599. {
  600. RequestedHelpItem help;
  601. // Check if this is a supported help option.
  602. if((strcmp(argv[i], "-help") == 0) ||
  603. (strcmp(argv[i], "--help") == 0) ||
  604. (strcmp(argv[i], "/?") == 0) ||
  605. (strcmp(argv[i], "-usage") == 0) ||
  606. (strcmp(argv[i], "-h") == 0) ||
  607. (strcmp(argv[i], "-H") == 0))
  608. {
  609. help.HelpType = cmDocumentation::Usage;
  610. help.HelpForm = cmDocumentation::UsageForm;
  611. GET_OPT_ARGUMENT(help.Argument);
  612. help.Argument = cmSystemTools::LowerCase(help.Argument);
  613. // special case for single command
  614. if (!help.Argument.empty())
  615. {
  616. help.HelpType = cmDocumentation::Single;
  617. }
  618. }
  619. else if(strcmp(argv[i], "--help-properties") == 0)
  620. {
  621. help.HelpType = cmDocumentation::Properties;
  622. GET_OPT_ARGUMENT(help.Filename);
  623. help.HelpForm = this->GetFormFromFilename(help.Filename);
  624. }
  625. else if(strcmp(argv[i], "--help-variables") == 0)
  626. {
  627. help.HelpType = cmDocumentation::Variables;
  628. GET_OPT_ARGUMENT(help.Filename);
  629. help.HelpForm = this->GetFormFromFilename(help.Filename);
  630. }
  631. else if(strcmp(argv[i], "--help-modules") == 0)
  632. {
  633. help.HelpType = cmDocumentation::Modules;
  634. GET_OPT_ARGUMENT(help.Filename);
  635. help.HelpForm = this->GetFormFromFilename(help.Filename);
  636. }
  637. else if(strcmp(argv[i], "--help-custom-modules") == 0)
  638. {
  639. help.HelpType = cmDocumentation::CustomModules;
  640. GET_OPT_ARGUMENT(help.Filename);
  641. help.HelpForm = this->GetFormFromFilename(help.Filename);
  642. }
  643. else if(strcmp(argv[i], "--help-commands") == 0)
  644. {
  645. help.HelpType = cmDocumentation::Commands;
  646. GET_OPT_ARGUMENT(help.Filename);
  647. help.HelpForm = this->GetFormFromFilename(help.Filename);
  648. }
  649. else if(strcmp(argv[i], "--help-compatcommands") == 0)
  650. {
  651. help.HelpType = cmDocumentation::CompatCommands;
  652. GET_OPT_ARGUMENT(help.Filename);
  653. help.HelpForm = this->GetFormFromFilename(help.Filename);
  654. }
  655. else if(strcmp(argv[i], "--help-full") == 0)
  656. {
  657. help.HelpType = cmDocumentation::Full;
  658. GET_OPT_ARGUMENT(help.Filename);
  659. help.HelpForm = this->GetFormFromFilename(help.Filename);
  660. }
  661. else if(strcmp(argv[i], "--help-html") == 0)
  662. {
  663. help.HelpType = cmDocumentation::Full;
  664. GET_OPT_ARGUMENT(help.Filename);
  665. help.HelpForm = cmDocumentation::HTMLForm;
  666. }
  667. else if(strcmp(argv[i], "--help-man") == 0)
  668. {
  669. help.HelpType = cmDocumentation::Full;
  670. GET_OPT_ARGUMENT(help.Filename);
  671. help.HelpForm = cmDocumentation::ManForm;
  672. }
  673. else if(strcmp(argv[i], "--help-command") == 0)
  674. {
  675. help.HelpType = cmDocumentation::Single;
  676. GET_OPT_ARGUMENT(help.Argument);
  677. GET_OPT_ARGUMENT(help.Filename);
  678. help.Argument = cmSystemTools::LowerCase(help.Argument);
  679. help.HelpForm = this->GetFormFromFilename(help.Filename);
  680. }
  681. else if(strcmp(argv[i], "--help-module") == 0)
  682. {
  683. help.HelpType = cmDocumentation::SingleModule;
  684. GET_OPT_ARGUMENT(help.Argument);
  685. GET_OPT_ARGUMENT(help.Filename);
  686. help.HelpForm = this->GetFormFromFilename(help.Filename);
  687. }
  688. else if(strcmp(argv[i], "--help-property") == 0)
  689. {
  690. help.HelpType = cmDocumentation::SingleProperty;
  691. GET_OPT_ARGUMENT(help.Argument);
  692. GET_OPT_ARGUMENT(help.Filename);
  693. help.HelpForm = this->GetFormFromFilename(help.Filename);
  694. }
  695. else if(strcmp(argv[i], "--help-variable") == 0)
  696. {
  697. help.HelpType = cmDocumentation::SingleVariable;
  698. GET_OPT_ARGUMENT(help.Argument);
  699. GET_OPT_ARGUMENT(help.Filename);
  700. help.HelpForm = this->GetFormFromFilename(help.Filename);
  701. }
  702. else if(strcmp(argv[i], "--help-command-list") == 0)
  703. {
  704. help.HelpType = cmDocumentation::List;
  705. GET_OPT_ARGUMENT(help.Filename);
  706. help.HelpForm = cmDocumentation::TextForm;
  707. }
  708. else if(strcmp(argv[i], "--help-module-list") == 0)
  709. {
  710. help.HelpType = cmDocumentation::ModuleList;
  711. GET_OPT_ARGUMENT(help.Filename);
  712. help.HelpForm = cmDocumentation::TextForm;
  713. }
  714. else if(strcmp(argv[i], "--help-property-list") == 0)
  715. {
  716. help.HelpType = cmDocumentation::PropertyList;
  717. GET_OPT_ARGUMENT(help.Filename);
  718. help.HelpForm = cmDocumentation::TextForm;
  719. }
  720. else if(strcmp(argv[i], "--help-variable-list") == 0)
  721. {
  722. help.HelpType = cmDocumentation::VariableList;
  723. GET_OPT_ARGUMENT(help.Filename);
  724. help.HelpForm = cmDocumentation::TextForm;
  725. }
  726. else if(strcmp(argv[i], "--copyright") == 0)
  727. {
  728. help.HelpType = cmDocumentation::Copyright;
  729. GET_OPT_ARGUMENT(help.Filename);
  730. help.HelpForm = cmDocumentation::UsageForm;
  731. }
  732. else if((strcmp(argv[i], "--version") == 0) ||
  733. (strcmp(argv[i], "-version") == 0) ||
  734. (strcmp(argv[i], "/V") == 0))
  735. {
  736. help.HelpType = cmDocumentation::Version;
  737. GET_OPT_ARGUMENT(help.Filename);
  738. help.HelpForm = cmDocumentation::UsageForm;
  739. }
  740. if(help.HelpType != None)
  741. {
  742. // This is a help option. See if there is a file name given.
  743. result = true;
  744. this->RequestedHelpItems.push_back(help);
  745. }
  746. }
  747. return result;
  748. }
  749. //----------------------------------------------------------------------------
  750. void cmDocumentation::Print(Form f, std::ostream& os)
  751. {
  752. this->SetForm(f);
  753. this->Print(os);
  754. }
  755. //----------------------------------------------------------------------------
  756. void cmDocumentation::Print(std::ostream& os)
  757. {
  758. for(unsigned int i=0; i < this->PrintSections.size(); ++i)
  759. {
  760. std::string name = this->PrintSections[i]->
  761. GetName((this->CurrentFormatter->GetForm()));
  762. this->CurrentFormatter->PrintSection(os,*this->PrintSections[i],
  763. name.c_str());
  764. }
  765. }
  766. //----------------------------------------------------------------------------
  767. void cmDocumentation::SetName(const char* name)
  768. {
  769. this->NameString = name?name:"";
  770. }
  771. //----------------------------------------------------------------------------
  772. void cmDocumentation::SetSection(const char *name,
  773. cmDocumentationSection *section)
  774. {
  775. if (this->AllSections.find(name) != this->AllSections.end())
  776. {
  777. delete this->AllSections[name];
  778. }
  779. this->AllSections[name] = section;
  780. }
  781. //----------------------------------------------------------------------------
  782. void cmDocumentation::SetSection(const char *name,
  783. std::vector<cmDocumentationEntry> &docs)
  784. {
  785. cmDocumentationSection *sec =
  786. new cmDocumentationSection(name,
  787. cmSystemTools::UpperCase(name).c_str());
  788. sec->Append(docs);
  789. this->SetSection(name,sec);
  790. }
  791. //----------------------------------------------------------------------------
  792. void cmDocumentation::SetSection(const char *name,
  793. const char *docs[][3])
  794. {
  795. cmDocumentationSection *sec =
  796. new cmDocumentationSection(name,
  797. cmSystemTools::UpperCase(name).c_str());
  798. sec->Append(docs);
  799. this->SetSection(name,sec);
  800. }
  801. //----------------------------------------------------------------------------
  802. void cmDocumentation
  803. ::SetSections(std::map<std::string,cmDocumentationSection *> &sections)
  804. {
  805. for (std::map<std::string,cmDocumentationSection *>::const_iterator
  806. it = sections.begin(); it != sections.end(); ++it)
  807. {
  808. this->SetSection(it->first.c_str(),it->second);
  809. }
  810. }
  811. //----------------------------------------------------------------------------
  812. void cmDocumentation::PrependSection(const char *name,
  813. const char *docs[][3])
  814. {
  815. cmDocumentationSection *sec = 0;
  816. if (this->AllSections.find(name) == this->AllSections.end())
  817. {
  818. sec = new cmDocumentationSection
  819. (name, cmSystemTools::UpperCase(name).c_str());
  820. this->SetSection(name,sec);
  821. }
  822. else
  823. {
  824. sec = this->AllSections[name];
  825. }
  826. sec->Prepend(docs);
  827. }
  828. //----------------------------------------------------------------------------
  829. void cmDocumentation::PrependSection(const char *name,
  830. std::vector<cmDocumentationEntry> &docs)
  831. {
  832. cmDocumentationSection *sec = 0;
  833. if (this->AllSections.find(name) == this->AllSections.end())
  834. {
  835. sec = new cmDocumentationSection
  836. (name, cmSystemTools::UpperCase(name).c_str());
  837. this->SetSection(name,sec);
  838. }
  839. else
  840. {
  841. sec = this->AllSections[name];
  842. }
  843. sec->Prepend(docs);
  844. }
  845. //----------------------------------------------------------------------------
  846. void cmDocumentation::AppendSection(const char *name,
  847. const char *docs[][3])
  848. {
  849. cmDocumentationSection *sec = 0;
  850. if (this->AllSections.find(name) == this->AllSections.end())
  851. {
  852. sec = new cmDocumentationSection
  853. (name, cmSystemTools::UpperCase(name).c_str());
  854. this->SetSection(name,sec);
  855. }
  856. else
  857. {
  858. sec = this->AllSections[name];
  859. }
  860. sec->Append(docs);
  861. }
  862. //----------------------------------------------------------------------------
  863. void cmDocumentation::AppendSection(const char *name,
  864. std::vector<cmDocumentationEntry> &docs)
  865. {
  866. cmDocumentationSection *sec = 0;
  867. if (this->AllSections.find(name) == this->AllSections.end())
  868. {
  869. sec = new cmDocumentationSection
  870. (name, cmSystemTools::UpperCase(name).c_str());
  871. this->SetSection(name,sec);
  872. }
  873. else
  874. {
  875. sec = this->AllSections[name];
  876. }
  877. sec->Append(docs);
  878. }
  879. //----------------------------------------------------------------------------
  880. void cmDocumentation::AppendSection(const char *name,
  881. cmDocumentationEntry &docs)
  882. {
  883. std::vector<cmDocumentationEntry> docsVec;
  884. docsVec.push_back(docs);
  885. this->AppendSection(name,docsVec);
  886. }
  887. //----------------------------------------------------------------------------
  888. void cmDocumentation::PrependSection(const char *name,
  889. cmDocumentationEntry &docs)
  890. {
  891. std::vector<cmDocumentationEntry> docsVec;
  892. docsVec.push_back(docs);
  893. this->PrependSection(name,docsVec);
  894. }
  895. //----------------------------------------------------------------------------
  896. void cmDocumentation::SetSeeAlsoList(const char *data[][3])
  897. {
  898. cmDocumentationSection *sec =
  899. new cmDocumentationSection("See Also", "SEE ALSO");
  900. this->AllSections["See Also"] = sec;
  901. this->SeeAlsoString = ".B ";
  902. int i = 0;
  903. while(data[i][1])
  904. {
  905. this->SeeAlsoString += data[i][1];
  906. this->SeeAlsoString += data[i+1][1]? "(1), ":"(1)";
  907. ++i;
  908. }
  909. sec->Append(0,this->SeeAlsoString.c_str(),0);
  910. sec->Append(cmDocumentationStandardSeeAlso);
  911. }
  912. //----------------------------------------------------------------------------
  913. bool cmDocumentation::PrintDocumentationGeneric(std::ostream& os,
  914. const char *section)
  915. {
  916. if(this->AllSections.find(section) == this->AllSections.end())
  917. {
  918. os << "Internal error: " << section << " list is empty." << std::endl;
  919. return false;
  920. }
  921. if(this->CurrentArgument.length() == 0)
  922. {
  923. os << "Required argument missing.\n";
  924. return false;
  925. }
  926. const std::vector<cmDocumentationEntry> &entries =
  927. this->AllSections[section]->GetEntries();
  928. for(std::vector<cmDocumentationEntry>::const_iterator ei =
  929. entries.begin();
  930. ei != entries.end(); ++ei)
  931. {
  932. if(this->CurrentArgument == ei->Name)
  933. {
  934. this->PrintDocumentationCommand(os, *ei);
  935. return true;
  936. }
  937. }
  938. return false;
  939. }
  940. //----------------------------------------------------------------------------
  941. bool cmDocumentation::PrintDocumentationSingle(std::ostream& os)
  942. {
  943. if (this->PrintDocumentationGeneric(os,"Commands"))
  944. {
  945. return true;
  946. }
  947. if (this->PrintDocumentationGeneric(os,"Compatibility Commands"))
  948. {
  949. return true;
  950. }
  951. // Argument was not a command. Complain.
  952. os << "Argument \"" << this->CurrentArgument.c_str()
  953. << "\" to --help-command is not a CMake command. "
  954. << "Use --help-command-list to see all commands.\n";
  955. return false;
  956. }
  957. //----------------------------------------------------------------------------
  958. bool cmDocumentation::PrintDocumentationSingleModule(std::ostream& os)
  959. {
  960. if(this->CurrentArgument.length() == 0)
  961. {
  962. os << "Argument --help-module needs a module name.\n";
  963. return false;
  964. }
  965. std::string moduleName;
  966. // find the module
  967. std::vector<std::string> dirs;
  968. cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
  969. for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
  970. dirIt != dirs.end();
  971. ++dirIt)
  972. {
  973. moduleName = *dirIt;
  974. moduleName += "/";
  975. moduleName += this->CurrentArgument;
  976. moduleName += ".cmake";
  977. if(cmSystemTools::FileExists(moduleName.c_str()))
  978. {
  979. break;
  980. }
  981. moduleName = "";
  982. }
  983. if (moduleName.empty())
  984. {
  985. moduleName = this->CMakeRoot;
  986. moduleName += "/Modules/";
  987. moduleName += this->CurrentArgument;
  988. moduleName += ".cmake";
  989. if(!cmSystemTools::FileExists(moduleName.c_str()))
  990. {
  991. moduleName = "";
  992. }
  993. }
  994. if(!moduleName.empty())
  995. {
  996. cmDocumentationSection *sec =
  997. new cmDocumentationSection("Standard CMake Modules", "MODULES");
  998. this->AllSections["Modules"] = sec;
  999. if (this->CreateSingleModule(moduleName.c_str(),
  1000. this->CurrentArgument.c_str(),
  1001. *this->AllSections["Modules"]))
  1002. {
  1003. this->PrintDocumentationCommand
  1004. (os, this->AllSections["Modules"]->GetEntries()[0]);
  1005. os << "\n Defined in: ";
  1006. os << moduleName << "\n";
  1007. return true;
  1008. }
  1009. }
  1010. // Argument was not a module. Complain.
  1011. os << "Argument \"" << this->CurrentArgument.c_str()
  1012. << "\" to --help-module is not a CMake module.\n";
  1013. return false;
  1014. }
  1015. //----------------------------------------------------------------------------
  1016. bool cmDocumentation::PrintDocumentationSingleProperty(std::ostream& os)
  1017. {
  1018. bool done = false;
  1019. for (std::vector<std::string>::iterator i =
  1020. this->PropertySections.begin();
  1021. !done && i != this->PropertySections.end(); ++i)
  1022. {
  1023. done = this->PrintDocumentationGeneric(os,i->c_str());
  1024. }
  1025. if (done)
  1026. {
  1027. return true;
  1028. }
  1029. // Argument was not a command. Complain.
  1030. os << "Argument \"" << this->CurrentArgument.c_str()
  1031. << "\" to --help-property is not a CMake property. "
  1032. << "Use --help-property-list to see all properties.\n";
  1033. return false;
  1034. }
  1035. //----------------------------------------------------------------------------
  1036. bool cmDocumentation::PrintDocumentationSingleVariable(std::ostream& os)
  1037. {
  1038. bool done = false;
  1039. for (std::vector<std::string>::iterator i =
  1040. this->VariableSections.begin();
  1041. !done && i != this->VariableSections.end(); ++i)
  1042. {
  1043. done = this->PrintDocumentationGeneric(os,i->c_str());
  1044. }
  1045. if (done)
  1046. {
  1047. return true;
  1048. }
  1049. // Argument was not a command. Complain.
  1050. os << "Argument \"" << this->CurrentArgument.c_str()
  1051. << "\" to --help-variable is not a defined variable. "
  1052. << "Use --help-variable-list to see all defined variables.\n";
  1053. return false;
  1054. }
  1055. //----------------------------------------------------------------------------
  1056. bool cmDocumentation::PrintDocumentationList(std::ostream& os,
  1057. const char *section)
  1058. {
  1059. if(this->AllSections.find(section) == this->AllSections.end())
  1060. {
  1061. os << "Internal error: " << section << " list is empty." << std::endl;
  1062. return false;
  1063. }
  1064. const std::vector<cmDocumentationEntry> &entries =
  1065. this->AllSections[section]->GetEntries();
  1066. for(std::vector<cmDocumentationEntry>::const_iterator ei =
  1067. entries.begin();
  1068. ei != entries.end(); ++ei)
  1069. {
  1070. if(ei->Name.size())
  1071. {
  1072. os << ei->Name << std::endl;
  1073. }
  1074. }
  1075. return true;
  1076. }
  1077. //----------------------------------------------------------------------------
  1078. bool cmDocumentation::PrintDocumentationUsage(std::ostream& os)
  1079. {
  1080. this->ClearSections();
  1081. this->AddSectionToPrint("Usage");
  1082. this->AddSectionToPrint("Options");
  1083. this->AddSectionToPrint("Generators");
  1084. this->Print(os);
  1085. return true;
  1086. }
  1087. //----------------------------------------------------------------------------
  1088. bool cmDocumentation::PrintDocumentationFull(std::ostream& os)
  1089. {
  1090. this->CreateFullDocumentation();
  1091. this->CurrentFormatter->PrintHeader(GetNameString(), os);
  1092. this->Print(os);
  1093. this->CurrentFormatter->PrintFooter(os);
  1094. return true;
  1095. }
  1096. //----------------------------------------------------------------------------
  1097. bool cmDocumentation::PrintDocumentationModules(std::ostream& os)
  1098. {
  1099. this->ClearSections();
  1100. this->CreateModulesSection();
  1101. this->AddSectionToPrint("Description");
  1102. this->AddSectionToPrint("Modules");
  1103. this->AddSectionToPrint("Copyright");
  1104. this->AddSectionToPrint("See Also");
  1105. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1106. this->Print(os);
  1107. this->CurrentFormatter->PrintFooter(os);
  1108. return true;
  1109. }
  1110. //----------------------------------------------------------------------------
  1111. bool cmDocumentation::PrintDocumentationCustomModules(std::ostream& os)
  1112. {
  1113. this->ClearSections();
  1114. this->CreateCustomModulesSection();
  1115. this->AddSectionToPrint("Description");
  1116. this->AddSectionToPrint("Custom Modules");
  1117. this->AddSectionToPrint("Copyright");
  1118. this->AddSectionToPrint("See Also");
  1119. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1120. this->Print(os);
  1121. this->CurrentFormatter->PrintFooter(os);
  1122. return true;
  1123. }
  1124. //----------------------------------------------------------------------------
  1125. bool cmDocumentation::PrintDocumentationProperties(std::ostream& os)
  1126. {
  1127. this->ClearSections();
  1128. this->AddSectionToPrint("Properties Description");
  1129. for (std::vector<std::string>::iterator i =
  1130. this->PropertySections.begin();
  1131. i != this->PropertySections.end(); ++i)
  1132. {
  1133. this->AddSectionToPrint(i->c_str());
  1134. }
  1135. this->AddSectionToPrint("Copyright");
  1136. this->AddSectionToPrint("Standard See Also");
  1137. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1138. this->Print(os);
  1139. this->CurrentFormatter->PrintFooter(os);
  1140. return true;
  1141. }
  1142. //----------------------------------------------------------------------------
  1143. bool cmDocumentation::PrintDocumentationVariables(std::ostream& os)
  1144. {
  1145. this->ClearSections();
  1146. for (std::vector<std::string>::iterator i =
  1147. this->VariableSections.begin();
  1148. i != this->VariableSections.end(); ++i)
  1149. {
  1150. this->AddSectionToPrint(i->c_str());
  1151. }
  1152. this->AddSectionToPrint("Copyright");
  1153. this->AddSectionToPrint("Standard See Also");
  1154. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1155. this->Print(os);
  1156. this->CurrentFormatter->PrintFooter(os);
  1157. return true;
  1158. }
  1159. //----------------------------------------------------------------------------
  1160. bool cmDocumentation::PrintDocumentationCurrentCommands(std::ostream& os)
  1161. {
  1162. this->ClearSections();
  1163. this->AddSectionToPrint("Commands");
  1164. this->AddSectionToPrint("Copyright");
  1165. this->AddSectionToPrint("Standard See Also");
  1166. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1167. this->Print(os);
  1168. this->CurrentFormatter->PrintFooter(os);
  1169. return true;
  1170. }
  1171. //----------------------------------------------------------------------------
  1172. bool cmDocumentation::PrintDocumentationCompatCommands(std::ostream& os)
  1173. {
  1174. this->ClearSections();
  1175. this->AddSectionToPrint("Compatibility Commands Description");
  1176. this->AddSectionToPrint("Compatibility Commands");
  1177. this->AddSectionToPrint("Copyright");
  1178. this->AddSectionToPrint("Standard See Also");
  1179. this->CurrentFormatter->PrintHeader(GetNameString(), os);
  1180. this->Print(os);
  1181. this->CurrentFormatter->PrintFooter(os);
  1182. return true;
  1183. }
  1184. //----------------------------------------------------------------------------
  1185. void cmDocumentation
  1186. ::PrintDocumentationCommand(std::ostream& os,
  1187. const cmDocumentationEntry &entry)
  1188. {
  1189. cmDocumentationSection *sec = new cmDocumentationSection("","");
  1190. sec->Append(entry);
  1191. this->AllSections["temp"] = sec;
  1192. this->ClearSections();
  1193. this->AddSectionToPrint("temp");
  1194. this->Print(os);
  1195. this->AllSections.erase("temp");
  1196. delete sec;
  1197. }
  1198. //----------------------------------------------------------------------------
  1199. void cmDocumentation::CreateFullDocumentation()
  1200. {
  1201. this->ClearSections();
  1202. this->CreateCustomModulesSection();
  1203. this->CreateModulesSection();
  1204. std::set<std::string> emitted;
  1205. this->AddSectionToPrint("Name");
  1206. emitted.insert("Name");
  1207. this->AddSectionToPrint("Usage");
  1208. emitted.insert("Usage");
  1209. this->AddSectionToPrint("Description");
  1210. emitted.insert("Description");
  1211. this->AddSectionToPrint("Options");
  1212. emitted.insert("Options");
  1213. this->AddSectionToPrint("Generators");
  1214. emitted.insert("Generators");
  1215. this->AddSectionToPrint("Commands");
  1216. emitted.insert("Commands");
  1217. this->AddSectionToPrint("Properties Description");
  1218. emitted.insert("Properties Description");
  1219. for (std::vector<std::string>::iterator i =
  1220. this->PropertySections.begin();
  1221. i != this->PropertySections.end(); ++i)
  1222. {
  1223. this->AddSectionToPrint(i->c_str());
  1224. emitted.insert(i->c_str());
  1225. }
  1226. emitted.insert("Copyright");
  1227. emitted.insert("See Also");
  1228. emitted.insert("Standard See Also");
  1229. emitted.insert("Author");
  1230. // add any sections not yet written out, or to be written out
  1231. for (std::map<std::string, cmDocumentationSection*>::iterator i =
  1232. this->AllSections.begin();
  1233. i != this->AllSections.end(); ++i)
  1234. {
  1235. if (emitted.find(i->first) == emitted.end())
  1236. {
  1237. this->AddSectionToPrint(i->first.c_str());
  1238. }
  1239. }
  1240. this->AddSectionToPrint("Copyright");
  1241. if(this->CurrentFormatter->GetForm() == ManForm)
  1242. {
  1243. this->AddSectionToPrint("See Also");
  1244. this->AddSectionToPrint("Author");
  1245. }
  1246. else
  1247. {
  1248. this->AddSectionToPrint("Standard See Also");
  1249. }
  1250. }
  1251. //----------------------------------------------------------------------------
  1252. void cmDocumentation::SetForm(Form f)
  1253. {
  1254. switch(f)
  1255. {
  1256. case HTMLForm:
  1257. this->CurrentFormatter = &this->HTMLFormatter;
  1258. break;
  1259. case ManForm:
  1260. this->CurrentFormatter = &this->ManFormatter;
  1261. break;
  1262. case TextForm:
  1263. this->CurrentFormatter = &this->TextFormatter;
  1264. break;
  1265. case UsageForm:
  1266. this->CurrentFormatter = & this->UsageFormatter;
  1267. break;
  1268. }
  1269. }
  1270. //----------------------------------------------------------------------------
  1271. const char* cmDocumentation::GetNameString() const
  1272. {
  1273. if(this->NameString.length() > 0)
  1274. {
  1275. return this->NameString.c_str();
  1276. }
  1277. else
  1278. {
  1279. return "CMake";
  1280. }
  1281. }
  1282. //----------------------------------------------------------------------------
  1283. bool cmDocumentation::IsOption(const char* arg) const
  1284. {
  1285. return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
  1286. (strcmp(arg, "/?") == 0));
  1287. }