cmDocumentation.cxx 62 KB

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