cpack.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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 "cmSystemTools.h"
  11. // Need these for documentation support.
  12. #include "cmake.h"
  13. #include "cmDocumentation.h"
  14. #include "cmCPackDocumentVariables.h"
  15. #include "cmCPackDocumentMacros.h"
  16. #include "cmCPackGeneratorFactory.h"
  17. #include "cmCPackGenerator.h"
  18. #include "cmake.h"
  19. #include "cmGlobalGenerator.h"
  20. #include "cmLocalGenerator.h"
  21. #include "cmMakefile.h"
  22. #include "cmCPackLog.h"
  23. #include <cmsys/CommandLineArguments.hxx>
  24. #include <cmsys/SystemTools.hxx>
  25. //----------------------------------------------------------------------------
  26. static const char * cmDocumentationName[][3] =
  27. {
  28. {0,
  29. " cpack - Packaging driver provided by CMake.", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const char * cmDocumentationUsage[][3] =
  34. {
  35. {0,
  36. " cpack -G <generator> [options]",
  37. 0},
  38. {0,0,0}
  39. };
  40. //----------------------------------------------------------------------------
  41. static const char * cmDocumentationDescription[][3] =
  42. {
  43. {0,
  44. "The \"cpack\" executable is the CMake packaging program. "
  45. "CMake-generated build trees created for projects that use "
  46. "the INSTALL_* commands have packaging support. "
  47. "This program will generate the package.", 0},
  48. CMAKE_STANDARD_INTRODUCTION,
  49. {0,0,0}
  50. };
  51. //----------------------------------------------------------------------------
  52. static const char * cmDocumentationOptions[][3] =
  53. {
  54. {"-G <generator>", "Use the specified generator to generate package.",
  55. "CPack may support multiple native packaging systems on certain "
  56. "platforms. A generator is responsible for generating input files for "
  57. "particular system and invoking that systems. Possible generator names "
  58. "are specified in the Generators section." },
  59. {"-C <Configuration>", "Specify the project configuration",
  60. "This option specifies the configuration that the project was build "
  61. "with, for example 'Debug', 'Release'." },
  62. {"-D <var>=<value>", "Set a CPack variable.", \
  63. "Set a variable that can be used by the generator."}, \
  64. {"--config <config file>", "Specify the config file.",
  65. "Specify the config file to use to create the package. By default "
  66. "CPackConfig.cmake in the current directory will be used." },
  67. {"--verbose,-V","enable verbose output","Run cpack with verbose output."},
  68. {"--debug","enable debug output (for CPack developers)",
  69. "Run cpack with debug output (for CPack developers)."},
  70. {"-P <package name>","override/define CPACK_PACKAGE_NAME",
  71. "If the package name is not specified on cpack commmand line then"
  72. "CPack.cmake defines it as CMAKE_PROJECT_NAME"},
  73. {"-R <package version>","override/define CPACK_PACKAGE_VERSION",
  74. "If version is not specified on cpack command line then"
  75. "CPack.cmake defines it from CPACK_PACKAGE_VERSION_[MAJOR|MINOR|PATCH]"
  76. "look into CPack.cmake for detail"},
  77. {"-B <package directory>","override/define CPACK_PACKAGE_DIRECTORY",
  78. "The directory where CPack will be doing its packaging work."
  79. "The resulting package will be found there. Inside this directory"
  80. "CPack creates '_CPack_Packages' sub-directory which is the"
  81. "CPack temporary directory."},
  82. {"--vendor <vendor name>","override/define CPACK_PACKAGE_VENDOR",
  83. "If vendor is not specified on cpack command line "
  84. "(or inside CMakeLists.txt) then"
  85. "CPack.cmake defines it with a default value"},
  86. {"--help-command cmd [file]", "Print help for a single command and exit.",
  87. "Full documentation specific to the given command is displayed. "
  88. "If a file is specified, the documentation is written into and the output "
  89. "format is determined depending on the filename suffix. Supported are man "
  90. "page, HTML, DocBook and plain text."},
  91. {"--help-command-list [file]", "List available commands and exit.",
  92. "The list contains all commands for which help may be obtained by using "
  93. "the --help-command argument followed by a command name. "
  94. "If a file is specified, the documentation is written into and the output "
  95. "format is determined depending on the filename suffix. Supported are man "
  96. "page, HTML, DocBook and plain text."},
  97. {"--help-commands [file]", "Print help for all commands and exit.",
  98. "Full documentation specific for all current command is displayed."
  99. "If a file is specified, the documentation is written into and the output "
  100. "format is determined depending on the filename suffix. Supported are man "
  101. "page, HTML, DocBook and plain text."},
  102. {"--help-variable var [file]",
  103. "Print help for a single variable and exit.",
  104. "Full documentation specific to the given variable is displayed."
  105. "If a file is specified, the documentation is written into and the output "
  106. "format is determined depending on the filename suffix. Supported are man "
  107. "page, HTML, DocBook and plain text."},
  108. {"--help-variable-list [file]", "List documented variables and exit.",
  109. "The list contains all variables for which help may be obtained by using "
  110. "the --help-variable argument followed by a variable name. If a file is "
  111. "specified, the help is written into it."
  112. "If a file is specified, the documentation is written into and the output "
  113. "format is determined depending on the filename suffix. Supported are man "
  114. "page, HTML, DocBook and plain text."},
  115. {"--help-variables [file]", "Print help for all variables and exit.",
  116. "Full documentation for all variables is displayed."
  117. "If a file is specified, the documentation is written into and the output "
  118. "format is determined depending on the filename suffix. Supported are man "
  119. "page, HTML, DocBook and plain text."},
  120. {0,0,0}
  121. };
  122. //----------------------------------------------------------------------------
  123. static const char * cmDocumentationSeeAlso[][3] =
  124. {
  125. {0, "cmake", 0},
  126. {0, "ccmake", 0},
  127. {0, 0, 0}
  128. };
  129. //----------------------------------------------------------------------------
  130. int cpackUnknownArgument(const char*, void*)
  131. {
  132. return 1;
  133. }
  134. //----------------------------------------------------------------------------
  135. struct cpackDefinitions
  136. {
  137. typedef std::map<cmStdString, cmStdString> MapType;
  138. MapType Map;
  139. cmCPackLog *Log;
  140. };
  141. //----------------------------------------------------------------------------
  142. int cpackDefinitionArgument(const char* argument, const char* cValue,
  143. void* call_data)
  144. {
  145. (void)argument;
  146. cpackDefinitions* def = static_cast<cpackDefinitions*>(call_data);
  147. std::string value = cValue;
  148. size_t pos = value.find_first_of("=");
  149. if ( pos == std::string::npos )
  150. {
  151. cmCPack_Log(def->Log, cmCPackLog::LOG_ERROR,
  152. "Please specify CPack definitions as: KEY=VALUE" << std::endl);
  153. return 0;
  154. }
  155. std::string key = value.substr(0, pos);
  156. value = value.c_str() + pos + 1;
  157. def->Map[key] = value;
  158. cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: "
  159. << key.c_str() << " to \"" << value.c_str() << "\"" << std::endl);
  160. return 1;
  161. }
  162. //----------------------------------------------------------------------------
  163. // this is CPack.
  164. int main (int argc, char *argv[])
  165. {
  166. cmSystemTools::FindExecutableDirectory(argv[0]);
  167. cmCPackLog log;
  168. log.SetErrorPrefix("CPack Error: ");
  169. log.SetWarningPrefix("CPack Warning: ");
  170. log.SetOutputPrefix("CPack: ");
  171. log.SetVerbosePrefix("CPack Verbose: ");
  172. cmSystemTools::EnableMSVCDebugHook();
  173. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  174. {
  175. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  176. "Current working directory cannot be established." << std::endl);
  177. return 1;
  178. }
  179. std::string generator;
  180. bool help = false;
  181. bool helpVersion = false;
  182. bool verbose = false;
  183. bool debug = false;
  184. std::string helpFull;
  185. std::string helpMAN;
  186. std::string helpHTML;
  187. std::string cpackProjectName;
  188. std::string cpackProjectDirectory;
  189. std::string cpackBuildConfig;
  190. std::string cpackProjectVersion;
  191. std::string cpackProjectPatch;
  192. std::string cpackProjectVendor;
  193. std::string cpackConfigFile;
  194. cpackDefinitions definitions;
  195. definitions.Log = &log;
  196. cpackConfigFile = "";
  197. cmsys::CommandLineArguments arg;
  198. arg.Initialize(argc, argv);
  199. typedef cmsys::CommandLineArguments argT;
  200. // Help arguments
  201. arg.AddArgument("--help", argT::NO_ARGUMENT, &help, "CPack help");
  202. arg.AddArgument("--help-full", argT::SPACE_ARGUMENT, &helpFull,
  203. "CPack help");
  204. arg.AddArgument("--help-html", argT::SPACE_ARGUMENT, &helpHTML,
  205. "CPack help");
  206. arg.AddArgument("--help-man", argT::SPACE_ARGUMENT, &helpMAN, "CPack help");
  207. arg.AddArgument("--version", argT::NO_ARGUMENT, &helpVersion, "CPack help");
  208. arg.AddArgument("-V", argT::NO_ARGUMENT, &verbose, "CPack verbose");
  209. arg.AddArgument("--verbose", argT::NO_ARGUMENT, &verbose, "-V");
  210. arg.AddArgument("--debug", argT::NO_ARGUMENT, &debug, "-V");
  211. arg.AddArgument("--config", argT::SPACE_ARGUMENT, &cpackConfigFile,
  212. "CPack configuration file");
  213. arg.AddArgument("-C", argT::SPACE_ARGUMENT, &cpackBuildConfig,
  214. "CPack build configuration");
  215. arg.AddArgument("-G", argT::SPACE_ARGUMENT,
  216. &generator, "CPack generator");
  217. arg.AddArgument("-P", argT::SPACE_ARGUMENT,
  218. &cpackProjectName, "CPack project name");
  219. arg.AddArgument("-R", argT::SPACE_ARGUMENT,
  220. &cpackProjectVersion, "CPack project version");
  221. arg.AddArgument("-B", argT::SPACE_ARGUMENT,
  222. &cpackProjectDirectory, "CPack project directory");
  223. arg.AddArgument("--patch", argT::SPACE_ARGUMENT,
  224. &cpackProjectPatch, "CPack project patch");
  225. arg.AddArgument("--vendor", argT::SPACE_ARGUMENT,
  226. &cpackProjectVendor, "CPack project vendor");
  227. arg.AddCallback("-D", argT::SPACE_ARGUMENT,
  228. cpackDefinitionArgument, &definitions, "CPack Definitions");
  229. arg.SetUnknownArgumentCallback(cpackUnknownArgument);
  230. // Parse command line
  231. int parsed = arg.Parse();
  232. // Setup logging
  233. if ( verbose )
  234. {
  235. log.SetVerbose(verbose);
  236. cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose" << std::endl);
  237. }
  238. if ( debug )
  239. {
  240. log.SetDebug(debug);
  241. cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl);
  242. }
  243. cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
  244. "Read CPack config file: " << cpackConfigFile.c_str() << std::endl);
  245. cmake cminst;
  246. cminst.RemoveUnscriptableCommands();
  247. cmGlobalGenerator cmgg;
  248. cmgg.SetCMakeInstance(&cminst);
  249. cmsys::auto_ptr<cmLocalGenerator> cmlg(cmgg.CreateLocalGenerator());
  250. cmMakefile* globalMF = cmlg->GetMakefile();
  251. bool cpackConfigFileSpecified = true;
  252. if ( cpackConfigFile.empty() )
  253. {
  254. cpackConfigFile = cmSystemTools::GetCurrentWorkingDirectory();
  255. cpackConfigFile += "/CPackConfig.cmake";
  256. cpackConfigFileSpecified = false;
  257. }
  258. cmCPackGeneratorFactory generators;
  259. generators.SetLogger(&log);
  260. cmCPackGenerator* cpackGenerator = 0;
  261. cmDocumentation doc;
  262. doc.addCPackStandardDocSections();
  263. /* Were we invoked to display doc or to do some work ?
  264. * Unlike cmake launching cpack with zero argument
  265. * should launch cpack using "cpackConfigFile" if it exists
  266. * in the current directory.
  267. */
  268. if((doc.CheckOptions(argc, argv,"-G")) && !(argc==1))
  269. {
  270. help = true;
  271. }
  272. else
  273. {
  274. help = false;
  275. }
  276. // This part is used for cpack documentation lookup as well.
  277. cminst.AddCMakePaths();
  278. if ( parsed && !help )
  279. {
  280. // find out which system cpack is running on, so it can setup the search
  281. // paths, so FIND_XXX() commands can be used in scripts
  282. std::string systemFile =
  283. globalMF->GetModulesFile("CMakeDetermineSystem.cmake");
  284. if (!globalMF->ReadListFile(0, systemFile.c_str()))
  285. {
  286. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  287. "Error reading CMakeDetermineSystem.cmake" << std::endl);
  288. return 1;
  289. }
  290. systemFile =
  291. globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake");
  292. if (!globalMF->ReadListFile(0, systemFile.c_str()))
  293. {
  294. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  295. "Error reading CMakeSystemSpecificInformation.cmake" << std::endl);
  296. return 1;
  297. }
  298. if ( cmSystemTools::FileExists(cpackConfigFile.c_str()) )
  299. {
  300. cpackConfigFile =
  301. cmSystemTools::CollapseFullPath(cpackConfigFile.c_str());
  302. cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
  303. "Read CPack configuration file: " << cpackConfigFile.c_str()
  304. << std::endl);
  305. if ( !globalMF->ReadListFile(0, cpackConfigFile.c_str()) )
  306. {
  307. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  308. "Problem reading CPack config file: \""
  309. << cpackConfigFile.c_str() << "\"" << std::endl);
  310. return 1;
  311. }
  312. }
  313. else if ( cpackConfigFileSpecified )
  314. {
  315. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  316. "Cannot find CPack config file: \"" << cpackConfigFile.c_str()
  317. << "\"" << std::endl);
  318. return 1;
  319. }
  320. if ( !generator.empty() )
  321. {
  322. globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str());
  323. }
  324. if ( !cpackProjectName.empty() )
  325. {
  326. globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
  327. }
  328. if ( !cpackProjectVersion.empty() )
  329. {
  330. globalMF->AddDefinition("CPACK_PACKAGE_VERSION",
  331. cpackProjectVersion.c_str());
  332. }
  333. if ( !cpackProjectVendor.empty() )
  334. {
  335. globalMF->AddDefinition("CPACK_PACKAGE_VENDOR",
  336. cpackProjectVendor.c_str());
  337. }
  338. // if this is not empty it has been set on the command line
  339. // go for it. Command line override values set in config file.
  340. if ( !cpackProjectDirectory.empty() )
  341. {
  342. globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
  343. cpackProjectDirectory.c_str());
  344. }
  345. // The value has not been set on the command line
  346. else
  347. {
  348. // get a default value (current working directory)
  349. cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory();
  350. // use default value iff no value has been provided by the config file
  351. if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY"))
  352. {
  353. globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
  354. cpackProjectDirectory.c_str());
  355. }
  356. }
  357. if ( !cpackBuildConfig.empty() )
  358. {
  359. globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
  360. }
  361. cpackDefinitions::MapType::iterator cdit;
  362. for ( cdit = definitions.Map.begin();
  363. cdit != definitions.Map.end();
  364. ++cdit )
  365. {
  366. globalMF->AddDefinition(cdit->first.c_str(), cdit->second.c_str());
  367. }
  368. const char* cpackModulesPath =
  369. globalMF->GetDefinition("CPACK_MODULE_PATH");
  370. if ( cpackModulesPath )
  371. {
  372. globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath);
  373. }
  374. const char* genList = globalMF->GetDefinition("CPACK_GENERATOR");
  375. if ( !genList )
  376. {
  377. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  378. "CPack generator not specified" << std::endl);
  379. parsed = 0;
  380. }
  381. else
  382. {
  383. std::vector<std::string> generatorsVector;
  384. cmSystemTools::ExpandListArgument(genList,
  385. generatorsVector);
  386. std::vector<std::string>::iterator it;
  387. for ( it = generatorsVector.begin();
  388. it != generatorsVector.end();
  389. ++it )
  390. {
  391. const char* gen = it->c_str();
  392. cmMakefile newMF(*globalMF);
  393. cmMakefile* mf = &newMF;
  394. cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
  395. "Specified generator: " << gen << std::endl);
  396. if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") )
  397. {
  398. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  399. "CPack project name not specified" << std::endl);
  400. parsed = 0;
  401. }
  402. if (parsed &&
  403. !(mf->GetDefinition("CPACK_PACKAGE_VERSION") ||
  404. (mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
  405. mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") &&
  406. mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"))))
  407. {
  408. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  409. "CPack project version not specified" << std::endl
  410. << "Specify CPACK_PACKAGE_VERSION, or "
  411. "CPACK_PACKAGE_VERSION_MAJOR, "
  412. "CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH."
  413. << std::endl);
  414. parsed = 0;
  415. }
  416. if ( parsed )
  417. {
  418. cpackGenerator = generators.NewGenerator(gen);
  419. if ( !cpackGenerator )
  420. {
  421. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  422. "Cannot initialize CPack generator: "
  423. << gen << std::endl);
  424. parsed = 0;
  425. }
  426. if ( parsed && !cpackGenerator->Initialize(gen, mf) )
  427. {
  428. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  429. "Cannot initialize the generator " << gen << std::endl);
  430. parsed = 0;
  431. }
  432. if ( !mf->GetDefinition("CPACK_INSTALL_COMMANDS") &&
  433. !mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") &&
  434. !mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS") )
  435. {
  436. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  437. "Please specify build tree of the project that uses CMake "
  438. "using CPACK_INSTALL_CMAKE_PROJECTS, specify "
  439. "CPACK_INSTALL_COMMANDS, or specify "
  440. "CPACK_INSTALLED_DIRECTORIES."
  441. << std::endl);
  442. parsed = 0;
  443. }
  444. if ( parsed )
  445. {
  446. #ifdef _WIN32
  447. std::string comspec = "cmw9xcom.exe";
  448. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  449. #endif
  450. const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
  451. cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: "
  452. << cpackGenerator->GetNameOfClass() << std::endl);
  453. cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: "
  454. << projName << std::endl);
  455. const char* projVersion =
  456. mf->GetDefinition("CPACK_PACKAGE_VERSION");
  457. if ( !projVersion )
  458. {
  459. const char* projVersionMajor
  460. = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR");
  461. const char* projVersionMinor
  462. = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR");
  463. const char* projVersionPatch
  464. = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
  465. cmOStringStream ostr;
  466. ostr << projVersionMajor << "." << projVersionMinor << "."
  467. << projVersionPatch;
  468. mf->AddDefinition("CPACK_PACKAGE_VERSION",
  469. ostr.str().c_str());
  470. }
  471. int res = cpackGenerator->DoPackage();
  472. if ( !res )
  473. {
  474. cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
  475. "Error when generating package: " << projName << std::endl);
  476. return 1;
  477. }
  478. }
  479. }
  480. }
  481. }
  482. }
  483. /* In this case we are building the documentation object
  484. * instance in order to create appropriate structure
  485. * in order to satisfy the appropriate --help-xxx request
  486. */
  487. if ( help )
  488. {
  489. // Construct and print requested documentation.
  490. doc.SetName("cpack");
  491. doc.SetSection("Name",cmDocumentationName);
  492. doc.SetSection("Usage",cmDocumentationUsage);
  493. doc.SetSection("Description",cmDocumentationDescription);
  494. doc.PrependSection("Options",cmDocumentationOptions);
  495. // statically (in C++ code) defined variables
  496. cmCPackDocumentVariables::DefineVariables(&cminst);
  497. std::vector<cmDocumentationEntry> commands;
  498. std::string docedFile;
  499. std::string docPath;
  500. cmDocumentation::documentedModulesList_t docedModList;
  501. docedFile = globalMF->GetModulesFile("CPack.cmake");
  502. if (docedFile.length()!=0)
  503. {
  504. docPath = cmSystemTools::GetFilenamePath(docedFile.c_str());
  505. doc.getDocumentedModulesListInDir(docPath,"CPack*.cmake",docedModList);
  506. }
  507. // parse the files for documentation.
  508. cmDocumentation::documentedModulesList_t::iterator docedIt;
  509. for (docedIt = docedModList.begin();
  510. docedIt!= docedModList.end(); ++docedIt)
  511. {
  512. doc.GetStructuredDocFromFile(
  513. (docedIt->first).c_str(),
  514. commands,&cminst);
  515. }
  516. std::map<std::string,cmDocumentationSection *> propDocs;
  517. cminst.GetPropertiesDocumentation(propDocs);
  518. doc.SetSections(propDocs);
  519. cminst.GetCommandDocumentation(commands,true,false);
  520. // statically (in C++ code) defined macros/commands
  521. cmCPackDocumentMacros::GetMacrosDocumentation(commands);
  522. doc.SetSection("Commands",commands);
  523. std::vector<cmDocumentationEntry> v;
  524. cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt;
  525. for( generatorIt = generators.GetGeneratorsList().begin();
  526. generatorIt != generators.GetGeneratorsList().end();
  527. ++ generatorIt )
  528. {
  529. cmDocumentationEntry e;
  530. e.Name = generatorIt->first.c_str();
  531. e.Brief = generatorIt->second.c_str();
  532. e.Full = "";
  533. v.push_back(e);
  534. }
  535. doc.SetSection("Generators",v);
  536. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  537. #undef cout
  538. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  539. #define cout no_cout_use_cmCPack_Log
  540. }
  541. if (cmSystemTools::GetErrorOccuredFlag())
  542. {
  543. return 1;
  544. }
  545. return 0;
  546. }