cmDocumentation.cxx 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  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. #include <cmsys/Glob.hxx>
  15. #include <algorithm>
  16. //----------------------------------------------------------------------------
  17. static const char *cmDocumentationStandardOptions[][3] =
  18. {
  19. {"--copyright [file]", "Print the CMake copyright and exit.",
  20. "If a file is specified, the copyright is written into it."},
  21. {"--help,-help,-usage,-h,-H,/?", "Print usage information and exit.",
  22. "Usage describes the basic command line interface and its options."},
  23. {"--help-full [file]", "Print full help and exit.",
  24. "Full help displays most of the documentation provided by the UNIX "
  25. "man page. It is provided for use on non-UNIX platforms, but is "
  26. "also convenient if the man page is not installed. If a file is "
  27. "specified, the help is written into it."},
  28. {"--help-html [file]", "Print full help in HTML format.",
  29. "This option is used by CMake authors to help produce web pages. "
  30. "If a file is specified, the help is written into it."},
  31. {"--help-man [file]", "Print full help as a UNIX man page and exit.",
  32. "This option is used by the cmake build to generate the UNIX man page. "
  33. "If a file is specified, the help is written into it."},
  34. {"--version,-version,/V [file]",
  35. "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 2000-2009 Kitware, Inc., Insight Software 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. "Neither the names of Kitware, Inc., the Insight Software Consortium, "
  167. "nor the names of their contributors may be used to endorse or promote "
  168. "products derived from this software without specific prior written "
  169. "permission.", 0},
  170. {0,
  171. "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "
  172. "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "
  173. "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR "
  174. "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT "
  175. "HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, "
  176. "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT "
  177. "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, "
  178. "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY "
  179. "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT "
  180. "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE "
  181. "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
  182. 0},
  183. {0, 0, 0}
  184. };
  185. //----------------------------------------------------------------------------
  186. #define DOCUMENT_INTRO(type, default_name, desc) \
  187. static char const *cmDocumentation##type##Intro[2] = { default_name, desc };
  188. #define GET_DOCUMENT_INTRO(type) cmDocumentation##type##Intro
  189. DOCUMENT_INTRO(Modules, "cmakemodules",
  190. "Reference of available CMake modules.");
  191. DOCUMENT_INTRO(CustomModules, "cmakecustommodules",
  192. "Reference of available CMake custom modules.");
  193. DOCUMENT_INTRO(Policies, "cmakepolicies",
  194. "Reference of CMake policies.");
  195. DOCUMENT_INTRO(Properties, "cmakeprops",
  196. "Reference of CMake properties.");
  197. DOCUMENT_INTRO(Variables, "cmakevars",
  198. "Reference of CMake variables.");
  199. DOCUMENT_INTRO(Commands, "cmakecommands",
  200. "Reference of available CMake commands.");
  201. DOCUMENT_INTRO(CompatCommands, "cmakecompat",
  202. "Reference of CMake compatibility commands.");
  203. //----------------------------------------------------------------------------
  204. cmDocumentation::cmDocumentation()
  205. :CurrentFormatter(0)
  206. {
  207. this->SetForm(TextForm);
  208. this->addCommonStandardDocSections();
  209. this->ShowGenerators = true;
  210. }
  211. //----------------------------------------------------------------------------
  212. cmDocumentation::~cmDocumentation()
  213. {
  214. for(std::vector< char* >::iterator i = this->ModuleStrings.begin();
  215. i != this->ModuleStrings.end(); ++i)
  216. {
  217. delete [] *i;
  218. }
  219. for(std::map<std::string,cmDocumentationSection *>::iterator i =
  220. this->AllSections.begin();
  221. i != this->AllSections.end(); ++i)
  222. {
  223. delete i->second;
  224. }
  225. }
  226. //----------------------------------------------------------------------------
  227. bool cmDocumentation::PrintCopyright(std::ostream& os)
  228. {
  229. cmDocumentationSection *sec = this->AllSections["Copyright"];
  230. const std::vector<cmDocumentationEntry> &entries = sec->GetEntries();
  231. for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
  232. op != entries.end(); ++op)
  233. {
  234. if(op->Name.size())
  235. {
  236. os << " * ";
  237. this->TextFormatter.SetIndent(" ");
  238. this->TextFormatter.PrintColumn(os, op->Brief.c_str());
  239. }
  240. else
  241. {
  242. this->TextFormatter.SetIndent("");
  243. this->TextFormatter.PrintColumn(os, op->Brief.c_str());
  244. }
  245. os << "\n";
  246. }
  247. return true;
  248. }
  249. //----------------------------------------------------------------------------
  250. bool cmDocumentation::PrintVersion(std::ostream& os)
  251. {
  252. os << this->GetNameString() << " version "
  253. << cmVersion::GetCMakeVersion() << "\n";
  254. return true;
  255. }
  256. //----------------------------------------------------------------------------
  257. void cmDocumentation::AddSectionToPrint(const char *section)
  258. {
  259. if (this->AllSections.find(section) != this->AllSections.end())
  260. {
  261. this->PrintSections.push_back(this->AllSections[section]);
  262. }
  263. }
  264. //----------------------------------------------------------------------------
  265. void cmDocumentation::ClearSections()
  266. {
  267. this->PrintSections.erase(this->PrintSections.begin(),
  268. this->PrintSections.end());
  269. this->ModulesFound.clear();
  270. }
  271. //----------------------------------------------------------------------------
  272. void cmDocumentation::AddDocumentIntroToPrint(const char* intro[2])
  273. {
  274. const char* docname = this->GetDocName(false);
  275. if(intro && docname)
  276. {
  277. cmDocumentationSection* section;
  278. std::string desc("");
  279. desc += docname;
  280. desc += " - ";
  281. desc += intro[1];
  282. section = new cmDocumentationSection("Introduction", "NAME");
  283. section->Append(0, desc.c_str(), 0);
  284. this->PrintSections.push_back(section);
  285. }
  286. }
  287. //----------------------------------------------------------------------------
  288. bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os,
  289. const char* docname)
  290. {
  291. if ((this->CurrentFormatter->GetForm() != HTMLForm)
  292. && (this->CurrentFormatter->GetForm() != DocbookForm)
  293. && (this->CurrentFormatter->GetForm() != ManForm))
  294. {
  295. this->PrintVersion(os);
  296. }
  297. // Handle Document Name. docname==0 disables intro.
  298. this->SetDocName("");
  299. if (docname)
  300. {
  301. if (*docname)
  302. this->SetDocName(docname);
  303. else // empty string was given. select default if possible
  304. this->SetDocName(this->GetDefaultDocName(ht));
  305. }
  306. switch (ht)
  307. {
  308. case cmDocumentation::Usage:
  309. return this->PrintDocumentationUsage(os);
  310. case cmDocumentation::Single:
  311. return this->PrintDocumentationSingle(os);
  312. case cmDocumentation::SingleModule:
  313. return this->PrintDocumentationSingleModule(os);
  314. case cmDocumentation::SinglePolicy:
  315. return this->PrintDocumentationSinglePolicy(os);
  316. case cmDocumentation::SingleProperty:
  317. return this->PrintDocumentationSingleProperty(os);
  318. case cmDocumentation::SingleVariable:
  319. return this->PrintDocumentationSingleVariable(os);
  320. case cmDocumentation::List:
  321. this->PrintDocumentationList(os,"Commands");
  322. this->PrintDocumentationList(os,"Compatibility Commands");
  323. return true;
  324. case cmDocumentation::ModuleList:
  325. // find the modules first, print the custom module docs only if
  326. // any custom modules have been found actually, Alex
  327. this->CreateCustomModulesSection();
  328. this->CreateModulesSection();
  329. if (this->AllSections.find("Custom CMake Modules")
  330. != this->AllSections.end())
  331. {
  332. this->PrintDocumentationList(os,"Custom CMake Modules");
  333. }
  334. this->PrintDocumentationList(os,"Modules");
  335. return true;
  336. case cmDocumentation::PropertyList:
  337. this->PrintDocumentationList(os,"Properties Description");
  338. for (std::vector<std::string>::iterator i =
  339. this->PropertySections.begin();
  340. i != this->PropertySections.end(); ++i)
  341. {
  342. this->PrintDocumentationList(os,i->c_str());
  343. }
  344. return true;
  345. case cmDocumentation::VariableList:
  346. for (std::vector<std::string>::iterator i =
  347. this->VariableSections.begin();
  348. i != this->VariableSections.end(); ++i)
  349. {
  350. this->PrintDocumentationList(os,i->c_str());
  351. }
  352. return true;
  353. case cmDocumentation::Full:
  354. return this->PrintDocumentationFull(os);
  355. case cmDocumentation::Modules:
  356. return this->PrintDocumentationModules(os);
  357. case cmDocumentation::CustomModules:
  358. return this->PrintDocumentationCustomModules(os);
  359. case cmDocumentation::Policies:
  360. return this->PrintDocumentationPolicies(os);
  361. case cmDocumentation::Properties:
  362. return this->PrintDocumentationProperties(os);
  363. case cmDocumentation::Variables:
  364. return this->PrintDocumentationVariables(os);
  365. case cmDocumentation::Commands:
  366. return this->PrintDocumentationCurrentCommands(os);
  367. case cmDocumentation::CompatCommands:
  368. return this->PrintDocumentationCompatCommands(os);
  369. case cmDocumentation::Copyright:
  370. return this->PrintCopyright(os);
  371. case cmDocumentation::Version:
  372. return true;
  373. default: return false;
  374. }
  375. }
  376. //----------------------------------------------------------------------------
  377. bool cmDocumentation::CreateModulesSection()
  378. {
  379. cmDocumentationSection *sec =
  380. new cmDocumentationSection("Standard CMake Modules", "MODULES");
  381. this->AllSections["Modules"] = sec;
  382. std::string cmakeModules = this->CMakeRoot;
  383. cmakeModules += "/Modules";
  384. cmsys::Directory dir;
  385. dir.Load(cmakeModules.c_str());
  386. if (dir.GetNumberOfFiles() > 0)
  387. {
  388. sec->Append(cmDocumentationModulesHeader[0]);
  389. sec->Append(cmModulesDocumentationDescription);
  390. this->CreateModuleDocsForDir(dir, *this->AllSections["Modules"]);
  391. }
  392. return true;
  393. }
  394. //----------------------------------------------------------------------------
  395. bool cmDocumentation::CreateCustomModulesSection()
  396. {
  397. bool sectionHasHeader = false;
  398. std::vector<std::string> dirs;
  399. cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
  400. for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
  401. dirIt != dirs.end();
  402. ++dirIt)
  403. {
  404. cmsys::Directory dir;
  405. dir.Load(dirIt->c_str());
  406. if (dir.GetNumberOfFiles() > 0)
  407. {
  408. if (!sectionHasHeader)
  409. {
  410. cmDocumentationSection *sec =
  411. new cmDocumentationSection("Custom CMake Modules","CUSTOM MODULES");
  412. this->AllSections["Custom CMake Modules"] = sec;
  413. sec->Append(cmDocumentationCustomModulesHeader[0]);
  414. sec->Append(cmCustomModulesDocumentationDescription);
  415. sectionHasHeader = true;
  416. }
  417. this->CreateModuleDocsForDir
  418. (dir, *this->AllSections["Custom CMake Modules"]);
  419. }
  420. }
  421. return true;
  422. }
  423. //----------------------------------------------------------------------------
  424. void cmDocumentation
  425. ::CreateModuleDocsForDir(cmsys::Directory& dir,
  426. cmDocumentationSection &moduleSection)
  427. {
  428. // sort the files alphabetically, so the docs for one module are easier
  429. // to find than if they are in random order
  430. std::vector<std::string> sortedFiles;
  431. for(unsigned int i = 0; i < dir.GetNumberOfFiles(); ++i)
  432. {
  433. sortedFiles.push_back(dir.GetFile(i));
  434. }
  435. std::sort(sortedFiles.begin(), sortedFiles.end());
  436. for(std::vector<std::string>::const_iterator fname = sortedFiles.begin();
  437. fname!=sortedFiles.end(); ++fname)
  438. {
  439. if(fname->length() > 6)
  440. {
  441. if(fname->substr(fname->length()-6, 6) == ".cmake")
  442. {
  443. std::string moduleName = fname->substr(0, fname->length()-6);
  444. // this check is to avoid creating documentation for the modules with
  445. // the same name in multiple directories of CMAKE_MODULE_PATH
  446. if (this->ModulesFound.find(moduleName) == this->ModulesFound.end())
  447. {
  448. this->ModulesFound.insert(moduleName);
  449. std::string path = dir.GetPath();
  450. path += "/";
  451. path += (*fname);
  452. this->CreateSingleModule(path.c_str(), moduleName.c_str(),
  453. moduleSection);
  454. }
  455. }
  456. }
  457. }
  458. }
  459. //----------------------------------------------------------------------------
  460. bool cmDocumentation::CreateSingleModule(const char* fname,
  461. const char* moduleName,
  462. cmDocumentationSection &moduleSection)
  463. {
  464. std::ifstream fin(fname);
  465. if(!fin)
  466. {
  467. std::cerr << "Internal error: can not open module." << fname << std::endl;
  468. return false;
  469. }
  470. std::string line;
  471. std::string text;
  472. std::string brief;
  473. brief = " ";
  474. bool newParagraph = true;
  475. while ( fin && cmSystemTools::GetLineFromStream(fin, line) )
  476. {
  477. if(line.size() && line[0] == '#')
  478. {
  479. /* line beginnings with ## are mark-up ignore them */
  480. if (line.size()>=2 && line[1] == '#') continue;
  481. // blank line
  482. if(line.size() <= 2)
  483. {
  484. text += "\n";
  485. newParagraph = true;
  486. }
  487. else if(line[2] == '-')
  488. {
  489. brief = line.c_str()+4;
  490. }
  491. else
  492. {
  493. // two spaces
  494. if(line[1] == ' ' && line[2] == ' ')
  495. {
  496. if(!newParagraph)
  497. {
  498. text += "\n";
  499. newParagraph = true;
  500. }
  501. // Skip #, and leave space for preformatted
  502. text += line.c_str()+1;
  503. text += "\n";
  504. }
  505. else if(line[1] == ' ')
  506. {
  507. if(!newParagraph)
  508. {
  509. text += " ";
  510. }
  511. newParagraph = false;
  512. // skip # and space
  513. text += line.c_str()+2;
  514. }
  515. else
  516. {
  517. if(!newParagraph)
  518. {
  519. text += " ";
  520. }
  521. newParagraph = false;
  522. // skip #
  523. text += line.c_str()+1;
  524. }
  525. }
  526. }
  527. else
  528. {
  529. break;
  530. }
  531. }
  532. if(text.length() < 2 && brief.length() == 1)
  533. {
  534. return false;
  535. }
  536. char* pname = strcpy(new char[strlen(moduleName)+1], moduleName);
  537. char* ptext = strcpy(new char[text.length()+1], text.c_str());
  538. this->ModuleStrings.push_back(pname);
  539. this->ModuleStrings.push_back(ptext);
  540. char* pbrief = strcpy(new char[brief.length()+1], brief.c_str());
  541. this->ModuleStrings.push_back(pbrief);
  542. moduleSection.Append(pname, pbrief, ptext);
  543. return true;
  544. }
  545. //----------------------------------------------------------------------------
  546. bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
  547. {
  548. bool result = true;
  549. // Loop over requested documentation types.
  550. for(std::vector<RequestedHelpItem>::const_iterator
  551. i = this->RequestedHelpItems.begin();
  552. i != this->RequestedHelpItems.end();
  553. ++i)
  554. {
  555. this->SetForm(i->HelpForm);
  556. this->CurrentArgument = i->Argument;
  557. // If a file name was given, use it. Otherwise, default to the
  558. // given stream.
  559. std::ofstream* fout = 0;
  560. std::ostream* s = &os;
  561. std::string docname("");
  562. if(i->Filename.length() > 0)
  563. {
  564. fout = new std::ofstream(i->Filename.c_str(), std::ios::out);
  565. if(fout)
  566. {
  567. s = fout;
  568. }
  569. else
  570. {
  571. result = false;
  572. }
  573. if(i->Filename != "-")
  574. {
  575. docname = cmSystemTools::GetFilenameWithoutLastExtension(i->Filename);
  576. }
  577. }
  578. // Print this documentation type to the stream.
  579. if(!this->PrintDocumentation(i->HelpType, *s, docname.c_str()) || !*s)
  580. {
  581. result = false;
  582. }
  583. // Close the file if we wrote one.
  584. if(fout)
  585. {
  586. delete fout;
  587. }
  588. }
  589. return result;
  590. }
  591. #define GET_OPT_ARGUMENT(target) \
  592. if((i+1 < argc) && !this->IsOption(argv[i+1])) \
  593. { \
  594. target = argv[i+1]; \
  595. i = i+1; \
  596. };
  597. cmDocumentation::Form cmDocumentation::GetFormFromFilename(
  598. const std::string& filename)
  599. {
  600. std::string ext = cmSystemTools::GetFilenameLastExtension(filename);
  601. ext = cmSystemTools::UpperCase(ext);
  602. if ((ext == ".HTM") || (ext == ".HTML"))
  603. {
  604. return cmDocumentation::HTMLForm;
  605. }
  606. if (ext == ".DOCBOOK")
  607. {
  608. return cmDocumentation::DocbookForm;
  609. }
  610. // ".1" to ".9" should be manpages
  611. if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
  612. {
  613. return cmDocumentation::ManForm;
  614. }
  615. return cmDocumentation::TextForm;
  616. }
  617. //----------------------------------------------------------------------------
  618. void cmDocumentation::addCommonStandardDocSections()
  619. {
  620. cmDocumentationSection *sec;
  621. sec = new cmDocumentationSection("Author","AUTHOR");
  622. sec->Append(cmDocumentationEntry
  623. (0,
  624. "This manual page was generated by the \"--help-man\" option.",
  625. 0));
  626. this->AllSections["Author"] = sec;
  627. sec = new cmDocumentationSection("Copyright","COPYRIGHT");
  628. sec->Append(cmDocumentationCopyright);
  629. this->AllSections["Copyright"] = sec;
  630. sec = new cmDocumentationSection("See Also","SEE ALSO");
  631. sec->Append(cmDocumentationStandardSeeAlso);
  632. this->AllSections["Standard See Also"] = sec;
  633. sec = new cmDocumentationSection("Options","OPTIONS");
  634. sec->Append(cmDocumentationStandardOptions);
  635. this->AllSections["Options"] = sec;
  636. sec = new cmDocumentationSection("Compatibility Commands",
  637. "COMPATIBILITY COMMANDS");
  638. sec->Append(cmCompatCommandsDocumentationDescription);
  639. this->AllSections["Compatibility Commands"] = sec;
  640. }
  641. //----------------------------------------------------------------------------
  642. void cmDocumentation::addCMakeStandardDocSections()
  643. {
  644. cmDocumentationSection *sec;
  645. sec = new cmDocumentationSection("Properties","PROPERTIES");
  646. sec->Append(cmPropertiesDocumentationDescription);
  647. this->AllSections["Properties Description"] = sec;
  648. sec = new cmDocumentationSection("Generators","GENERATORS");
  649. sec->Append(cmDocumentationGeneratorsHeader);
  650. this->AllSections["Generators"] = sec;
  651. this->PropertySections.push_back("Properties of Global Scope");
  652. this->PropertySections.push_back("Properties on Directories");
  653. this->PropertySections.push_back("Properties on Targets");
  654. this->PropertySections.push_back("Properties on Tests");
  655. this->PropertySections.push_back("Properties on Source Files");
  656. this->PropertySections.push_back("Properties on Cache Entries");
  657. this->VariableSections.push_back("Variables that Provide Information");
  658. this->VariableSections.push_back("Variables That Change Behavior");
  659. this->VariableSections.push_back("Variables That Describe the System");
  660. this->VariableSections.push_back("Variables that Control the Build");
  661. this->VariableSections.push_back("Variables for Languages");
  662. }
  663. //----------------------------------------------------------------------------
  664. void cmDocumentation::addCTestStandardDocSections()
  665. {
  666. // This is currently done for backward compatibility reason
  667. // We may suppress some of these.
  668. addCMakeStandardDocSections();
  669. }
  670. //----------------------------------------------------------------------------
  671. void cmDocumentation::addCPackStandardDocSections()
  672. {
  673. cmDocumentationSection *sec;
  674. sec = new cmDocumentationSection("Generators","GENERATORS");
  675. sec->Append(cmDocumentationGeneratorsHeader);
  676. this->AllSections["Generators"] = sec;
  677. this->VariableSections.push_back(
  678. "Variables common to all CPack generators");
  679. }
  680. void cmDocumentation::addAutomaticVariableSections(const std::string& section)
  681. {
  682. std::vector<std::string>::iterator it;
  683. it = std::find(this->VariableSections.begin(),
  684. this->VariableSections.end(),
  685. section);
  686. /* if the section does not exist then add it */
  687. if (it==this->VariableSections.end())
  688. {
  689. this->VariableSections.push_back(section);
  690. }
  691. }
  692. //----------------------------------------------------------------------------
  693. int cmDocumentation::getDocumentedModulesListInDir(
  694. std::string path,
  695. std::string globExpr,
  696. documentedModulesList_t& docedModuleList)
  697. {
  698. cmsys::Glob gl;
  699. std::string findExpr;
  700. std::vector<std::string> files;
  701. std::string line;
  702. documentedModuleSectionPair_t docPair;
  703. int nbDocumentedModules = 0;
  704. findExpr = path + "/" + globExpr;
  705. if (gl.FindFiles(findExpr))
  706. {
  707. files = gl.GetFiles();
  708. for (std::vector<std::string>::iterator itf=files.begin();
  709. itf!=files.end();++itf)
  710. {
  711. std::ifstream fin((*itf).c_str());
  712. // file access trouble ignore it (ignore this kind of error)
  713. if (!fin) continue;
  714. /* read first line in order to get doc section */
  715. if (cmSystemTools::GetLineFromStream(fin, line))
  716. {
  717. /* Doc section indicates that
  718. * this file has structured doc in it.
  719. */
  720. if (line.find("##section")!=std::string::npos)
  721. {
  722. // ok found one more documented module
  723. ++nbDocumentedModules;
  724. docPair.first = *itf;
  725. // 10 is the size of '##section' + 1
  726. docPair.second = line.substr(10,std::string::npos);
  727. docedModuleList.push_back(docPair);
  728. }
  729. // No else if no section is found (undocumented module)
  730. }
  731. // No else cannot read first line (ignore this kind of error)
  732. line = "";
  733. }
  734. }
  735. if (nbDocumentedModules>0)
  736. {
  737. return 0;
  738. }
  739. else
  740. {
  741. return 1;
  742. }
  743. }
  744. //----------------------------------------------------------------------------
  745. static void trim(std::string& s)
  746. {
  747. std::string::size_type pos = s.find_last_not_of(' ');
  748. if(pos != std::string::npos)
  749. {
  750. s.erase(pos + 1);
  751. pos = s.find_first_not_of(' ');
  752. if(pos != std::string::npos) s.erase(0, pos);
  753. }
  754. else
  755. {
  756. s.erase(s.begin(), s.end());
  757. }
  758. }
  759. int cmDocumentation::GetStructuredDocFromFile(
  760. const char* fname,
  761. std::vector<cmDocumentationEntry>& commands,
  762. cmake* cm)
  763. {
  764. typedef enum sdoce {
  765. SDOC_NONE, SDOC_MODULE, SDOC_MACRO, SDOC_FUNCTION, SDOC_VARIABLE,
  766. SDOC_SECTION,
  767. SDOC_UNKNOWN} sdoc_t;
  768. int nbDocItemFound = 0;
  769. int docCtxIdx = 0;
  770. std::vector<int> docContextStack(60);
  771. docContextStack[docCtxIdx]=SDOC_NONE;
  772. cmDocumentationEntry e;
  773. std::ifstream fin(fname);
  774. if(!fin)
  775. {
  776. return nbDocItemFound;
  777. }
  778. std::string section;
  779. std::string name;
  780. std::string full;
  781. std::string brief;
  782. std::string line;
  783. bool newCtx = false; /* we've just entered ##<beginkey> context */
  784. bool inBrief = false; /* we are currently parsing brief desc. */
  785. bool inFullFirstParagraph = false; /* we are currently parsing full
  786. desc. first paragraph */
  787. brief = "";
  788. full = "";
  789. bool newParagraph = true;
  790. while ( fin && cmSystemTools::GetLineFromStream(fin, line) )
  791. {
  792. if(line.size() && line[0] == '#')
  793. {
  794. /* handle structured doc context */
  795. if ((line.size()>=2) && line[1]=='#')
  796. {
  797. /* markup word is following '##' stopping at first space
  798. * Some markup word like 'section' may have more characters
  799. * following but we don't handle those here.
  800. */
  801. std::string mkword = line.substr(2,line.find(' ',2)-2);
  802. if (mkword=="macro")
  803. {
  804. docCtxIdx++;
  805. docContextStack[docCtxIdx]=SDOC_MACRO;
  806. newCtx = true;
  807. }
  808. else if (mkword=="variable")
  809. {
  810. docCtxIdx++;
  811. docContextStack[docCtxIdx]=SDOC_VARIABLE;
  812. newCtx = true;
  813. }
  814. else if (mkword=="function")
  815. {
  816. docCtxIdx++;
  817. docContextStack[docCtxIdx]=SDOC_FUNCTION;
  818. newCtx = true;
  819. }
  820. else if (mkword=="module")
  821. {
  822. docCtxIdx++;
  823. docContextStack[docCtxIdx]=SDOC_MODULE;
  824. newCtx = true;
  825. }
  826. else if (mkword=="section")
  827. {
  828. docCtxIdx++;
  829. docContextStack[docCtxIdx]=SDOC_SECTION;
  830. // 10 is the size of '##section' + 1
  831. section = line.substr(10,std::string::npos);
  832. /* drop the rest of the line */
  833. line = "";
  834. newCtx = true;
  835. }
  836. else if (mkword.substr(0,3)=="end")
  837. {
  838. switch (docContextStack[docCtxIdx]) {
  839. case SDOC_MACRO:
  840. /* for now MACRO and FUNCTION are handled in the same way */
  841. case SDOC_FUNCTION:
  842. commands.push_back(cmDocumentationEntry(name.c_str(),
  843. brief.c_str(),full.c_str()));
  844. break;
  845. case SDOC_VARIABLE:
  846. this->addAutomaticVariableSections(section);
  847. cm->DefineProperty
  848. (name.c_str(), cmProperty::VARIABLE,
  849. brief.c_str(),
  850. full.c_str(),false,
  851. section.c_str());
  852. break;
  853. case SDOC_MODULE:
  854. /* not implemented */
  855. break;
  856. case SDOC_SECTION:
  857. /* not implemented */
  858. break;
  859. default:
  860. /* ignore other cases */
  861. break;
  862. }
  863. docCtxIdx--;
  864. newCtx = false;
  865. ++nbDocItemFound;
  866. }
  867. else
  868. {
  869. // error out unhandled context
  870. return nbDocItemFound;
  871. }
  872. /* context is set go to next doc line */
  873. continue;
  874. }
  875. // Now parse the text attached to the context
  876. // The first line after the context mark-up contains::
  877. // name - brief until. (brief is dot terminated or
  878. // followed by a blank line)
  879. if (newCtx)
  880. {
  881. // no brief (for easy variable definition)
  882. if (line.find("-")==std::string::npos)
  883. {
  884. name = line.substr(1,std::string::npos);
  885. trim(name);
  886. brief = "";
  887. inBrief = false;
  888. full = "";
  889. }
  890. // here we have a name and brief beginning
  891. else
  892. {
  893. name = line.substr(1,line.find("-")-1);
  894. trim(name);
  895. // we are parsing the brief context
  896. brief = line.substr(line.find("-")+1,std::string::npos);
  897. trim(brief);
  898. // Brief may already be terminated on the first line
  899. if (brief.find('.')!=std::string::npos)
  900. {
  901. inBrief = false;
  902. full = brief.substr(brief.find('.')+1,std::string::npos);
  903. trim(full);
  904. inFullFirstParagraph = true;
  905. brief = brief.substr(0,brief.find('.'));
  906. }
  907. // brief is continued on following lines
  908. else
  909. {
  910. inBrief = true;
  911. full = "";
  912. }
  913. }
  914. newCtx = false;
  915. continue;
  916. }
  917. // blank line
  918. if(line.size() <= 2)
  919. {
  920. if (inBrief) {
  921. inBrief = false;
  922. full = "";
  923. } else {
  924. if (full.length()>0)
  925. {
  926. full += "\n";
  927. }
  928. // the first paragraph of full has ended
  929. inFullFirstParagraph = false;
  930. }
  931. newParagraph = true;
  932. }
  933. // brief is terminated by '.'
  934. else if (inBrief && (line.find('.')!=std::string::npos))
  935. {
  936. /* the brief just ended */
  937. inBrief = false;
  938. std::string endBrief = line.substr(1,line.find('.'));
  939. trim(endBrief);
  940. trim(brief);
  941. brief += " " + endBrief;
  942. full += line.substr(line.find('.')+1,std::string::npos);
  943. trim(full);
  944. inFullFirstParagraph = true;
  945. }
  946. // we handle full text or multi-line brief.
  947. else
  948. {
  949. std::string* text;
  950. if (inBrief)
  951. {
  952. text = &brief;
  953. }
  954. else
  955. {
  956. text = &full;
  957. }
  958. // two spaces
  959. if(line[1] == ' ' && line[2] == ' ')
  960. {
  961. // there is no "full first paragraph at all."
  962. if (line[3] == ' ')
  963. {
  964. inFullFirstParagraph = false;
  965. }
  966. if(!newParagraph && !inFullFirstParagraph)
  967. {
  968. *text += "\n";
  969. newParagraph = true;
  970. }
  971. // Skip #, and leave space for pre-formatted
  972. if (inFullFirstParagraph)
  973. {
  974. std::string temp = line.c_str()+1;
  975. trim(temp);
  976. *text += " " + temp;
  977. }
  978. else
  979. {
  980. *text += line.c_str()+1;
  981. *text += "\n";
  982. }
  983. }
  984. else if(line[1] == ' ')
  985. {
  986. if(!newParagraph)
  987. {
  988. *text += " ";
  989. }
  990. newParagraph = false;
  991. // skip # and space
  992. *text += line.c_str()+2;
  993. }
  994. else
  995. {
  996. if(!newParagraph)
  997. {
  998. *text += " ";
  999. }
  1000. newParagraph = false;
  1001. // skip #
  1002. *text += line.c_str()+1;
  1003. }
  1004. }
  1005. }
  1006. /* next line is not the first context line */
  1007. newCtx = false;
  1008. }
  1009. return nbDocItemFound;
  1010. }
  1011. //----------------------------------------------------------------------------
  1012. bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
  1013. const char* exitOpt)
  1014. {
  1015. // Providing zero arguments gives usage information.
  1016. if(argc == 1)
  1017. {
  1018. RequestedHelpItem help;
  1019. help.HelpType = cmDocumentation::Usage;
  1020. help.HelpForm = cmDocumentation::UsageForm;
  1021. this->RequestedHelpItems.push_back(help);
  1022. return true;
  1023. }
  1024. // Search for supported help options.
  1025. bool result = false;
  1026. for(int i=1; i < argc; ++i)
  1027. {
  1028. if(exitOpt && strcmp(argv[i], exitOpt) == 0)
  1029. {
  1030. return result;
  1031. }
  1032. RequestedHelpItem help;
  1033. // Check if this is a supported help option.
  1034. if((strcmp(argv[i], "-help") == 0) ||
  1035. (strcmp(argv[i], "--help") == 0) ||
  1036. (strcmp(argv[i], "/?") == 0) ||
  1037. (strcmp(argv[i], "-usage") == 0) ||
  1038. (strcmp(argv[i], "-h") == 0) ||
  1039. (strcmp(argv[i], "-H") == 0))
  1040. {
  1041. help.HelpType = cmDocumentation::Usage;
  1042. help.HelpForm = cmDocumentation::UsageForm;
  1043. GET_OPT_ARGUMENT(help.Argument);
  1044. help.Argument = cmSystemTools::LowerCase(help.Argument);
  1045. // special case for single command
  1046. if (!help.Argument.empty())
  1047. {
  1048. help.HelpType = cmDocumentation::Single;
  1049. }
  1050. }
  1051. else if(strcmp(argv[i], "--help-properties") == 0)
  1052. {
  1053. help.HelpType = cmDocumentation::Properties;
  1054. GET_OPT_ARGUMENT(help.Filename);
  1055. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1056. }
  1057. else if(strcmp(argv[i], "--help-policies") == 0)
  1058. {
  1059. help.HelpType = cmDocumentation::Policies;
  1060. GET_OPT_ARGUMENT(help.Filename);
  1061. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1062. }
  1063. else if(strcmp(argv[i], "--help-variables") == 0)
  1064. {
  1065. help.HelpType = cmDocumentation::Variables;
  1066. GET_OPT_ARGUMENT(help.Filename);
  1067. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1068. }
  1069. else if(strcmp(argv[i], "--help-modules") == 0)
  1070. {
  1071. help.HelpType = cmDocumentation::Modules;
  1072. GET_OPT_ARGUMENT(help.Filename);
  1073. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1074. }
  1075. else if(strcmp(argv[i], "--help-custom-modules") == 0)
  1076. {
  1077. help.HelpType = cmDocumentation::CustomModules;
  1078. GET_OPT_ARGUMENT(help.Filename);
  1079. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1080. }
  1081. else if(strcmp(argv[i], "--help-commands") == 0)
  1082. {
  1083. help.HelpType = cmDocumentation::Commands;
  1084. GET_OPT_ARGUMENT(help.Filename);
  1085. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1086. }
  1087. else if(strcmp(argv[i], "--help-compatcommands") == 0)
  1088. {
  1089. help.HelpType = cmDocumentation::CompatCommands;
  1090. GET_OPT_ARGUMENT(help.Filename);
  1091. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1092. }
  1093. else if(strcmp(argv[i], "--help-full") == 0)
  1094. {
  1095. help.HelpType = cmDocumentation::Full;
  1096. GET_OPT_ARGUMENT(help.Filename);
  1097. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1098. }
  1099. else if(strcmp(argv[i], "--help-html") == 0)
  1100. {
  1101. help.HelpType = cmDocumentation::Full;
  1102. GET_OPT_ARGUMENT(help.Filename);
  1103. help.HelpForm = cmDocumentation::HTMLForm;
  1104. }
  1105. else if(strcmp(argv[i], "--help-man") == 0)
  1106. {
  1107. help.HelpType = cmDocumentation::Full;
  1108. GET_OPT_ARGUMENT(help.Filename);
  1109. help.HelpForm = cmDocumentation::ManForm;
  1110. }
  1111. else if(strcmp(argv[i], "--help-command") == 0)
  1112. {
  1113. help.HelpType = cmDocumentation::Single;
  1114. GET_OPT_ARGUMENT(help.Argument);
  1115. GET_OPT_ARGUMENT(help.Filename);
  1116. help.Argument = cmSystemTools::LowerCase(help.Argument);
  1117. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1118. }
  1119. else if(strcmp(argv[i], "--help-module") == 0)
  1120. {
  1121. help.HelpType = cmDocumentation::SingleModule;
  1122. GET_OPT_ARGUMENT(help.Argument);
  1123. GET_OPT_ARGUMENT(help.Filename);
  1124. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1125. }
  1126. else if(strcmp(argv[i], "--help-property") == 0)
  1127. {
  1128. help.HelpType = cmDocumentation::SingleProperty;
  1129. GET_OPT_ARGUMENT(help.Argument);
  1130. GET_OPT_ARGUMENT(help.Filename);
  1131. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1132. }
  1133. else if(strcmp(argv[i], "--help-policy") == 0)
  1134. {
  1135. help.HelpType = cmDocumentation::SinglePolicy;
  1136. GET_OPT_ARGUMENT(help.Argument);
  1137. GET_OPT_ARGUMENT(help.Filename);
  1138. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1139. }
  1140. else if(strcmp(argv[i], "--help-variable") == 0)
  1141. {
  1142. help.HelpType = cmDocumentation::SingleVariable;
  1143. GET_OPT_ARGUMENT(help.Argument);
  1144. GET_OPT_ARGUMENT(help.Filename);
  1145. help.HelpForm = this->GetFormFromFilename(help.Filename);
  1146. }
  1147. else if(strcmp(argv[i], "--help-command-list") == 0)
  1148. {
  1149. help.HelpType = cmDocumentation::List;
  1150. GET_OPT_ARGUMENT(help.Filename);
  1151. help.HelpForm = cmDocumentation::TextForm;
  1152. }
  1153. else if(strcmp(argv[i], "--help-module-list") == 0)
  1154. {
  1155. help.HelpType = cmDocumentation::ModuleList;
  1156. GET_OPT_ARGUMENT(help.Filename);
  1157. help.HelpForm = cmDocumentation::TextForm;
  1158. }
  1159. else if(strcmp(argv[i], "--help-property-list") == 0)
  1160. {
  1161. help.HelpType = cmDocumentation::PropertyList;
  1162. GET_OPT_ARGUMENT(help.Filename);
  1163. help.HelpForm = cmDocumentation::TextForm;
  1164. }
  1165. else if(strcmp(argv[i], "--help-variable-list") == 0)
  1166. {
  1167. help.HelpType = cmDocumentation::VariableList;
  1168. GET_OPT_ARGUMENT(help.Filename);
  1169. help.HelpForm = cmDocumentation::TextForm;
  1170. }
  1171. else if(strcmp(argv[i], "--copyright") == 0)
  1172. {
  1173. help.HelpType = cmDocumentation::Copyright;
  1174. GET_OPT_ARGUMENT(help.Filename);
  1175. help.HelpForm = cmDocumentation::UsageForm;
  1176. }
  1177. else if((strcmp(argv[i], "--version") == 0) ||
  1178. (strcmp(argv[i], "-version") == 0) ||
  1179. (strcmp(argv[i], "/V") == 0))
  1180. {
  1181. help.HelpType = cmDocumentation::Version;
  1182. GET_OPT_ARGUMENT(help.Filename);
  1183. help.HelpForm = cmDocumentation::UsageForm;
  1184. }
  1185. if(help.HelpType != None)
  1186. {
  1187. // This is a help option. See if there is a file name given.
  1188. result = true;
  1189. this->RequestedHelpItems.push_back(help);
  1190. }
  1191. }
  1192. return result;
  1193. }
  1194. //----------------------------------------------------------------------------
  1195. void cmDocumentation::Print(Form f, std::ostream& os)
  1196. {
  1197. this->SetForm(f);
  1198. this->Print(os);
  1199. }
  1200. //----------------------------------------------------------------------------
  1201. void cmDocumentation::Print(std::ostream& os)
  1202. {
  1203. // if the formatter supports it, print a master index for
  1204. // all sections
  1205. this->CurrentFormatter->PrintIndex(os, this->PrintSections);
  1206. for(unsigned int i=0; i < this->PrintSections.size(); ++i)
  1207. {
  1208. std::string name = this->PrintSections[i]->
  1209. GetName((this->CurrentFormatter->GetForm()));
  1210. this->CurrentFormatter->PrintSection(os,*this->PrintSections[i],
  1211. name.c_str());
  1212. }
  1213. }
  1214. //----------------------------------------------------------------------------
  1215. void cmDocumentation::SetName(const char* name)
  1216. {
  1217. this->NameString = name?name:"";
  1218. }
  1219. //----------------------------------------------------------------------------
  1220. void cmDocumentation::SetDocName(const char *docname)
  1221. {
  1222. this->DocName = docname?docname:"";
  1223. }
  1224. //----------------------------------------------------------------------------
  1225. void cmDocumentation::SetSection(const char *name,
  1226. cmDocumentationSection *section)
  1227. {
  1228. if (this->AllSections.find(name) != this->AllSections.end())
  1229. {
  1230. delete this->AllSections[name];
  1231. }
  1232. this->AllSections[name] = section;
  1233. }
  1234. //----------------------------------------------------------------------------
  1235. void cmDocumentation::SetSection(const char *name,
  1236. std::vector<cmDocumentationEntry> &docs)
  1237. {
  1238. cmDocumentationSection *sec =
  1239. new cmDocumentationSection(name,
  1240. cmSystemTools::UpperCase(name).c_str());
  1241. sec->Append(docs);
  1242. this->SetSection(name,sec);
  1243. }
  1244. //----------------------------------------------------------------------------
  1245. void cmDocumentation::SetSection(const char *name,
  1246. const char *docs[][3])
  1247. {
  1248. cmDocumentationSection *sec =
  1249. new cmDocumentationSection(name,
  1250. cmSystemTools::UpperCase(name).c_str());
  1251. sec->Append(docs);
  1252. this->SetSection(name,sec);
  1253. }
  1254. //----------------------------------------------------------------------------
  1255. void cmDocumentation
  1256. ::SetSections(std::map<std::string,cmDocumentationSection *> &sections)
  1257. {
  1258. for (std::map<std::string,cmDocumentationSection *>::const_iterator
  1259. it = sections.begin(); it != sections.end(); ++it)
  1260. {
  1261. this->SetSection(it->first.c_str(),it->second);
  1262. }
  1263. }
  1264. //----------------------------------------------------------------------------
  1265. void cmDocumentation::PrependSection(const char *name,
  1266. const char *docs[][3])
  1267. {
  1268. cmDocumentationSection *sec = 0;
  1269. if (this->AllSections.find(name) == this->AllSections.end())
  1270. {
  1271. sec = new cmDocumentationSection
  1272. (name, cmSystemTools::UpperCase(name).c_str());
  1273. this->SetSection(name,sec);
  1274. }
  1275. else
  1276. {
  1277. sec = this->AllSections[name];
  1278. }
  1279. sec->Prepend(docs);
  1280. }
  1281. //----------------------------------------------------------------------------
  1282. void cmDocumentation::PrependSection(const char *name,
  1283. std::vector<cmDocumentationEntry> &docs)
  1284. {
  1285. cmDocumentationSection *sec = 0;
  1286. if (this->AllSections.find(name) == this->AllSections.end())
  1287. {
  1288. sec = new cmDocumentationSection
  1289. (name, cmSystemTools::UpperCase(name).c_str());
  1290. this->SetSection(name,sec);
  1291. }
  1292. else
  1293. {
  1294. sec = this->AllSections[name];
  1295. }
  1296. sec->Prepend(docs);
  1297. }
  1298. //----------------------------------------------------------------------------
  1299. void cmDocumentation::AppendSection(const char *name,
  1300. const char *docs[][3])
  1301. {
  1302. cmDocumentationSection *sec = 0;
  1303. if (this->AllSections.find(name) == this->AllSections.end())
  1304. {
  1305. sec = new cmDocumentationSection
  1306. (name, cmSystemTools::UpperCase(name).c_str());
  1307. this->SetSection(name,sec);
  1308. }
  1309. else
  1310. {
  1311. sec = this->AllSections[name];
  1312. }
  1313. sec->Append(docs);
  1314. }
  1315. //----------------------------------------------------------------------------
  1316. void cmDocumentation::AppendSection(const char *name,
  1317. std::vector<cmDocumentationEntry> &docs)
  1318. {
  1319. cmDocumentationSection *sec = 0;
  1320. if (this->AllSections.find(name) == this->AllSections.end())
  1321. {
  1322. sec = new cmDocumentationSection
  1323. (name, cmSystemTools::UpperCase(name).c_str());
  1324. this->SetSection(name,sec);
  1325. }
  1326. else
  1327. {
  1328. sec = this->AllSections[name];
  1329. }
  1330. sec->Append(docs);
  1331. }
  1332. //----------------------------------------------------------------------------
  1333. void cmDocumentation::AppendSection(const char *name,
  1334. cmDocumentationEntry &docs)
  1335. {
  1336. std::vector<cmDocumentationEntry> docsVec;
  1337. docsVec.push_back(docs);
  1338. this->AppendSection(name,docsVec);
  1339. }
  1340. //----------------------------------------------------------------------------
  1341. void cmDocumentation::PrependSection(const char *name,
  1342. cmDocumentationEntry &docs)
  1343. {
  1344. std::vector<cmDocumentationEntry> docsVec;
  1345. docsVec.push_back(docs);
  1346. this->PrependSection(name,docsVec);
  1347. }
  1348. //----------------------------------------------------------------------------
  1349. void cmDocumentation::SetSeeAlsoList(const char *data[][3])
  1350. {
  1351. cmDocumentationSection *sec =
  1352. new cmDocumentationSection("See Also", "SEE ALSO");
  1353. this->AllSections["See Also"] = sec;
  1354. this->SeeAlsoString = ".B ";
  1355. int i = 0;
  1356. while(data[i][1])
  1357. {
  1358. this->SeeAlsoString += data[i][1];
  1359. this->SeeAlsoString += data[i+1][1]? "(1), ":"(1)";
  1360. ++i;
  1361. }
  1362. sec->Append(0,this->SeeAlsoString.c_str(),0);
  1363. sec->Append(cmDocumentationStandardSeeAlso);
  1364. }
  1365. //----------------------------------------------------------------------------
  1366. bool cmDocumentation::PrintDocumentationGeneric(std::ostream& os,
  1367. const char *section)
  1368. {
  1369. if(this->AllSections.find(section) == this->AllSections.end())
  1370. {
  1371. os << "Internal error: " << section << " list is empty." << std::endl;
  1372. return false;
  1373. }
  1374. if(this->CurrentArgument.length() == 0)
  1375. {
  1376. os << "Required argument missing.\n";
  1377. return false;
  1378. }
  1379. const std::vector<cmDocumentationEntry> &entries =
  1380. this->AllSections[section]->GetEntries();
  1381. for(std::vector<cmDocumentationEntry>::const_iterator ei =
  1382. entries.begin();
  1383. ei != entries.end(); ++ei)
  1384. {
  1385. if(this->CurrentArgument == ei->Name)
  1386. {
  1387. this->PrintDocumentationCommand(os, *ei);
  1388. return true;
  1389. }
  1390. }
  1391. return false;
  1392. }
  1393. //----------------------------------------------------------------------------
  1394. bool cmDocumentation::PrintDocumentationSingle(std::ostream& os)
  1395. {
  1396. if (this->PrintDocumentationGeneric(os,"Commands"))
  1397. {
  1398. return true;
  1399. }
  1400. if (this->PrintDocumentationGeneric(os,"Compatibility Commands"))
  1401. {
  1402. return true;
  1403. }
  1404. // Argument was not a command. Complain.
  1405. os << "Argument \"" << this->CurrentArgument.c_str()
  1406. << "\" to --help-command is not a CMake command. "
  1407. << "Use --help-command-list to see all commands.\n";
  1408. return false;
  1409. }
  1410. //----------------------------------------------------------------------------
  1411. bool cmDocumentation::PrintDocumentationSingleModule(std::ostream& os)
  1412. {
  1413. if(this->CurrentArgument.length() == 0)
  1414. {
  1415. os << "Argument --help-module needs a module name.\n";
  1416. return false;
  1417. }
  1418. std::string moduleName;
  1419. // find the module
  1420. std::vector<std::string> dirs;
  1421. cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
  1422. for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
  1423. dirIt != dirs.end();
  1424. ++dirIt)
  1425. {
  1426. moduleName = *dirIt;
  1427. moduleName += "/";
  1428. moduleName += this->CurrentArgument;
  1429. moduleName += ".cmake";
  1430. if(cmSystemTools::FileExists(moduleName.c_str()))
  1431. {
  1432. break;
  1433. }
  1434. moduleName = "";
  1435. }
  1436. if (moduleName.empty())
  1437. {
  1438. moduleName = this->CMakeRoot;
  1439. moduleName += "/Modules/";
  1440. moduleName += this->CurrentArgument;
  1441. moduleName += ".cmake";
  1442. if(!cmSystemTools::FileExists(moduleName.c_str()))
  1443. {
  1444. moduleName = "";
  1445. }
  1446. }
  1447. if(!moduleName.empty())
  1448. {
  1449. cmDocumentationSection *sec =
  1450. new cmDocumentationSection("Standard CMake Modules", "MODULES");
  1451. this->AllSections["Modules"] = sec;
  1452. if (this->CreateSingleModule(moduleName.c_str(),
  1453. this->CurrentArgument.c_str(),
  1454. *this->AllSections["Modules"]))
  1455. {
  1456. if(this->AllSections["Modules"]->GetEntries().size())
  1457. {
  1458. this->PrintDocumentationCommand
  1459. (os, this->AllSections["Modules"]->GetEntries()[0]);
  1460. os << "\n Defined in: ";
  1461. os << moduleName << "\n";
  1462. return true;
  1463. }
  1464. else
  1465. {
  1466. return false;
  1467. }
  1468. }
  1469. }
  1470. // Argument was not a module. Complain.
  1471. os << "Argument \"" << this->CurrentArgument.c_str()
  1472. << "\" to --help-module is not a CMake module.\n";
  1473. return false;
  1474. }
  1475. //----------------------------------------------------------------------------
  1476. bool cmDocumentation::PrintDocumentationSingleProperty(std::ostream& os)
  1477. {
  1478. bool done = false;
  1479. for (std::vector<std::string>::iterator i =
  1480. this->PropertySections.begin();
  1481. !done && i != this->PropertySections.end(); ++i)
  1482. {
  1483. done = this->PrintDocumentationGeneric(os,i->c_str());
  1484. }
  1485. if (done)
  1486. {
  1487. return true;
  1488. }
  1489. // Argument was not a command. Complain.
  1490. os << "Argument \"" << this->CurrentArgument.c_str()
  1491. << "\" to --help-property is not a CMake property. "
  1492. << "Use --help-property-list to see all properties.\n";
  1493. return false;
  1494. }
  1495. //----------------------------------------------------------------------------
  1496. bool cmDocumentation::PrintDocumentationSinglePolicy(std::ostream& os)
  1497. {
  1498. if (this->PrintDocumentationGeneric(os,"Policies"))
  1499. {
  1500. return true;
  1501. }
  1502. // Argument was not a command. Complain.
  1503. os << "Argument \"" << this->CurrentArgument.c_str()
  1504. << "\" to --help-policy is not a CMake policy.\n";
  1505. return false;
  1506. }
  1507. //----------------------------------------------------------------------------
  1508. bool cmDocumentation::PrintDocumentationSingleVariable(std::ostream& os)
  1509. {
  1510. bool done = false;
  1511. for (std::vector<std::string>::iterator i =
  1512. this->VariableSections.begin();
  1513. !done && i != this->VariableSections.end(); ++i)
  1514. {
  1515. done = this->PrintDocumentationGeneric(os,i->c_str());
  1516. }
  1517. if (done)
  1518. {
  1519. return true;
  1520. }
  1521. // Argument was not a command. Complain.
  1522. os << "Argument \"" << this->CurrentArgument.c_str()
  1523. << "\" to --help-variable is not a defined variable. "
  1524. << "Use --help-variable-list to see all defined variables.\n";
  1525. return false;
  1526. }
  1527. //----------------------------------------------------------------------------
  1528. bool cmDocumentation::PrintDocumentationList(std::ostream& os,
  1529. const char *section)
  1530. {
  1531. if(this->AllSections.find(section) == this->AllSections.end())
  1532. {
  1533. os << "Internal error: " << section << " list is empty." << std::endl;
  1534. return false;
  1535. }
  1536. const std::vector<cmDocumentationEntry> &entries =
  1537. this->AllSections[section]->GetEntries();
  1538. for(std::vector<cmDocumentationEntry>::const_iterator ei =
  1539. entries.begin();
  1540. ei != entries.end(); ++ei)
  1541. {
  1542. if(ei->Name.size())
  1543. {
  1544. os << ei->Name << std::endl;
  1545. }
  1546. }
  1547. return true;
  1548. }
  1549. //----------------------------------------------------------------------------
  1550. bool cmDocumentation::PrintDocumentationUsage(std::ostream& os)
  1551. {
  1552. this->ClearSections();
  1553. this->AddSectionToPrint("Usage");
  1554. this->AddSectionToPrint("Options");
  1555. if(this->ShowGenerators)
  1556. {
  1557. this->AddSectionToPrint("Generators");
  1558. }
  1559. this->Print(os);
  1560. return true;
  1561. }
  1562. //----------------------------------------------------------------------------
  1563. bool cmDocumentation::PrintDocumentationFull(std::ostream& os)
  1564. {
  1565. this->CreateFullDocumentation();
  1566. this->CurrentFormatter->PrintHeader(GetNameString(), GetNameString(), os);
  1567. this->Print(os);
  1568. this->CurrentFormatter->PrintFooter(os);
  1569. return true;
  1570. }
  1571. //----------------------------------------------------------------------------
  1572. bool cmDocumentation::PrintDocumentationModules(std::ostream& os)
  1573. {
  1574. this->ClearSections();
  1575. this->CreateModulesSection();
  1576. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(Modules));
  1577. this->AddSectionToPrint("Description");
  1578. this->AddSectionToPrint("Modules");
  1579. this->AddSectionToPrint("Copyright");
  1580. this->AddSectionToPrint("See Also");
  1581. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1582. this->Print(os);
  1583. this->CurrentFormatter->PrintFooter(os);
  1584. return true;
  1585. }
  1586. //----------------------------------------------------------------------------
  1587. bool cmDocumentation::PrintDocumentationCustomModules(std::ostream& os)
  1588. {
  1589. this->ClearSections();
  1590. this->CreateCustomModulesSection();
  1591. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(CustomModules));
  1592. this->AddSectionToPrint("Description");
  1593. this->AddSectionToPrint("Custom CMake Modules");
  1594. // the custom modules are most probably not under Kitware's copyright, Alex
  1595. // this->AddSectionToPrint("Copyright");
  1596. this->AddSectionToPrint("See Also");
  1597. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1598. this->Print(os);
  1599. this->CurrentFormatter->PrintFooter(os);
  1600. return true;
  1601. }
  1602. //----------------------------------------------------------------------------
  1603. bool cmDocumentation::PrintDocumentationPolicies(std::ostream& os)
  1604. {
  1605. this->ClearSections();
  1606. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(Policies));
  1607. this->AddSectionToPrint("Description");
  1608. this->AddSectionToPrint("Policies");
  1609. this->AddSectionToPrint("Copyright");
  1610. this->AddSectionToPrint("See Also");
  1611. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1612. this->Print(os);
  1613. this->CurrentFormatter->PrintFooter(os);
  1614. return true;
  1615. }
  1616. //----------------------------------------------------------------------------
  1617. bool cmDocumentation::PrintDocumentationProperties(std::ostream& os)
  1618. {
  1619. this->ClearSections();
  1620. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(Properties));
  1621. this->AddSectionToPrint("Properties Description");
  1622. for (std::vector<std::string>::iterator i =
  1623. this->PropertySections.begin();
  1624. i != this->PropertySections.end(); ++i)
  1625. {
  1626. this->AddSectionToPrint(i->c_str());
  1627. }
  1628. this->AddSectionToPrint("Copyright");
  1629. this->AddSectionToPrint("Standard See Also");
  1630. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1631. this->Print(os);
  1632. this->CurrentFormatter->PrintFooter(os);
  1633. return true;
  1634. }
  1635. //----------------------------------------------------------------------------
  1636. bool cmDocumentation::PrintDocumentationVariables(std::ostream& os)
  1637. {
  1638. this->ClearSections();
  1639. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(Variables));
  1640. for (std::vector<std::string>::iterator i =
  1641. this->VariableSections.begin();
  1642. i != this->VariableSections.end(); ++i)
  1643. {
  1644. this->AddSectionToPrint(i->c_str());
  1645. }
  1646. this->AddSectionToPrint("Copyright");
  1647. this->AddSectionToPrint("Standard See Also");
  1648. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1649. this->Print(os);
  1650. this->CurrentFormatter->PrintFooter(os);
  1651. return true;
  1652. }
  1653. //----------------------------------------------------------------------------
  1654. bool cmDocumentation::PrintDocumentationCurrentCommands(std::ostream& os)
  1655. {
  1656. this->ClearSections();
  1657. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(Commands));
  1658. this->AddSectionToPrint("Commands");
  1659. this->AddSectionToPrint("Copyright");
  1660. this->AddSectionToPrint("Standard See Also");
  1661. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1662. this->Print(os);
  1663. this->CurrentFormatter->PrintFooter(os);
  1664. return true;
  1665. }
  1666. //----------------------------------------------------------------------------
  1667. bool cmDocumentation::PrintDocumentationCompatCommands(std::ostream& os)
  1668. {
  1669. this->ClearSections();
  1670. this->AddDocumentIntroToPrint(GET_DOCUMENT_INTRO(CompatCommands));
  1671. this->AddSectionToPrint("Compatibility Commands Description");
  1672. this->AddSectionToPrint("Compatibility Commands");
  1673. this->AddSectionToPrint("Copyright");
  1674. this->AddSectionToPrint("Standard See Also");
  1675. this->CurrentFormatter->PrintHeader(GetDocName(), GetNameString(), os);
  1676. this->Print(os);
  1677. this->CurrentFormatter->PrintFooter(os);
  1678. return true;
  1679. }
  1680. //----------------------------------------------------------------------------
  1681. void cmDocumentation
  1682. ::PrintDocumentationCommand(std::ostream& os,
  1683. const cmDocumentationEntry &entry)
  1684. {
  1685. // the string "SingleItem" will be used in a few places to detect the case
  1686. // that only the documentation for a single item is printed
  1687. cmDocumentationSection *sec = new cmDocumentationSection("SingleItem","");
  1688. sec->Append(entry);
  1689. this->AllSections["temp"] = sec;
  1690. this->ClearSections();
  1691. this->AddSectionToPrint("temp");
  1692. this->Print(os);
  1693. this->AllSections.erase("temp");
  1694. delete sec;
  1695. }
  1696. //----------------------------------------------------------------------------
  1697. void cmDocumentation::CreateFullDocumentation()
  1698. {
  1699. this->ClearSections();
  1700. this->CreateCustomModulesSection();
  1701. this->CreateModulesSection();
  1702. std::set<std::string> emitted;
  1703. this->AddSectionToPrint("Name");
  1704. emitted.insert("Name");
  1705. this->AddSectionToPrint("Usage");
  1706. emitted.insert("Usage");
  1707. this->AddSectionToPrint("Description");
  1708. emitted.insert("Description");
  1709. this->AddSectionToPrint("Options");
  1710. emitted.insert("Options");
  1711. this->AddSectionToPrint("Generators");
  1712. emitted.insert("Generators");
  1713. this->AddSectionToPrint("Commands");
  1714. emitted.insert("Commands");
  1715. this->AddSectionToPrint("Properties Description");
  1716. emitted.insert("Properties Description");
  1717. for (std::vector<std::string>::iterator i =
  1718. this->PropertySections.begin();
  1719. i != this->PropertySections.end(); ++i)
  1720. {
  1721. this->AddSectionToPrint(i->c_str());
  1722. emitted.insert(i->c_str());
  1723. }
  1724. emitted.insert("Copyright");
  1725. emitted.insert("See Also");
  1726. emitted.insert("Standard See Also");
  1727. emitted.insert("Author");
  1728. // add any sections not yet written out, or to be written out
  1729. for (std::map<std::string, cmDocumentationSection*>::iterator i =
  1730. this->AllSections.begin();
  1731. i != this->AllSections.end(); ++i)
  1732. {
  1733. if (emitted.find(i->first) == emitted.end())
  1734. {
  1735. this->AddSectionToPrint(i->first.c_str());
  1736. }
  1737. }
  1738. this->AddSectionToPrint("Copyright");
  1739. if(this->CurrentFormatter->GetForm() == ManForm)
  1740. {
  1741. this->AddSectionToPrint("See Also");
  1742. this->AddSectionToPrint("Author");
  1743. }
  1744. else
  1745. {
  1746. this->AddSectionToPrint("Standard See Also");
  1747. }
  1748. }
  1749. //----------------------------------------------------------------------------
  1750. void cmDocumentation::SetForm(Form f)
  1751. {
  1752. switch(f)
  1753. {
  1754. case HTMLForm:
  1755. this->CurrentFormatter = &this->HTMLFormatter;
  1756. break;
  1757. case DocbookForm:
  1758. this->CurrentFormatter = &this->DocbookFormatter;
  1759. break;
  1760. case ManForm:
  1761. this->CurrentFormatter = &this->ManFormatter;
  1762. break;
  1763. case TextForm:
  1764. this->CurrentFormatter = &this->TextFormatter;
  1765. break;
  1766. case UsageForm:
  1767. this->CurrentFormatter = & this->UsageFormatter;
  1768. break;
  1769. }
  1770. }
  1771. //----------------------------------------------------------------------------
  1772. const char* cmDocumentation::GetNameString() const
  1773. {
  1774. if(this->NameString.length() > 0)
  1775. {
  1776. return this->NameString.c_str();
  1777. }
  1778. else
  1779. {
  1780. return "CMake";
  1781. }
  1782. }
  1783. //----------------------------------------------------------------------------
  1784. const char* cmDocumentation::GetDocName(bool fallbackToNameString) const
  1785. {
  1786. if (this->DocName.length() > 0)
  1787. {
  1788. return this->DocName.c_str();
  1789. }
  1790. else if (fallbackToNameString)
  1791. {
  1792. return this->GetNameString();
  1793. }
  1794. else
  1795. return 0;
  1796. }
  1797. //----------------------------------------------------------------------------
  1798. #define CASE_DEFAULT_DOCNAME(doctype) \
  1799. case cmDocumentation::doctype : \
  1800. return GET_DOCUMENT_INTRO(doctype)[0];
  1801. const char* cmDocumentation::GetDefaultDocName(Type ht) const
  1802. {
  1803. switch (ht)
  1804. {
  1805. CASE_DEFAULT_DOCNAME(Modules)
  1806. CASE_DEFAULT_DOCNAME(CustomModules)
  1807. CASE_DEFAULT_DOCNAME(Policies)
  1808. CASE_DEFAULT_DOCNAME(Properties)
  1809. CASE_DEFAULT_DOCNAME(Variables)
  1810. CASE_DEFAULT_DOCNAME(Commands)
  1811. CASE_DEFAULT_DOCNAME(CompatCommands)
  1812. default: break;
  1813. }
  1814. return 0;
  1815. }
  1816. //----------------------------------------------------------------------------
  1817. bool cmDocumentation::IsOption(const char* arg) const
  1818. {
  1819. return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
  1820. (strcmp(arg, "/?") == 0));
  1821. }