| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263 |
- /*=========================================================================
- Program: CMake - Cross-Platform Makefile Generator
- Module: $RCSfile$
- Language: C++
- Date: $Date$
- Version: $Revision$
- Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
- See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
- This software is distributed WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- PURPOSE. See the above copyright notices for more information.
- =========================================================================*/
- #include "cmDocumentation.h"
- #include "cmSystemTools.h"
- #include "cmVersion.h"
- #include <cmsys/Directory.hxx>
- //----------------------------------------------------------------------------
- static const char *cmDocumentationStandardOptions[][3] =
- {
- {"--copyright [file]", "Print the CMake copyright and exit.",
- "If a file is specified, the copyright is written into it."},
- {"--help", "Print usage information and exit.",
- "Usage describes the basic command line interface and its options."},
- {"--help-full [file]", "Print full help and exit.",
- "Full help displays most of the documentation provided by the UNIX "
- "man page. It is provided for use on non-UNIX platforms, but is "
- "also convenient if the man page is not installed. If a file is "
- "specified, the help is written into it."},
- {"--help-html [file]", "Print full help in HTML format.",
- "This option is used by CMake authors to help produce web pages. "
- "If a file is specified, the help is written into it."},
- {"--help-man [file]", "Print full help as a UNIX man page and exit.",
- "This option is used by the cmake build to generate the UNIX man page. "
- "If a file is specified, the help is written into it."},
- {"--version [file]", "Show program name/version banner and exit.",
- "If a file is specified, the version is written into it."},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmModulesDocumentationDescription[][3] =
- {
- {0,
- " CMake Modules - Modules coming with CMake, the Cross-Platform Makefile "
- "Generator.", 0},
- // CMAKE_DOCUMENTATION_OVERVIEW,
- {0,
- "This is the documentation for the modules and scripts coming with CMake. "
- "Using these modules you can check the computer system for "
- "installed software packages, features of the compiler and the "
- "existance of headers to name just a few.", 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmCustomModulesDocumentationDescription[][3] =
- {
- {0,
- " Custom CMake Modules - Additional Modules for CMake.", 0},
- // CMAKE_DOCUMENTATION_OVERVIEW,
- {0,
- "This is the documentation for additional modules and scripts for CMake. "
- "Using these modules you can check the computer system for "
- "installed software packages, features of the compiler and the "
- "existance of headers to name just a few.", 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmPropertiesDocumentationDescription[][3] =
- {
- {0,
- " CMake Properties - Properties supported by CMake, "
- "the Cross-Platform Makefile Generator.", 0},
- // CMAKE_DOCUMENTATION_OVERVIEW,
- {0,
- "This is the documentation for the properties supported by CMake. "
- "Properties can have different scopes. They can either be assigned to a "
- "source file, a directory, a target or globally to CMake. By modifying the "
- "values of properties the behaviour of the buildsystem can be customized.",
- 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmCompatCommandsDocumentationDescription[][3] =
- {
- {0,
- " CMake Compatibility Listfile Commands - "
- "Obsolete commands supported by CMake for compatibility.", 0},
- // CMAKE_DOCUMENTATION_OVERVIEW,
- {0,
- "This is the documentation for now obsolete listfile commands from previous "
- "CMake versions, which are still supported for compatibility reasons. You "
- "should instead use the newer, faster and shinier new commands. ;-)", 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmDocumentationModulesHeader[][3] =
- {
- {0,
- "The following modules are provided with CMake. "
- "They can be used with INCLUDE(ModuleName).", 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmDocumentationCustomModulesHeader[][3] =
- {
- {0,
- "The following modules are also available for CMake. "
- "They can be used with INCLUDE(ModuleName).", 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmDocumentationGeneratorsHeader[][3] =
- {
- {0,
- "The following generators are available on this platform:", 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmDocumentationStandardSeeAlso[][3] =
- {
- {0,
- "The following resources are available to get help using CMake:", 0},
- {"Home Page",
- "http://www.cmake.org",
- "The primary starting point for learning about CMake."},
- {"Frequently Asked Questions",
- "http://www.cmake.org/Wiki/CMake_FAQ",
- "A Wiki is provided containing answers to frequently asked questions. "},
- {"Online Documentation",
- "http://www.cmake.org/HTML/Documentation.html",
- "Links to available documentation may be found on this web page."},
- {"Mailing List",
- "http://www.cmake.org/HTML/MailingLists.html",
- "For help and discussion about using cmake, a mailing list is provided at "
- "[email protected]. "
- "The list is member-post-only but one may sign up on the CMake web page. "
- "Please first read the full documentation at "
- "http://www.cmake.org before posting questions to the list."},
- {0,
- "Summary of helpful links:\n"
- " Home: http://www.cmake.org\n"
- " Docs: http://www.cmake.org/HTML/Documentation.html\n"
- " Mail: http://www.cmake.org/HTML/MailingLists.html\n"
- " FAQ: http://www.cmake.org/Wiki/CMake_FAQ\n"
- , 0},
- {0,0,0}
- };
- //----------------------------------------------------------------------------
- static const char *cmDocumentationCopyright[][3] =
- {
- {0,
- "Copyright (c) 2002 Kitware, Inc., Insight Consortium. "
- "All rights reserved.", 0},
- {0,
- "Redistribution and use in source and binary forms, with or without "
- "modification, are permitted provided that the following conditions are "
- "met:", 0},
- {"",
- "Redistributions of source code must retain the above copyright notice, "
- "this list of conditions and the following disclaimer.", 0},
- {"",
- "Redistributions in binary form must reproduce the above copyright "
- "notice, this list of conditions and the following disclaimer in the "
- "documentation and/or other materials provided with the distribution.",
- 0},
- {"",
- "The names of Kitware, Inc., the Insight Consortium, or the names of "
- "any consortium members, or of any contributors, may not be used to "
- "endorse or promote products derived from this software without "
- "specific prior written permission.", 0},
- {"",
- "Modified source versions must be plainly marked as such, and must "
- "not be misrepresented as being the original software.", 0},
- {0,
- "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "
- "``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "
- "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR "
- "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR "
- "CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, "
- "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, "
- "PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR "
- "PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF "
- "LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING "
- "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS "
- "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", 0},
- {0, 0, 0}
- };
- //----------------------------------------------------------------------------
- cmDocumentation::cmDocumentation()
- :CurrentFormatter(0)
- {
- this->SetForm(TextForm);
- cmDocumentationSection *sec;
- sec = new cmDocumentationSection("Author","AUTHOR");
- sec->Append(cmDocumentationEntry
- (0,
- "This manual page was generated by the \"--help-man\" option.",
- 0));
- this->AllSections["Author"] = sec;
- sec = new cmDocumentationSection("Copyright","COPYRIGHT");
- sec->Append(cmDocumentationCopyright);
- this->AllSections["Copyright"] = sec;
- sec = new cmDocumentationSection("See Also","SEE ALSO");
- sec->Append(cmDocumentationStandardSeeAlso);
- this->AllSections["Standard See Also"] = sec;
- sec = new cmDocumentationSection("Options","OPTIONS");
- sec->Append(cmDocumentationStandardOptions);
- this->AllSections["Options"] = sec;
- sec = new cmDocumentationSection("Properties","PROPERTIES");
- sec->Append(cmPropertiesDocumentationDescription);
- this->AllSections["Properties Description"] = sec;
- sec = new cmDocumentationSection("Generators","GENERATORS");
- sec->Append(cmDocumentationGeneratorsHeader);
- this->AllSections["Generators"] = sec;
- }
- //----------------------------------------------------------------------------
- cmDocumentation::~cmDocumentation()
- {
- for(std::vector< char* >::iterator i = this->ModuleStrings.begin();
- i != this->ModuleStrings.end(); ++i)
- {
- delete [] *i;
- }
- for(std::map<std::string,cmDocumentationSection *>::iterator i =
- this->AllSections.begin();
- i != this->AllSections.end(); ++i)
- {
- delete i->second;
- }
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintCopyright(std::ostream& os)
- {
- cmDocumentationSection *sec = this->AllSections["Copyright"];
- const std::vector<cmDocumentationEntry> &entries = sec->GetEntries();
- for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin();
- op != entries.end(); ++op)
- {
- if(op->Name.size())
- {
- os << " * ";
- this->TextFormatter.SetIndent(" ");
- this->TextFormatter.PrintColumn(os, op->Brief.c_str());
- }
- else
- {
- this->TextFormatter.SetIndent("");
- this->TextFormatter.PrintColumn(os, op->Brief.c_str());
- }
- os << "\n";
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintVersion(std::ostream& os)
- {
- os << this->GetNameString() << " version "
- << cmVersion::GetCMakeVersion() << "\n";
- return true;
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::AddSectionToPrint(const char *section)
- {
- if (this->AllSections.find(section) != this->AllSections.end())
- {
- this->PrintSections.push_back(this->AllSections[section]);
- }
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::ClearSections()
- {
- this->PrintSections.erase(this->PrintSections.begin(),
- this->PrintSections.end());
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
- {
- if ((this->CurrentFormatter->GetForm() != HTMLForm)
- && (this->CurrentFormatter->GetForm() != ManForm))
- {
- this->PrintVersion(os);
- }
- switch (ht)
- {
- case cmDocumentation::Usage:
- return this->PrintDocumentationUsage(os);
- case cmDocumentation::Single:
- return this->PrintDocumentationSingle(os);
- case cmDocumentation::SingleModule:
- return this->PrintDocumentationSingleModule(os);
- case cmDocumentation::SingleProperty:
- return this->PrintDocumentationSingleProperty(os);
- case cmDocumentation::List:
- this->PrintDocumentationList(os,"Commands");
- this->PrintDocumentationList(os,"Compatibility Commands");
- return true;
- case cmDocumentation::ModuleList:
- this->PrintDocumentationList(os,"Modules");
- return true;
- case cmDocumentation::PropertyList:
- this->PrintDocumentationList(os,"Properties Description");
- this->PrintDocumentationList(os,"Properties of Global Scope");
- this->PrintDocumentationList(os,"Properties on Directories");
- this->PrintDocumentationList(os,"Properties on Targets");
- this->PrintDocumentationList(os,"Properties on Tests");
- this->PrintDocumentationList(os,"Properties on Source Files");
- return true;
- case cmDocumentation::Full:
- return this->PrintDocumentationFull(os);
- case cmDocumentation::Modules:
- return this->PrintDocumentationModules(os);
- case cmDocumentation::CustomModules:
- return this->PrintDocumentationCustomModules(os);
- case cmDocumentation::Properties:
- return this->PrintDocumentationProperties(os);
- case cmDocumentation::Commands:
- return this->PrintDocumentationCurrentCommands(os);
- case cmDocumentation::CompatCommands:
- return this->PrintDocumentationCompatCommands(os);
- case cmDocumentation::Copyright:
- return this->PrintCopyright(os);
- case cmDocumentation::Version:
- return true;
- default: return false;
- }
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::CreateModulesSection()
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection("Standard CMake Modules", "MODULES");
- this->AllSections["Modules"] = sec;
- std::string cmakeModules = this->CMakeRoot;
- cmakeModules += "/Modules";
- cmsys::Directory dir;
- dir.Load(cmakeModules.c_str());
- if (dir.GetNumberOfFiles() > 0)
- {
- sec->Append(cmDocumentationModulesHeader[0]);
- sec->Append(cmModulesDocumentationDescription);
- this->CreateModuleDocsForDir(dir, *this->AllSections["Modules"]);
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::CreateCustomModulesSection()
- {
- bool sectionHasHeader = false;
- std::vector<std::string> dirs;
- cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
- for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
- dirIt != dirs.end();
- ++dirIt)
- {
- cmsys::Directory dir;
- dir.Load(dirIt->c_str());
- if (dir.GetNumberOfFiles() > 0)
- {
- if (!sectionHasHeader)
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection("Custom CMake Modules","CUSTOM MODULES");
- this->AllSections["Custom CMake Modules"] = sec;
- sec->Append(cmDocumentationCustomModulesHeader[0]);
- sec->Append(cmCustomModulesDocumentationDescription);
- sectionHasHeader = true;
- }
- this->CreateModuleDocsForDir
- (dir, *this->AllSections["Custom CMake Modules"]);
- }
- }
- return true;
- }
- //----------------------------------------------------------------------------
- void cmDocumentation
- ::CreateModuleDocsForDir(cmsys::Directory& dir,
- cmDocumentationSection &moduleSection)
- {
- for(unsigned int i = 0; i < dir.GetNumberOfFiles(); ++i)
- {
- std::string fname = dir.GetFile(i);
- if(fname.length() > 6)
- {
- if(fname.substr(fname.length()-6, 6) == ".cmake")
- {
- std::string moduleName = fname.substr(0, fname.length()-6);
- if (this->ModulesFound.find(moduleName) == this->ModulesFound.end())
- {
- this->ModulesFound.insert(moduleName);
- std::string path = dir.GetPath();
- path += "/";
- path += fname;
- this->CreateSingleModule(path.c_str(), moduleName.c_str(),
- moduleSection);
- }
- }
- }
- }
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::CreateSingleModule(const char* fname,
- const char* moduleName,
- cmDocumentationSection &moduleSection)
- {
- std::ifstream fin(fname);
- if(!fin)
- {
- std::cerr << "Internal error: can not open module." << fname << std::endl;
- return false;
- }
- std::string line;
- std::string text;
- std::string brief;
- brief = " ";
- bool newParagraph = true;
- while ( fin && cmSystemTools::GetLineFromStream(fin, line) )
- {
- if(line.size() && line[0] == '#')
- {
- // blank line
- if(line.size() <= 2)
- {
- text += "\n";
- newParagraph = true;
- }
- else if(line[2] == '-')
- {
- brief = line.c_str()+4;
- }
- else
- {
- // two spaces
- if(line[1] == ' ' && line[2] == ' ')
- {
- if(!newParagraph)
- {
- text += "\n";
- newParagraph = true;
- }
- // Skip #, and leave space for preformatted
- text += line.c_str()+1;
- text += "\n";
- }
- else if(line[1] == ' ')
- {
- if(!newParagraph)
- {
- text += " ";
- }
- newParagraph = false;
- // skip # and space
- text += line.c_str()+2;
- }
- else
- {
- if(!newParagraph)
- {
- text += " ";
- }
- newParagraph = false;
- // skip #
- text += line.c_str()+1;
- }
- }
- }
- else
- {
- if(text.length() < 2 && brief.length() == 1)
- {
- return false;
- }
- char* pname = strcpy(new char[strlen(moduleName)+1], moduleName);
- char* ptext = strcpy(new char[text.length()+1], text.c_str());
- this->ModuleStrings.push_back(pname);
- this->ModuleStrings.push_back(ptext);
- char* pbrief = strcpy(new char[brief.length()+1], brief.c_str());
- this->ModuleStrings.push_back(pbrief);
- moduleSection.Append(pname, pbrief, ptext);
- return true;
- }
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
- {
- bool result = true;
-
- // Loop over requested documentation types.
- for(std::vector<RequestedHelpItem>::const_iterator
- i = this->RequestedHelpItems.begin();
- i != this->RequestedHelpItems.end();
- ++i)
- {
- this->SetForm(i->HelpForm);
- this->CurrentArgument = i->Argument;
- // If a file name was given, use it. Otherwise, default to the
- // given stream.
- std::ofstream* fout = 0;
- std::ostream* s = &os;
- if(i->Filename.length() > 0)
- {
- fout = new std::ofstream(i->Filename.c_str(), std::ios::out);
- if(fout)
- {
- s = fout;
- }
- else
- {
- result = false;
- }
- }
-
- // Print this documentation type to the stream.
- if(!this->PrintDocumentation(i->HelpType, *s) || !*s)
- {
- result = false;
- }
-
- // Close the file if we wrote one.
- if(fout)
- {
- delete fout;
- }
- }
- return result;
- }
- #define GET_OPT_ARGUMENT(target) \
- if((i+1 < argc) && !this->IsOption(argv[i+1])) \
- { \
- target = argv[i+1]; \
- i = i+1; \
- };
- cmDocumentation::Form cmDocumentation::GetFormFromFilename(
- const std::string& filename)
- {
- std::string ext = cmSystemTools::GetFilenameExtension(filename);
- ext = cmSystemTools::UpperCase(ext);
- if ((ext == ".HTM") || (ext == ".HTML"))
- {
- return cmDocumentation::HTMLForm;
- }
- // ".1" to ".9" should be manpages
- if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
- {
- return cmDocumentation::ManForm;
- }
- return cmDocumentation::TextForm;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::CheckOptions(int argc, const char* const* argv)
- {
- // Providing zero arguments gives usage information.
- if(argc == 1)
- {
- RequestedHelpItem help;
- help.HelpType = cmDocumentation::Usage;
- help.HelpForm = cmDocumentation::UsageForm;
- this->RequestedHelpItems.push_back(help);
- return true;
- }
- // Search for supported help options.
- bool result = false;
- for(int i=1; i < argc; ++i)
- {
- RequestedHelpItem help;
- // Check if this is a supported help option.
- if((strcmp(argv[i], "-help") == 0) ||
- (strcmp(argv[i], "--help") == 0) ||
- (strcmp(argv[i], "/?") == 0) ||
- (strcmp(argv[i], "-usage") == 0) ||
- (strcmp(argv[i], "-h") == 0) ||
- (strcmp(argv[i], "-H") == 0))
- {
- help.HelpType = cmDocumentation::Usage;
- help.HelpForm = cmDocumentation::UsageForm;
- GET_OPT_ARGUMENT(help.Argument);
- help.Argument = cmSystemTools::LowerCase(help.Argument);
- // special case for single command
- if (!help.Argument.empty())
- {
- help.HelpType = cmDocumentation::Single;
- }
- }
- else if(strcmp(argv[i], "--help-properties") == 0)
- {
- help.HelpType = cmDocumentation::Properties;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-modules") == 0)
- {
- help.HelpType = cmDocumentation::Modules;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-custom-modules") == 0)
- {
- help.HelpType = cmDocumentation::CustomModules;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-commands") == 0)
- {
- help.HelpType = cmDocumentation::Commands;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-compatcommands") == 0)
- {
- help.HelpType = cmDocumentation::CompatCommands;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-full") == 0)
- {
- help.HelpType = cmDocumentation::Full;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-html") == 0)
- {
- help.HelpType = cmDocumentation::Full;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::HTMLForm;
- }
- else if(strcmp(argv[i], "--help-man") == 0)
- {
- help.HelpType = cmDocumentation::Full;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::ManForm;
- }
- else if(strcmp(argv[i], "--help-command") == 0)
- {
- help.HelpType = cmDocumentation::Single;
- GET_OPT_ARGUMENT(help.Argument);
- GET_OPT_ARGUMENT(help.Filename);
- help.Argument = cmSystemTools::LowerCase(help.Argument);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-module") == 0)
- {
- help.HelpType = cmDocumentation::SingleModule;
- GET_OPT_ARGUMENT(help.Argument);
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-property") == 0)
- {
- help.HelpType = cmDocumentation::SingleProperty;
- GET_OPT_ARGUMENT(help.Argument);
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = this->GetFormFromFilename(help.Filename);
- }
- else if(strcmp(argv[i], "--help-command-list") == 0)
- {
- help.HelpType = cmDocumentation::List;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::TextForm;
- }
- else if(strcmp(argv[i], "--help-module-list") == 0)
- {
- help.HelpType = cmDocumentation::ModuleList;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::TextForm;
- }
- else if(strcmp(argv[i], "--help-property-list") == 0)
- {
- help.HelpType = cmDocumentation::PropertyList;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::TextForm;
- }
- else if(strcmp(argv[i], "--copyright") == 0)
- {
- help.HelpType = cmDocumentation::Copyright;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::UsageForm;
- }
- else if((strcmp(argv[i], "--version") == 0) ||
- (strcmp(argv[i], "-version") == 0) ||
- (strcmp(argv[i], "/V") == 0))
- {
- help.HelpType = cmDocumentation::Version;
- GET_OPT_ARGUMENT(help.Filename);
- help.HelpForm = cmDocumentation::UsageForm;
- }
- if(help.HelpType != None)
- {
- // This is a help option. See if there is a file name given.
- result = true;
- this->RequestedHelpItems.push_back(help);
- }
- }
- return result;
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::Print(Form f, std::ostream& os)
- {
- this->SetForm(f);
- this->Print(os);
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::Print(std::ostream& os)
- {
- for(unsigned int i=0; i < this->PrintSections.size(); ++i)
- {
- std::string name = this->PrintSections[i]->
- GetName((this->CurrentFormatter->GetForm()));
- this->CurrentFormatter->PrintSection(os,*this->PrintSections[i],
- name.c_str());
- }
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::SetName(const char* name)
- {
- this->NameString = name?name:"";
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::SetSection(const char *name,
- cmDocumentationSection *section)
- {
- if (this->AllSections.find(name) != this->AllSections.end())
- {
- delete this->AllSections[name];
- }
- this->AllSections[name] = section;
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::SetSection(const char *name,
- std::vector<cmDocumentationEntry> &docs)
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection(name,
- cmSystemTools::UpperCase(name).c_str());
- sec->Append(docs);
- this->SetSection(name,sec);
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::SetSection(const char *name,
- const char *docs[][3])
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection(name,
- cmSystemTools::UpperCase(name).c_str());
- sec->Append(docs);
- this->SetSection(name,sec);
- }
- //----------------------------------------------------------------------------
- void cmDocumentation
- ::SetSections(std::map<std::string,cmDocumentationSection *> §ions)
- {
- for (std::map<std::string,cmDocumentationSection *>::const_iterator
- it = sections.begin(); it != sections.end(); ++it)
- {
- this->SetSection(it->first.c_str(),it->second);
- }
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::PrependSection(const char *name,
- const char *docs[][3])
- {
- cmDocumentationSection *sec = 0;
- if (this->AllSections.find(name) == this->AllSections.end())
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection(name,
- cmSystemTools::UpperCase(name).c_str());
- this->SetSection(name,sec);
- }
- else
- {
- sec = this->AllSections[name];
- }
- sec->Prepend(docs);
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::AppendSection(const char *name,
- const char *docs[][3])
- {
- cmDocumentationSection *sec = 0;
- if (this->AllSections.find(name) == this->AllSections.end())
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection(name,
- cmSystemTools::UpperCase(name).c_str());
- this->SetSection(name,sec);
- }
- else
- {
- sec = this->AllSections[name];
- }
- sec->Append(docs);
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::AppendSection(const char *name,
- std::vector<cmDocumentationEntry> &docs)
- {
- cmDocumentationSection *sec = 0;
- if (this->AllSections.find(name) == this->AllSections.end())
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection(name,
- cmSystemTools::UpperCase(name).c_str());
- this->SetSection(name,sec);
- }
- else
- {
- sec = this->AllSections[name];
- }
- sec->Append(docs);
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::SetSeeAlsoList(const char *data[][3])
- {
- cmDocumentationSection *sec =
- new cmDocumentationSection("See Also", "SEE ALSO");
- this->AllSections["See Also"] = sec;
- this->SeeAlsoString = ".B ";
- int i = 0;
- while(data[i][1])
- {
- this->SeeAlsoString += data[i][1];
- this->SeeAlsoString += data[i+1][1]? "(1), ":"(1)";
- ++i;
- }
- sec->Append(0,this->SeeAlsoString.c_str(),0);
- sec->Append(cmDocumentationStandardSeeAlso);
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationGeneric(std::ostream& os,
- const char *section)
- {
- if(this->AllSections.find(section) == this->AllSections.end())
- {
- os << "Internal error: " << section << " list is empty." << std::endl;
- return false;
- }
- if(this->CurrentArgument.length() == 0)
- {
- os << "Required argument missing.\n";
- return false;
- }
- const std::vector<cmDocumentationEntry> &entries =
- this->AllSections[section]->GetEntries();
- for(std::vector<cmDocumentationEntry>::const_iterator ei =
- entries.begin();
- ei != entries.end(); ++ei)
- {
- if(this->CurrentArgument == ei->Name)
- {
- this->PrintDocumentationCommand(os, *ei);
- return true;
- }
- }
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationSingle(std::ostream& os)
- {
- if (this->PrintDocumentationGeneric(os,"Commands"))
- {
- return true;
- }
- if (this->PrintDocumentationGeneric(os,"Compatibility Commands"))
- {
- return true;
- }
- // Argument was not a command. Complain.
- os << "Argument \"" << this->CurrentArgument.c_str()
- << "\" to --help-command is not a CMake command. "
- << "Use --help-command-list to see all commands.\n";
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationSingleModule(std::ostream& os)
- {
- if(this->CurrentArgument.length() == 0)
- {
- os << "Argument --help-module needs a module name.\n";
- return false;
- }
-
- std::string moduleName;
- // find the module
- std::vector<std::string> dirs;
- cmSystemTools::ExpandListArgument(this->CMakeModulePath, dirs);
- for(std::vector<std::string>::const_iterator dirIt = dirs.begin();
- dirIt != dirs.end();
- ++dirIt)
- {
- moduleName = *dirIt;
- moduleName += "/";
- moduleName += this->CurrentArgument;
- moduleName += ".cmake";
- if(cmSystemTools::FileExists(moduleName.c_str()))
- {
- break;
- }
- moduleName = "";
- }
- if (moduleName.empty())
- {
- moduleName = this->CMakeRoot;
- moduleName += "/Modules/";
- moduleName += this->CurrentArgument;
- moduleName += ".cmake";
- if(!cmSystemTools::FileExists(moduleName.c_str()))
- {
- moduleName = "";
- }
- }
- if(!moduleName.empty()
- && this->CreateSingleModule(moduleName.c_str(),
- this->CurrentArgument.c_str(),
- *this->AllSections["Modules"]))
- {
- this->PrintDocumentationCommand
- (os, this->AllSections["Modules"]->GetEntries()[0]);
- os << "\n Defined in: ";
- os << moduleName << "\n";
- return true;
- }
- // Argument was not a module. Complain.
- os << "Argument \"" << this->CurrentArgument.c_str()
- << "\" to --help-module is not a CMake module.\n";
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationSingleProperty(std::ostream& os)
- {
- if (this->PrintDocumentationGeneric(os,"Properties of Global Scope"))
- {
- return true;
- }
- if (this->PrintDocumentationGeneric(os,"Properties on Directories"))
- {
- return true;
- }
- if (this->PrintDocumentationGeneric(os,"Properties on Targets"))
- {
- return true;
- }
- if (this->PrintDocumentationGeneric(os,"Properties on Tests"))
- {
- return true;
- }
- if (this->PrintDocumentationGeneric(os,"Properties on Source Files"))
- {
- return true;
- }
- // Argument was not a command. Complain.
- os << "Argument \"" << this->CurrentArgument.c_str()
- << "\" to --help-property is not a CMake property. "
- << "Use --help-property-list to see all properties.\n";
- return false;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationList(std::ostream& os,
- const char *section)
- {
- if(this->AllSections.find(section) == this->AllSections.end())
- {
- os << "Internal error: " << section << " list is empty." << std::endl;
- return false;
- }
- const std::vector<cmDocumentationEntry> &entries =
- this->AllSections[section]->GetEntries();
- for(std::vector<cmDocumentationEntry>::const_iterator ei =
- entries.begin();
- ei != entries.end(); ++ei)
- {
- if(ei->Name.size())
- {
- os << ei->Name << std::endl;
- }
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationUsage(std::ostream& os)
- {
- this->ClearSections();
- this->AddSectionToPrint("Usage");
- this->AddSectionToPrint("Options");
- this->AddSectionToPrint("Generators");
- this->Print(os);
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationFull(std::ostream& os)
- {
- this->CreateFullDocumentation();
- this->CurrentFormatter->PrintHeader(GetNameString(), os);
- this->Print(os);
- this->CurrentFormatter->PrintFooter(os);
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationModules(std::ostream& os)
- {
- this->ClearSections();
- this->CreateModulesSection();
- this->AddSectionToPrint("Description");
- this->AddSectionToPrint("Modules");
- this->AddSectionToPrint("Copyright");
- this->AddSectionToPrint("See Also");
- this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
- this->Print(os);
- this->CurrentFormatter->PrintFooter(os);
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationCustomModules(std::ostream& os)
- {
- this->ClearSections();
- this->CreateCustomModulesSection();
- this->AddSectionToPrint("Description");
- this->AddSectionToPrint("Custom Modules");
- this->AddSectionToPrint("Copyright");
- this->AddSectionToPrint("See Also");
- this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
- this->Print(os);
- this->CurrentFormatter->PrintFooter(os);
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationProperties(std::ostream& os)
- {
- this->ClearSections();
- this->AddSectionToPrint("Properties Description");
- this->AddSectionToPrint("Properties of Global Scope");
- this->AddSectionToPrint("Properties on Directories");
- this->AddSectionToPrint("Properties on Targets");
- this->AddSectionToPrint("Properties on Tests");
- this->AddSectionToPrint("Properties on Source Files");
- this->AddSectionToPrint("Copyright");
- this->AddSectionToPrint("Standard See Also");
- this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
- this->Print(os);
- this->CurrentFormatter->PrintFooter(os);
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationCurrentCommands(std::ostream& os)
- {
- this->ClearSections();
- this->AddSectionToPrint("Commands");
- this->AddSectionToPrint("Copyright");
- this->AddSectionToPrint("Standard See Also");
- this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
- this->Print(os);
- this->CurrentFormatter->PrintFooter(os);
- return true;
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::PrintDocumentationCompatCommands(std::ostream& os)
- {
- this->ClearSections();
- this->AddSectionToPrint("Compatibility Commands Description");
- this->AddSectionToPrint("Compatibility Commands");
- this->AddSectionToPrint("Copyright");
- this->AddSectionToPrint("Standard See Also");
- this->CurrentFormatter->PrintHeader(GetNameString(), os);
- this->Print(os);
- this->CurrentFormatter->PrintFooter(os);
- return true;
- }
- //----------------------------------------------------------------------------
- void cmDocumentation
- ::PrintDocumentationCommand(std::ostream& os,
- const cmDocumentationEntry &entry)
- {
- cmDocumentationSection *sec = new cmDocumentationSection("","");
- sec->Append(entry);
- this->AllSections["temp"] = sec;
- this->ClearSections();
- this->AddSectionToPrint("temp");
- this->Print(os);
- this->AllSections.erase("temp");
- delete sec;
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::CreateFullDocumentation()
- {
- this->ClearSections();
- this->CreateCustomModulesSection();
- this->CreateModulesSection();
- std::set<std::string> emitted;
- this->AddSectionToPrint("Name");
- emitted.insert("Name");
- this->AddSectionToPrint("Usage");
- emitted.insert("Usage");
- this->AddSectionToPrint("Description");
- emitted.insert("Description");
- this->AddSectionToPrint("Options");
- emitted.insert("Options");
- this->AddSectionToPrint("Generators");
- emitted.insert("Generators");
- this->AddSectionToPrint("Commands");
- emitted.insert("Commands");
- this->AddSectionToPrint("Properties Description");
- emitted.insert("Properties Description");
- this->AddSectionToPrint("Properties of Global Scope");
- emitted.insert("Properties of Global Scope");
- this->AddSectionToPrint("Properties on Directories");
- emitted.insert("Properties on Directories");
- this->AddSectionToPrint("Properties on Targets");
- emitted.insert("Properties on Targets");
- this->AddSectionToPrint("Properties on Tests");
- emitted.insert("Properties on Tests");
- this->AddSectionToPrint("Properties on Source Files");
- emitted.insert("Properties on Source Files");
- emitted.insert("Copyright");
- emitted.insert("See Also");
- emitted.insert("Standard See Also");
- emitted.insert("Author");
- // add any sections not yet written out, or to be written out
- for (std::map<std::string, cmDocumentationSection*>::iterator i =
- this->AllSections.begin();
- i != this->AllSections.end(); ++i)
- {
- if (emitted.find(i->first) == emitted.end())
- {
- this->AddSectionToPrint(i->first.c_str());
- }
- }
- this->AddSectionToPrint("Copyright");
- if(this->CurrentFormatter->GetForm() == ManForm)
- {
- this->AddSectionToPrint("See Also");
- this->AddSectionToPrint("Author");
- }
- else
- {
- this->AddSectionToPrint("Standard See Also");
- }
- }
- //----------------------------------------------------------------------------
- void cmDocumentation::SetForm(Form f)
- {
- switch(f)
- {
- case HTMLForm:
- this->CurrentFormatter = &this->HTMLFormatter;
- break;
- case ManForm:
- this->CurrentFormatter = &this->ManFormatter;
- break;
- case TextForm:
- this->CurrentFormatter = &this->TextFormatter;
- break;
- case UsageForm:
- this->CurrentFormatter = & this->UsageFormatter;
- break;
- }
- }
- //----------------------------------------------------------------------------
- const char* cmDocumentation::GetNameString() const
- {
- if(this->NameString.length() > 0)
- {
- return this->NameString.c_str();
- }
- else
- {
- return "CMake";
- }
- }
- //----------------------------------------------------------------------------
- bool cmDocumentation::IsOption(const char* arg) const
- {
- return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
- (strcmp(arg, "/?") == 0));
- }
|