cmDocumentation.cxx 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  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 build system 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. // find the modules first, print the custom module docs only if
  315. // any custom modules have been found actually, Alex
  316. this->CreateCustomModulesSection();
  317. this->CreateModulesSection();
  318. if (this->AllSections.find("Custom CMake Modules")
  319. != this->AllSections.end())
  320. {
  321. this->PrintDocumentationList(os,"Custom CMake Modules");
  322. }
  323. this->PrintDocumentationList(os,"Modules");
  324. return true;
  325. case cmDocumentation::PropertyList:
  326. this->PrintDocumentationList(os,"Properties Description");
  327. for (std::vector<std::string>::iterator i =
  328. this->PropertySections.begin();
  329. i != this->PropertySections.end(); ++i)
  330. {
  331. this->PrintDocumentationList(os,i->c_str());
  332. }
  333. return true;
  334. case cmDocumentation::VariableList:
  335. for (std::vector<std::string>::iterator i =
  336. this->VariableSections.begin();
  337. i != this->VariableSections.end(); ++i)
  338. {
  339. this->PrintDocumentationList(os,i->c_str());
  340. }
  341. return true;
  342. case cmDocumentation::Full:
  343. return this->PrintDocumentationFull(os);
  344. case cmDocumentation::Modules:
  345. return this->PrintDocumentationModules(os);
  346. case cmDocumentation::CustomModules:
  347. return this->PrintDocumentationCustomModules(os);
  348. case cmDocumentation::Properties:
  349. return this->PrintDocumentationProperties(os);
  350. case cmDocumentation::Variables:
  351. return this->PrintDocumentationVariables(os);
  352. case cmDocumentation::Commands:
  353. return this->PrintDocumentationCurrentCommands(os);
  354. case cmDocumentation::CompatCommands:
  355. return this->PrintDocumentationCompatCommands(os);
  356. case cmDocumentation::Copyright:
  357. return this->PrintCopyright(os);
  358. case cmDocumentation::Version:
  359. return true;
  360. default: return false;
  361. }
  362. }
  363. //----------------------------------------------------------------------------
  364. bool cmDocumentation::CreateModulesSection()
  365. {
  366. cmDocumentationSection *sec =
  367. new cmDocumentationSection("Standard CMake Modules", "MODULES");
  368. this->AllSections["Modules"] = sec;
  369. std::string cmakeModules = this->CMakeRoot;
  370. cmakeModules += "/Modules";
  371. cmsys::Directory dir;
  372. dir.Load(cmakeModules.c_str());
  373. if (dir.GetNumberOfFiles() > 0)
  374. {
  375. sec->Append(cmDocumentationModulesHeader[0]);
  376. sec->Append(cmModulesDocumentationDescription);
  377. this->CreateModuleDocsForDir(dir, *this->AllSections["Modules"]);
  378. }
  379. return true;
  380. }
  381. //----------------------------------------------------------------------------
  382. bool cmDocumentation::CreateCustomModulesSection()
  383. {
  384. bool sectionHasHeader = false;
  385. std::vector<std::string> dirs;
  386. cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
  387. for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
  388. dirIt != dirs.end();
  389. ++dirIt)
  390. {
  391. cmsys::Directory dir;
  392. dir.Load(dirIt->c_str());
  393. if (dir.GetNumberOfFiles() > 0)
  394. {
  395. if (!sectionHasHeader)
  396. {
  397. cmDocumentationSection *sec =
  398. new cmDocumentationSection("Custom CMake Modules","CUSTOM MODULES");
  399. this->AllSections["Custom CMake Modules"] = sec;
  400. sec->Append(cmDocumentationCustomModulesHeader[0]);
  401. sec->Append(cmCustomModulesDocumentationDescription);
  402. sectionHasHeader = true;
  403. }
  404. this->CreateModuleDocsForDir
  405. (dir, *this->AllSections["Custom CMake Modules"]);
  406. }
  407. }
  408. return true;
  409. }
  410. //----------------------------------------------------------------------------
  411. void cmDocumentation
  412. ::CreateModuleDocsForDir(cmsys::Directory& dir,
  413. cmDocumentationSection &moduleSection)
  414. {
  415. // sort the files alphabetically, so the docs for one module are easier
  416. // to find than if they are in random order
  417. std::vector<std::string> sortedFiles;
  418. for(unsigned int i = 0; i < dir.GetNumberOfFiles(); ++i)
  419. {
  420. sortedFiles.push_back(dir.GetFile(i));
  421. }
  422. std::sort(sortedFiles.begin(), sortedFiles.end());
  423. for(std::vector<std::string>::const_iterator fname = sortedFiles.begin();
  424. fname!=sortedFiles.end(); ++fname)
  425. {
  426. if(fname->length() > 6)
  427. {
  428. if(fname->substr(fname->length()-6, 6) == ".cmake")
  429. {
  430. std::string moduleName = fname->substr(0, fname->length()-6);
  431. // this check is to avoid creating documentation for the modules with
  432. // the same name in multiple directories of CMAKE_MODULE_PATH
  433. if (this->ModulesFound.find(moduleName) == this->ModulesFound.end())
  434. {
  435. this->ModulesFound.insert(moduleName);
  436. std::string path = dir.GetPath();
  437. path += "/";
  438. path += (*fname);
  439. this->CreateSingleModule(path.c_str(), moduleName.c_str(),
  440. moduleSection);
  441. }
  442. }
  443. }
  444. }
  445. }
  446. //----------------------------------------------------------------------------
  447. bool cmDocumentation::CreateSingleModule(const char* fname,
  448. const char* moduleName,
  449. cmDocumentationSection &moduleSection)
  450. {
  451. std::ifstream fin(fname);
  452. if(!fin)
  453. {
  454. std::cerr << "Internal error: can not open module." << fname << std::endl;
  455. return false;
  456. }
  457. std::string line;
  458. std::string text;
  459. std::string brief;
  460. brief = " ";
  461. bool newParagraph = true;
  462. while ( fin && cmSystemTools::GetLineFromStream(fin, line) )
  463. {
  464. if(line.size() && line[0] == '#')
  465. {
  466. // blank line
  467. if(line.size() <= 2)
  468. {
  469. text += "\n";
  470. newParagraph = true;
  471. }
  472. else if(line[2] == '-')
  473. {
  474. brief = line.c_str()+4;
  475. }
  476. else
  477. {
  478. // two spaces
  479. if(line[1] == ' ' && line[2] == ' ')
  480. {
  481. if(!newParagraph)
  482. {
  483. text += "\n";
  484. newParagraph = true;
  485. }
  486. // Skip #, and leave space for preformatted
  487. text += line.c_str()+1;
  488. text += "\n";
  489. }
  490. else if(line[1] == ' ')
  491. {
  492. if(!newParagraph)
  493. {
  494. text += " ";
  495. }
  496. newParagraph = false;
  497. // skip # and space
  498. text += line.c_str()+2;
  499. }
  500. else
  501. {
  502. if(!newParagraph)
  503. {
  504. text += " ";
  505. }
  506. newParagraph = false;
  507. // skip #
  508. text += line.c_str()+1;
  509. }
  510. }
  511. }
  512. else
  513. {
  514. if(text.length() < 2 && brief.length() == 1)
  515. {
  516. return false;
  517. }
  518. char* pname = strcpy(new char[strlen(moduleName)+1], moduleName);
  519. char* ptext = strcpy(new char[text.length()+1], text.c_str());
  520. this->ModuleStrings.push_back(pname);
  521. this->ModuleStrings.push_back(ptext);
  522. char* pbrief = strcpy(new char[brief.length()+1], brief.c_str());
  523. this->ModuleStrings.push_back(pbrief);
  524. moduleSection.Append(pname, pbrief, ptext);
  525. return true;
  526. }
  527. }
  528. return true;
  529. }
  530. //----------------------------------------------------------------------------
  531. bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
  532. {
  533. bool result = true;
  534. // Loop over requested documentation types.
  535. for(std::vector<RequestedHelpItem>::const_iterator
  536. i = this->RequestedHelpItems.begin();
  537. i != this->RequestedHelpItems.end();
  538. ++i)
  539. {
  540. this->SetForm(i->HelpForm);
  541. this->CurrentArgument = i->Argument;
  542. // If a file name was given, use it. Otherwise, default to the
  543. // given stream.
  544. std::ofstream* fout = 0;
  545. std::ostream* s = &os;
  546. if(i->Filename.length() > 0)
  547. {
  548. fout = new std::ofstream(i->Filename.c_str(), std::ios::out);
  549. if(fout)
  550. {
  551. s = fout;
  552. }
  553. else
  554. {
  555. result = false;
  556. }
  557. }
  558. // Print this documentation type to the stream.
  559. if(!this->PrintDocumentation(i->HelpType, *s) || !*s)
  560. {
  561. result = false;
  562. }
  563. // Close the file if we wrote one.
  564. if(fout)
  565. {
  566. delete fout;
  567. }
  568. }
  569. return result;
  570. }
  571. #define GET_OPT_ARGUMENT(target) \
  572. if((i+1 < argc) && !this->IsOption(argv[i+1])) \
  573. { \
  574. target = argv[i+1]; \
  575. i = i+1; \
  576. };
  577. cmDocumentation::Form cmDocumentation::GetFormFromFilename(
  578. const std::string& filename)
  579. {
  580. std::string ext = cmSystemTools::GetFilenameExtension(filename);
  581. ext = cmSystemTools::UpperCase(ext);
  582. if ((ext == ".HTM") || (ext == ".HTML"))
  583. {
  584. return cmDocumentation::HTMLForm;
  585. }
  586. // ".1" to ".9" should be manpages
  587. if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
  588. {
  589. return cmDocumentation::ManForm;
  590. }
  591. return cmDocumentation::TextForm;
  592. }
  593. //----------------------------------------------------------------------------
  594. bool cmDocumentation::CheckOptions(int argc, const char* const* argv)
  595. {
  596. // Providing zero arguments gives usage information.
  597. if(argc == 1)
  598. {
  599. RequestedHelpItem help;
  600. help.HelpType = cmDocumentation::Usage;
  601. help.HelpForm = cmDocumentation::UsageForm;
  602. this->RequestedHelpItems.push_back(help);
  603. return true;
  604. }
  605. // Search for supported help options.
  606. bool result = false;
  607. for(int i=1; i < argc; ++i)
  608. {
  609. RequestedHelpItem help;
  610. // Check if this is a supported help option.
  611. if((strcmp(argv[i], "-help") == 0) ||
  612. (strcmp(argv[i], "--help") == 0) ||
  613. (strcmp(argv[i], "/?") == 0) ||
  614. (strcmp(argv[i], "-usage") == 0) ||
  615. (strcmp(argv[i], "-h") == 0) ||
  616. (strcmp(argv[i], "-H") == 0))
  617. {
  618. help.HelpType = cmDocumentation::Usage;
  619. help.HelpForm = cmDocumentation::UsageForm;
  620. GET_OPT_ARGUMENT(help.Argument);
  621. help.Argument = cmSystemTools::LowerCase(help.Argument);
  622. // special case for single command
  623. if (!help.Argument.empty())
  624. {
  625. help.HelpType = cmDocumentation::Single;
  626. }
  627. }
  628. else if(strcmp(argv[i], "--help-properties") == 0)
  629. {
  630. help.HelpType = cmDocumentation::Properties;
  631. GET_OPT_ARGUMENT(help.Filename);
  632. help.HelpForm = this->GetFormFromFilename(help.Filename);
  633. }
  634. else if(strcmp(argv[i], "--help-variables") == 0)
  635. {
  636. help.HelpType = cmDocumentation::Variables;
  637. GET_OPT_ARGUMENT(help.Filename);
  638. help.HelpForm = this->GetFormFromFilename(help.Filename);
  639. }
  640. else if(strcmp(argv[i], "--help-modules") == 0)
  641. {
  642. help.HelpType = cmDocumentation::Modules;
  643. GET_OPT_ARGUMENT(help.Filename);
  644. help.HelpForm = this->GetFormFromFilename(help.Filename);
  645. }
  646. else if(strcmp(argv[i], "--help-custom-modules") == 0)
  647. {
  648. help.HelpType = cmDocumentation::CustomModules;
  649. GET_OPT_ARGUMENT(help.Filename);
  650. help.HelpForm = this->GetFormFromFilename(help.Filename);
  651. }
  652. else if(strcmp(argv[i], "--help-commands") == 0)
  653. {
  654. help.HelpType = cmDocumentation::Commands;
  655. GET_OPT_ARGUMENT(help.Filename);
  656. help.HelpForm = this->GetFormFromFilename(help.Filename);
  657. }
  658. else if(strcmp(argv[i], "--help-compatcommands") == 0)
  659. {
  660. help.HelpType = cmDocumentation::CompatCommands;
  661. GET_OPT_ARGUMENT(help.Filename);
  662. help.HelpForm = this->GetFormFromFilename(help.Filename);
  663. }
  664. else if(strcmp(argv[i], "--help-full") == 0)
  665. {
  666. help.HelpType = cmDocumentation::Full;
  667. GET_OPT_ARGUMENT(help.Filename);
  668. help.HelpForm = this->GetFormFromFilename(help.Filename);
  669. }
  670. else if(strcmp(argv[i], "--help-html") == 0)
  671. {
  672. help.HelpType = cmDocumentation::Full;
  673. GET_OPT_ARGUMENT(help.Filename);
  674. help.HelpForm = cmDocumentation::HTMLForm;
  675. }
  676. else if(strcmp(argv[i], "--help-man") == 0)
  677. {
  678. help.HelpType = cmDocumentation::Full;
  679. GET_OPT_ARGUMENT(help.Filename);
  680. help.HelpForm = cmDocumentation::ManForm;
  681. }
  682. else if(strcmp(argv[i], "--help-command") == 0)
  683. {
  684. help.HelpType = cmDocumentation::Single;
  685. GET_OPT_ARGUMENT(help.Argument);
  686. GET_OPT_ARGUMENT(help.Filename);
  687. help.Argument = cmSystemTools::LowerCase(help.Argument);
  688. help.HelpForm = this->GetFormFromFilename(help.Filename);
  689. }
  690. else if(strcmp(argv[i], "--help-module") == 0)
  691. {
  692. help.HelpType = cmDocumentation::SingleModule;
  693. GET_OPT_ARGUMENT(help.Argument);
  694. GET_OPT_ARGUMENT(help.Filename);
  695. help.HelpForm = this->GetFormFromFilename(help.Filename);
  696. }
  697. else if(strcmp(argv[i], "--help-property") == 0)
  698. {
  699. help.HelpType = cmDocumentation::SingleProperty;
  700. GET_OPT_ARGUMENT(help.Argument);
  701. GET_OPT_ARGUMENT(help.Filename);
  702. help.HelpForm = this->GetFormFromFilename(help.Filename);
  703. }
  704. else if(strcmp(argv[i], "--help-variable") == 0)
  705. {
  706. help.HelpType = cmDocumentation::SingleVariable;
  707. GET_OPT_ARGUMENT(help.Argument);
  708. GET_OPT_ARGUMENT(help.Filename);
  709. help.HelpForm = this->GetFormFromFilename(help.Filename);
  710. }
  711. else if(strcmp(argv[i], "--help-command-list") == 0)
  712. {
  713. help.HelpType = cmDocumentation::List;
  714. GET_OPT_ARGUMENT(help.Filename);
  715. help.HelpForm = cmDocumentation::TextForm;
  716. }
  717. else if(strcmp(argv[i], "--help-module-list") == 0)
  718. {
  719. help.HelpType = cmDocumentation::ModuleList;
  720. GET_OPT_ARGUMENT(help.Filename);
  721. help.HelpForm = cmDocumentation::TextForm;
  722. }
  723. else if(strcmp(argv[i], "--help-property-list") == 0)
  724. {
  725. help.HelpType = cmDocumentation::PropertyList;
  726. GET_OPT_ARGUMENT(help.Filename);
  727. help.HelpForm = cmDocumentation::TextForm;
  728. }
  729. else if(strcmp(argv[i], "--help-variable-list") == 0)
  730. {
  731. help.HelpType = cmDocumentation::VariableList;
  732. GET_OPT_ARGUMENT(help.Filename);
  733. help.HelpForm = cmDocumentation::TextForm;
  734. }
  735. else if(strcmp(argv[i], "--copyright") == 0)
  736. {
  737. help.HelpType = cmDocumentation::Copyright;
  738. GET_OPT_ARGUMENT(help.Filename);
  739. help.HelpForm = cmDocumentation::UsageForm;
  740. }
  741. else if((strcmp(argv[i], "--version") == 0) ||
  742. (strcmp(argv[i], "-version") == 0) ||
  743. (strcmp(argv[i], "/V") == 0))
  744. {
  745. help.HelpType = cmDocumentation::Version;
  746. GET_OPT_ARGUMENT(help.Filename);
  747. help.HelpForm = cmDocumentation::UsageForm;
  748. }
  749. if(help.HelpType != None)
  750. {
  751. // This is a help option. See if there is a file name given.
  752. result = true;
  753. this->RequestedHelpItems.push_back(help);
  754. }
  755. }
  756. return result;
  757. }
  758. //----------------------------------------------------------------------------
  759. void cmDocumentation::Print(Form f, std::ostream& os)
  760. {
  761. this->SetForm(f);
  762. this->Print(os);
  763. }
  764. //----------------------------------------------------------------------------
  765. void cmDocumentation::Print(std::ostream& os)
  766. {
  767. for(unsigned int i=0; i < this->PrintSections.size(); ++i)
  768. {
  769. std::string name = this->PrintSections[i]->
  770. GetName((this->CurrentFormatter->GetForm()));
  771. this->CurrentFormatter->PrintSection(os,*this->PrintSections[i],
  772. name.c_str());
  773. }
  774. }
  775. //----------------------------------------------------------------------------
  776. void cmDocumentation::SetName(const char* name)
  777. {
  778. this->NameString = name?name:"";
  779. }
  780. //----------------------------------------------------------------------------
  781. void cmDocumentation::SetSection(const char *name,
  782. cmDocumentationSection *section)
  783. {
  784. if (this->AllSections.find(name) != this->AllSections.end())
  785. {
  786. delete this->AllSections[name];
  787. }
  788. this->AllSections[name] = section;
  789. }
  790. //----------------------------------------------------------------------------
  791. void cmDocumentation::SetSection(const char *name,
  792. std::vector<cmDocumentationEntry> &docs)
  793. {
  794. cmDocumentationSection *sec =
  795. new cmDocumentationSection(name,
  796. cmSystemTools::UpperCase(name).c_str());
  797. sec->Append(docs);
  798. this->SetSection(name,sec);
  799. }
  800. //----------------------------------------------------------------------------
  801. void cmDocumentation::SetSection(const char *name,
  802. const char *docs[][3])
  803. {
  804. cmDocumentationSection *sec =
  805. new cmDocumentationSection(name,
  806. cmSystemTools::UpperCase(name).c_str());
  807. sec->Append(docs);
  808. this->SetSection(name,sec);
  809. }
  810. //----------------------------------------------------------------------------
  811. void cmDocumentation
  812. ::SetSections(std::map<std::string,cmDocumentationSection *> &sections)
  813. {
  814. for (std::map<std::string,cmDocumentationSection *>::const_iterator
  815. it = sections.begin(); it != sections.end(); ++it)
  816. {
  817. this->SetSection(it->first.c_str(),it->second);
  818. }
  819. }
  820. //----------------------------------------------------------------------------
  821. void cmDocumentation::PrependSection(const char *name,
  822. const char *docs[][3])
  823. {
  824. cmDocumentationSection *sec = 0;
  825. if (this->AllSections.find(name) == this->AllSections.end())
  826. {
  827. sec = new cmDocumentationSection
  828. (name, cmSystemTools::UpperCase(name).c_str());
  829. this->SetSection(name,sec);
  830. }
  831. else
  832. {
  833. sec = this->AllSections[name];
  834. }
  835. sec->Prepend(docs);
  836. }
  837. //----------------------------------------------------------------------------
  838. void cmDocumentation::PrependSection(const char *name,
  839. std::vector<cmDocumentationEntry> &docs)
  840. {
  841. cmDocumentationSection *sec = 0;
  842. if (this->AllSections.find(name) == this->AllSections.end())
  843. {
  844. sec = new cmDocumentationSection
  845. (name, cmSystemTools::UpperCase(name).c_str());
  846. this->SetSection(name,sec);
  847. }
  848. else
  849. {
  850. sec = this->AllSections[name];
  851. }
  852. sec->Prepend(docs);
  853. }
  854. //----------------------------------------------------------------------------
  855. void cmDocumentation::AppendSection(const char *name,
  856. const char *docs[][3])
  857. {
  858. cmDocumentationSection *sec = 0;
  859. if (this->AllSections.find(name) == this->AllSections.end())
  860. {
  861. sec = new cmDocumentationSection
  862. (name, cmSystemTools::UpperCase(name).c_str());
  863. this->SetSection(name,sec);
  864. }
  865. else
  866. {
  867. sec = this->AllSections[name];
  868. }
  869. sec->Append(docs);
  870. }
  871. //----------------------------------------------------------------------------
  872. void cmDocumentation::AppendSection(const char *name,
  873. std::vector<cmDocumentationEntry> &docs)
  874. {
  875. cmDocumentationSection *sec = 0;
  876. if (this->AllSections.find(name) == this->AllSections.end())
  877. {
  878. sec = new cmDocumentationSection
  879. (name, cmSystemTools::UpperCase(name).c_str());
  880. this->SetSection(name,sec);
  881. }
  882. else
  883. {
  884. sec = this->AllSections[name];
  885. }
  886. sec->Append(docs);
  887. }
  888. //----------------------------------------------------------------------------
  889. void cmDocumentation::AppendSection(const char *name,
  890. cmDocumentationEntry &docs)
  891. {
  892. std::vector<cmDocumentationEntry> docsVec;
  893. docsVec.push_back(docs);
  894. this->AppendSection(name,docsVec);
  895. }
  896. //----------------------------------------------------------------------------
  897. void cmDocumentation::PrependSection(const char *name,
  898. cmDocumentationEntry &docs)
  899. {
  900. std::vector<cmDocumentationEntry> docsVec;
  901. docsVec.push_back(docs);
  902. this->PrependSection(name,docsVec);
  903. }
  904. //----------------------------------------------------------------------------
  905. void cmDocumentation::SetSeeAlsoList(const char *data[][3])
  906. {
  907. cmDocumentationSection *sec =
  908. new cmDocumentationSection("See Also", "SEE ALSO");
  909. this->AllSections["See Also"] = sec;
  910. this->SeeAlsoString = ".B ";
  911. int i = 0;
  912. while(data[i][1])
  913. {
  914. this->SeeAlsoString += data[i][1];
  915. this->SeeAlsoString += data[i+1][1]? "(1), ":"(1)";
  916. ++i;
  917. }
  918. sec->Append(0,this->SeeAlsoString.c_str(),0);
  919. sec->Append(cmDocumentationStandardSeeAlso);
  920. }
  921. //----------------------------------------------------------------------------
  922. bool cmDocumentation::PrintDocumentationGeneric(std::ostream& os,
  923. const char *section)
  924. {
  925. if(this->AllSections.find(section) == this->AllSections.end())
  926. {
  927. os << "Internal error: " << section << " list is empty." << std::endl;
  928. return false;
  929. }
  930. if(this->CurrentArgument.length() == 0)
  931. {
  932. os << "Required argument missing.\n";
  933. return false;
  934. }
  935. const std::vector<cmDocumentationEntry> &entries =
  936. this->AllSections[section]->GetEntries();
  937. for(std::vector<cmDocumentationEntry>::const_iterator ei =
  938. entries.begin();
  939. ei != entries.end(); ++ei)
  940. {
  941. if(this->CurrentArgument == ei->Name)
  942. {
  943. this->PrintDocumentationCommand(os, *ei);
  944. return true;
  945. }
  946. }
  947. return false;
  948. }
  949. //----------------------------------------------------------------------------
  950. bool cmDocumentation::PrintDocumentationSingle(std::ostream& os)
  951. {
  952. if (this->PrintDocumentationGeneric(os,"Commands"))
  953. {
  954. return true;
  955. }
  956. if (this->PrintDocumentationGeneric(os,"Compatibility Commands"))
  957. {
  958. return true;
  959. }
  960. // Argument was not a command. Complain.
  961. os << "Argument \"" << this->CurrentArgument.c_str()
  962. << "\" to --help-command is not a CMake command. "
  963. << "Use --help-command-list to see all commands.\n";
  964. return false;
  965. }
  966. //----------------------------------------------------------------------------
  967. bool cmDocumentation::PrintDocumentationSingleModule(std::ostream& os)
  968. {
  969. if(this->CurrentArgument.length() == 0)
  970. {
  971. os << "Argument --help-module needs a module name.\n";
  972. return false;
  973. }
  974. std::string moduleName;
  975. // find the module
  976. std::vector<std::string> dirs;
  977. cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
  978. for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
  979. dirIt != dirs.end();
  980. ++dirIt)
  981. {
  982. moduleName = *dirIt;
  983. moduleName += "/";
  984. moduleName += this->CurrentArgument;
  985. moduleName += ".cmake";
  986. if(cmSystemTools::FileExists(moduleName.c_str()))
  987. {
  988. break;
  989. }
  990. moduleName = "";
  991. }
  992. if (moduleName.empty())
  993. {
  994. moduleName = this->CMakeRoot;
  995. moduleName += "/Modules/";
  996. moduleName += this->CurrentArgument;
  997. moduleName += ".cmake";
  998. if(!cmSystemTools::FileExists(moduleName.c_str()))
  999. {
  1000. moduleName = "";
  1001. }
  1002. }
  1003. if(!moduleName.empty())
  1004. {
  1005. cmDocumentationSection *sec =
  1006. new cmDocumentationSection("Standard CMake Modules", "MODULES");
  1007. this->AllSections["Modules"] = sec;
  1008. if (this->CreateSingleModule(moduleName.c_str(),
  1009. this->CurrentArgument.c_str(),
  1010. *this->AllSections["Modules"]))
  1011. {
  1012. this->PrintDocumentationCommand
  1013. (os, this->AllSections["Modules"]->GetEntries()[0]);
  1014. os << "\n Defined in: ";
  1015. os << moduleName << "\n";
  1016. return true;
  1017. }
  1018. }
  1019. // Argument was not a module. Complain.
  1020. os << "Argument \"" << this->CurrentArgument.c_str()
  1021. << "\" to --help-module is not a CMake module.\n";
  1022. return false;
  1023. }
  1024. //----------------------------------------------------------------------------
  1025. bool cmDocumentation::PrintDocumentationSingleProperty(std::ostream& os)
  1026. {
  1027. bool done = false;
  1028. for (std::vector<std::string>::iterator i =
  1029. this->PropertySections.begin();
  1030. !done && i != this->PropertySections.end(); ++i)
  1031. {
  1032. done = this->PrintDocumentationGeneric(os,i->c_str());
  1033. }
  1034. if (done)
  1035. {
  1036. return true;
  1037. }
  1038. // Argument was not a command. Complain.
  1039. os << "Argument \"" << this->CurrentArgument.c_str()
  1040. << "\" to --help-property is not a CMake property. "
  1041. << "Use --help-property-list to see all properties.\n";
  1042. return false;
  1043. }
  1044. //----------------------------------------------------------------------------
  1045. bool cmDocumentation::PrintDocumentationSingleVariable(std::ostream& os)
  1046. {
  1047. bool done = false;
  1048. for (std::vector<std::string>::iterator i =
  1049. this->VariableSections.begin();
  1050. !done && i != this->VariableSections.end(); ++i)
  1051. {
  1052. done = this->PrintDocumentationGeneric(os,i->c_str());
  1053. }
  1054. if (done)
  1055. {
  1056. return true;
  1057. }
  1058. // Argument was not a command. Complain.
  1059. os << "Argument \"" << this->CurrentArgument.c_str()
  1060. << "\" to --help-variable is not a defined variable. "
  1061. << "Use --help-variable-list to see all defined variables.\n";
  1062. return false;
  1063. }
  1064. //----------------------------------------------------------------------------
  1065. bool cmDocumentation::PrintDocumentationList(std::ostream& os,
  1066. const char *section)
  1067. {
  1068. if(this->AllSections.find(section) == this->AllSections.end())
  1069. {
  1070. os << "Internal error: " << section << " list is empty." << std::endl;
  1071. return false;
  1072. }
  1073. const std::vector<cmDocumentationEntry> &entries =
  1074. this->AllSections[section]->GetEntries();
  1075. for(std::vector<cmDocumentationEntry>::const_iterator ei =
  1076. entries.begin();
  1077. ei != entries.end(); ++ei)
  1078. {
  1079. if(ei->Name.size())
  1080. {
  1081. os << ei->Name << std::endl;
  1082. }
  1083. }
  1084. return true;
  1085. }
  1086. //----------------------------------------------------------------------------
  1087. bool cmDocumentation::PrintDocumentationUsage(std::ostream& os)
  1088. {
  1089. this->ClearSections();
  1090. this->AddSectionToPrint("Usage");
  1091. this->AddSectionToPrint("Options");
  1092. this->AddSectionToPrint("Generators");
  1093. this->Print(os);
  1094. return true;
  1095. }
  1096. //----------------------------------------------------------------------------
  1097. bool cmDocumentation::PrintDocumentationFull(std::ostream& os)
  1098. {
  1099. this->CreateFullDocumentation();
  1100. this->CurrentFormatter->PrintHeader(GetNameString(), os);
  1101. this->Print(os);
  1102. this->CurrentFormatter->PrintFooter(os);
  1103. return true;
  1104. }
  1105. //----------------------------------------------------------------------------
  1106. bool cmDocumentation::PrintDocumentationModules(std::ostream& os)
  1107. {
  1108. this->ClearSections();
  1109. this->CreateModulesSection();
  1110. this->AddSectionToPrint("Description");
  1111. this->AddSectionToPrint("Modules");
  1112. this->AddSectionToPrint("Copyright");
  1113. this->AddSectionToPrint("See Also");
  1114. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1115. this->Print(os);
  1116. this->CurrentFormatter->PrintFooter(os);
  1117. return true;
  1118. }
  1119. //----------------------------------------------------------------------------
  1120. bool cmDocumentation::PrintDocumentationCustomModules(std::ostream& os)
  1121. {
  1122. this->ClearSections();
  1123. this->CreateCustomModulesSection();
  1124. this->AddSectionToPrint("Description");
  1125. this->AddSectionToPrint("Custom CMake Modules");
  1126. this->AddSectionToPrint("Copyright");
  1127. this->AddSectionToPrint("See Also");
  1128. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1129. this->Print(os);
  1130. this->CurrentFormatter->PrintFooter(os);
  1131. return true;
  1132. }
  1133. //----------------------------------------------------------------------------
  1134. bool cmDocumentation::PrintDocumentationProperties(std::ostream& os)
  1135. {
  1136. this->ClearSections();
  1137. this->AddSectionToPrint("Properties Description");
  1138. for (std::vector<std::string>::iterator i =
  1139. this->PropertySections.begin();
  1140. i != this->PropertySections.end(); ++i)
  1141. {
  1142. this->AddSectionToPrint(i->c_str());
  1143. }
  1144. this->AddSectionToPrint("Copyright");
  1145. this->AddSectionToPrint("Standard See Also");
  1146. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1147. this->Print(os);
  1148. this->CurrentFormatter->PrintFooter(os);
  1149. return true;
  1150. }
  1151. //----------------------------------------------------------------------------
  1152. bool cmDocumentation::PrintDocumentationVariables(std::ostream& os)
  1153. {
  1154. this->ClearSections();
  1155. for (std::vector<std::string>::iterator i =
  1156. this->VariableSections.begin();
  1157. i != this->VariableSections.end(); ++i)
  1158. {
  1159. this->AddSectionToPrint(i->c_str());
  1160. }
  1161. this->AddSectionToPrint("Copyright");
  1162. this->AddSectionToPrint("Standard See Also");
  1163. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1164. this->Print(os);
  1165. this->CurrentFormatter->PrintFooter(os);
  1166. return true;
  1167. }
  1168. //----------------------------------------------------------------------------
  1169. bool cmDocumentation::PrintDocumentationCurrentCommands(std::ostream& os)
  1170. {
  1171. this->ClearSections();
  1172. this->AddSectionToPrint("Commands");
  1173. this->AddSectionToPrint("Copyright");
  1174. this->AddSectionToPrint("Standard See Also");
  1175. this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
  1176. this->Print(os);
  1177. this->CurrentFormatter->PrintFooter(os);
  1178. return true;
  1179. }
  1180. //----------------------------------------------------------------------------
  1181. bool cmDocumentation::PrintDocumentationCompatCommands(std::ostream& os)
  1182. {
  1183. this->ClearSections();
  1184. this->AddSectionToPrint("Compatibility Commands Description");
  1185. this->AddSectionToPrint("Compatibility Commands");
  1186. this->AddSectionToPrint("Copyright");
  1187. this->AddSectionToPrint("Standard See Also");
  1188. this->CurrentFormatter->PrintHeader(GetNameString(), os);
  1189. this->Print(os);
  1190. this->CurrentFormatter->PrintFooter(os);
  1191. return true;
  1192. }
  1193. //----------------------------------------------------------------------------
  1194. void cmDocumentation
  1195. ::PrintDocumentationCommand(std::ostream& os,
  1196. const cmDocumentationEntry &entry)
  1197. {
  1198. cmDocumentationSection *sec = new cmDocumentationSection("","");
  1199. sec->Append(entry);
  1200. this->AllSections["temp"] = sec;
  1201. this->ClearSections();
  1202. this->AddSectionToPrint("temp");
  1203. this->Print(os);
  1204. this->AllSections.erase("temp");
  1205. delete sec;
  1206. }
  1207. //----------------------------------------------------------------------------
  1208. void cmDocumentation::CreateFullDocumentation()
  1209. {
  1210. this->ClearSections();
  1211. this->CreateCustomModulesSection();
  1212. this->CreateModulesSection();
  1213. std::set<std::string> emitted;
  1214. this->AddSectionToPrint("Name");
  1215. emitted.insert("Name");
  1216. this->AddSectionToPrint("Usage");
  1217. emitted.insert("Usage");
  1218. this->AddSectionToPrint("Description");
  1219. emitted.insert("Description");
  1220. this->AddSectionToPrint("Options");
  1221. emitted.insert("Options");
  1222. this->AddSectionToPrint("Generators");
  1223. emitted.insert("Generators");
  1224. this->AddSectionToPrint("Commands");
  1225. emitted.insert("Commands");
  1226. this->AddSectionToPrint("Properties Description");
  1227. emitted.insert("Properties Description");
  1228. for (std::vector<std::string>::iterator i =
  1229. this->PropertySections.begin();
  1230. i != this->PropertySections.end(); ++i)
  1231. {
  1232. this->AddSectionToPrint(i->c_str());
  1233. emitted.insert(i->c_str());
  1234. }
  1235. emitted.insert("Copyright");
  1236. emitted.insert("See Also");
  1237. emitted.insert("Standard See Also");
  1238. emitted.insert("Author");
  1239. // add any sections not yet written out, or to be written out
  1240. for (std::map<std::string, cmDocumentationSection*>::iterator i =
  1241. this->AllSections.begin();
  1242. i != this->AllSections.end(); ++i)
  1243. {
  1244. if (emitted.find(i->first) == emitted.end())
  1245. {
  1246. this->AddSectionToPrint(i->first.c_str());
  1247. }
  1248. }
  1249. this->AddSectionToPrint("Copyright");
  1250. if(this->CurrentFormatter->GetForm() == ManForm)
  1251. {
  1252. this->AddSectionToPrint("See Also");
  1253. this->AddSectionToPrint("Author");
  1254. }
  1255. else
  1256. {
  1257. this->AddSectionToPrint("Standard See Also");
  1258. }
  1259. }
  1260. //----------------------------------------------------------------------------
  1261. void cmDocumentation::SetForm(Form f)
  1262. {
  1263. switch(f)
  1264. {
  1265. case HTMLForm:
  1266. this->CurrentFormatter = &this->HTMLFormatter;
  1267. break;
  1268. case ManForm:
  1269. this->CurrentFormatter = &this->ManFormatter;
  1270. break;
  1271. case TextForm:
  1272. this->CurrentFormatter = &this->TextFormatter;
  1273. break;
  1274. case UsageForm:
  1275. this->CurrentFormatter = & this->UsageFormatter;
  1276. break;
  1277. }
  1278. }
  1279. //----------------------------------------------------------------------------
  1280. const char* cmDocumentation::GetNameString() const
  1281. {
  1282. if(this->NameString.length() > 0)
  1283. {
  1284. return this->NameString.c_str();
  1285. }
  1286. else
  1287. {
  1288. return "CMake";
  1289. }
  1290. }
  1291. //----------------------------------------------------------------------------
  1292. bool cmDocumentation::IsOption(const char* arg) const
  1293. {
  1294. return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
  1295. (strcmp(arg, "/?") == 0));
  1296. }