cmDocumentation.cxx 63 KB

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