cmDocumentation.cxx 41 KB

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