cmDocumentation.cxx 51 KB

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