cmDocumentation.cxx 47 KB

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