cmCPackGenerator.cxx 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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 "cmCPackGenerator.h"
  11. #include "cmMakefile.h"
  12. #include "cmCPackLog.h"
  13. #include "cmake.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include "cmCPackComponentGroup.h"
  18. #include "cmXMLSafe.h"
  19. #include <cmsys/SystemTools.hxx>
  20. #include <cmsys/Glob.hxx>
  21. #include <memory> // auto_ptr
  22. #if defined(__HAIKU__)
  23. #include <StorageKit.h>
  24. #endif
  25. //----------------------------------------------------------------------
  26. cmCPackGenerator::cmCPackGenerator()
  27. {
  28. this->GeneratorVerbose = false;
  29. this->MakefileMap = 0;
  30. this->Logger = 0;
  31. }
  32. //----------------------------------------------------------------------
  33. cmCPackGenerator::~cmCPackGenerator()
  34. {
  35. this->MakefileMap = 0;
  36. }
  37. //----------------------------------------------------------------------
  38. void cmCPackGeneratorProgress(const char *msg, float prog, void* ptr)
  39. {
  40. cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr);
  41. self->DisplayVerboseOutput(msg, prog);
  42. }
  43. //----------------------------------------------------------------------
  44. void cmCPackGenerator::DisplayVerboseOutput(const char* msg,
  45. float progress)
  46. {
  47. (void)progress;
  48. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
  49. }
  50. //----------------------------------------------------------------------
  51. int cmCPackGenerator::PrepareNames()
  52. {
  53. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  54. "Create temp directory." << std::endl);
  55. std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  56. tempDirectory += "/_CPack_Packages/";
  57. const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
  58. if ( toplevelTag )
  59. {
  60. tempDirectory += toplevelTag;
  61. tempDirectory += "/";
  62. }
  63. tempDirectory += this->GetOption("CPACK_GENERATOR");
  64. std::string topDirectory = tempDirectory;
  65. this->GetOption("CPACK_PACKAGE_FILE_NAME");
  66. const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME");
  67. if(!pfname)
  68. {
  69. cmCPackLogger(cmCPackLog::LOG_ERROR,
  70. "CPACK_PACKAGE_FILE_NAME not specified" << std::endl);
  71. return 0;
  72. }
  73. std::string outName = pfname;
  74. tempDirectory += "/" + outName;
  75. if(!this->GetOutputExtension())
  76. {
  77. cmCPackLogger(cmCPackLog::LOG_ERROR,
  78. "No output extension specified" << std::endl);
  79. return 0;
  80. }
  81. outName += this->GetOutputExtension();
  82. const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  83. if(!pdir)
  84. {
  85. cmCPackLogger(cmCPackLog::LOG_ERROR,
  86. "CPACK_PACKAGE_DIRECTORY not specified" << std::endl);
  87. return 0;
  88. }
  89. std::string destFile = pdir;
  90. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PREFIX", destFile.c_str());
  91. destFile += "/" + outName;
  92. std::string outFile = topDirectory + "/" + outName;
  93. this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  94. this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  95. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  96. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  97. this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  98. outFile.c_str());
  99. this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  100. this->SetOptionIfNotSet("CPACK_NATIVE_INSTALL_DIRECTORY",
  101. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  102. this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
  103. tempDirectory.c_str());
  104. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  105. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  106. const char* descFileName
  107. = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  108. if ( descFileName )
  109. {
  110. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  111. "Look for: " << descFileName << std::endl);
  112. if ( !cmSystemTools::FileExists(descFileName) )
  113. {
  114. cmCPackLogger(cmCPackLog::LOG_ERROR,
  115. "Cannot find description file name: ["
  116. << descFileName << "]" << std::endl);
  117. return 0;
  118. }
  119. std::ifstream ifs(descFileName);
  120. if ( !ifs )
  121. {
  122. cmCPackLogger(cmCPackLog::LOG_ERROR,
  123. "Cannot open description file name: " << descFileName << std::endl);
  124. return 0;
  125. }
  126. cmOStringStream ostr;
  127. std::string line;
  128. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  129. "Read description file: " << descFileName << std::endl);
  130. while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
  131. {
  132. ostr << cmXMLSafe(line) << std::endl;
  133. }
  134. this->SetOptionIfNotSet("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  135. }
  136. if ( !this->GetOption("CPACK_PACKAGE_DESCRIPTION") )
  137. {
  138. cmCPackLogger(cmCPackLog::LOG_ERROR,
  139. "Project description not specified. Please specify "
  140. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  141. << std::endl);
  142. return 0;
  143. }
  144. this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
  145. return 1;
  146. }
  147. //----------------------------------------------------------------------
  148. int cmCPackGenerator::InstallProject()
  149. {
  150. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  151. this->CleanTemporaryDirectory();
  152. std::string bareTempInstallDirectory
  153. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  154. std::string tempInstallDirectoryStr = bareTempInstallDirectory;
  155. bool setDestDir = cmSystemTools::IsOn(this->GetOption("CPACK_SET_DESTDIR"));
  156. if (!setDestDir)
  157. {
  158. tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
  159. }
  160. const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
  161. int res = 1;
  162. if ( !cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str()))
  163. {
  164. cmCPackLogger(cmCPackLog::LOG_ERROR,
  165. "Problem creating temporary directory: "
  166. << (tempInstallDirectory ? tempInstallDirectory : "(NULL}")
  167. << std::endl);
  168. return 0;
  169. }
  170. if ( setDestDir )
  171. {
  172. std::string destDir = "DESTDIR=";
  173. destDir += tempInstallDirectory;
  174. cmSystemTools::PutEnv(destDir.c_str());
  175. }
  176. else
  177. {
  178. // Make sure there is no destdir
  179. cmSystemTools::PutEnv("DESTDIR=");
  180. }
  181. // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
  182. // as listed
  183. if ( !this->InstallProjectViaInstallCommands(
  184. setDestDir, tempInstallDirectory) )
  185. {
  186. return 0;
  187. }
  188. // If the CPackConfig file sets CPACK_INSTALL_SCRIPT then run them
  189. // as listed
  190. if ( !this->InstallProjectViaInstallScript(
  191. setDestDir, tempInstallDirectory) )
  192. {
  193. return 0;
  194. }
  195. // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
  196. // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
  197. // This is used in Source packageing
  198. if ( !this->InstallProjectViaInstalledDirectories(
  199. setDestDir, tempInstallDirectory) )
  200. {
  201. return 0;
  202. }
  203. // If the project is a CMAKE project then run pre-install
  204. // and then read the cmake_install script to run it
  205. if ( !this->InstallProjectViaInstallCMakeProjects(
  206. setDestDir, bareTempInstallDirectory.c_str()) )
  207. {
  208. return 0;
  209. }
  210. if ( setDestDir )
  211. {
  212. cmSystemTools::PutEnv("DESTDIR=");
  213. }
  214. return res;
  215. }
  216. //----------------------------------------------------------------------
  217. int cmCPackGenerator::InstallProjectViaInstallCommands(
  218. bool setDestDir, const char* tempInstallDirectory)
  219. {
  220. (void) setDestDir;
  221. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  222. if ( installCommands && *installCommands )
  223. {
  224. std::string tempInstallDirectoryEnv = "CMAKE_INSTALL_PREFIX=";
  225. tempInstallDirectoryEnv += tempInstallDirectory;
  226. cmSystemTools::PutEnv(tempInstallDirectoryEnv.c_str());
  227. std::vector<std::string> installCommandsVector;
  228. cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
  229. std::vector<std::string>::iterator it;
  230. for ( it = installCommandsVector.begin();
  231. it != installCommandsVector.end();
  232. ++it )
  233. {
  234. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << it->c_str()
  235. << std::endl);
  236. std::string output;
  237. int retVal = 1;
  238. bool resB = cmSystemTools::RunSingleCommand(it->c_str(), &output,
  239. &retVal, 0, this->GeneratorVerbose, 0);
  240. if ( !resB || retVal )
  241. {
  242. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  243. tmpFile += "/InstallOutput.log";
  244. cmGeneratedFileStream ofs(tmpFile.c_str());
  245. ofs << "# Run command: " << it->c_str() << std::endl
  246. << "# Output:" << std::endl
  247. << output.c_str() << std::endl;
  248. cmCPackLogger(cmCPackLog::LOG_ERROR,
  249. "Problem running install command: " << it->c_str() << std::endl
  250. << "Please check " << tmpFile.c_str() << " for errors"
  251. << std::endl);
  252. return 0;
  253. }
  254. }
  255. }
  256. return 1;
  257. }
  258. //----------------------------------------------------------------------
  259. int cmCPackGenerator::InstallProjectViaInstalledDirectories(
  260. bool setDestDir, const char* tempInstallDirectory)
  261. {
  262. (void)setDestDir;
  263. (void)tempInstallDirectory;
  264. std::vector<cmsys::RegularExpression> ignoreFilesRegex;
  265. const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
  266. if ( cpackIgnoreFiles )
  267. {
  268. std::vector<std::string> ignoreFilesRegexString;
  269. cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
  270. ignoreFilesRegexString);
  271. std::vector<std::string>::iterator it;
  272. for ( it = ignoreFilesRegexString.begin();
  273. it != ignoreFilesRegexString.end();
  274. ++it )
  275. {
  276. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  277. "Create ignore files regex for: " << it->c_str() << std::endl);
  278. ignoreFilesRegex.push_back(it->c_str());
  279. }
  280. }
  281. const char* installDirectories
  282. = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  283. if ( installDirectories && *installDirectories )
  284. {
  285. std::vector<std::string> installDirectoriesVector;
  286. cmSystemTools::ExpandListArgument(installDirectories,
  287. installDirectoriesVector);
  288. if ( installDirectoriesVector.size() % 2 != 0 )
  289. {
  290. cmCPackLogger(cmCPackLog::LOG_ERROR,
  291. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> and "
  292. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  293. "the toplevel directory of installation." << std::endl);
  294. return 0;
  295. }
  296. std::vector<std::string>::iterator it;
  297. const char* tempDir = tempInstallDirectory;
  298. for ( it = installDirectoriesVector.begin();
  299. it != installDirectoriesVector.end();
  300. ++it )
  301. {
  302. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  303. cmsys::Glob gl;
  304. std::string top = it->c_str();
  305. it ++;
  306. std::string subdir = it->c_str();
  307. std::string findExpr = top;
  308. findExpr += "/*";
  309. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  310. "- Install directory: " << top << std::endl);
  311. gl.RecurseOn();
  312. if ( !gl.FindFiles(findExpr) )
  313. {
  314. cmCPackLogger(cmCPackLog::LOG_ERROR,
  315. "Cannot find any files in the installed directory" << std::endl);
  316. return 0;
  317. }
  318. files = gl.GetFiles();
  319. std::vector<std::string>::iterator gfit;
  320. std::vector<cmsys::RegularExpression>::iterator regIt;
  321. for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
  322. {
  323. bool skip = false;
  324. std::string &inFile = *gfit;
  325. for ( regIt= ignoreFilesRegex.begin();
  326. regIt!= ignoreFilesRegex.end();
  327. ++ regIt)
  328. {
  329. if ( regIt->find(inFile.c_str()) )
  330. {
  331. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Ignore file: "
  332. << inFile.c_str() << std::endl);
  333. skip = true;
  334. }
  335. }
  336. if ( skip )
  337. {
  338. continue;
  339. }
  340. std::string filePath = tempDir;
  341. filePath += "/" + subdir + "/"
  342. + cmSystemTools::RelativePath(top.c_str(), gfit->c_str());
  343. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
  344. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  345. if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
  346. filePath.c_str()) )
  347. {
  348. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying file: "
  349. << inFile.c_str() << " -> " << filePath.c_str() << std::endl);
  350. return 0;
  351. }
  352. }
  353. }
  354. }
  355. return 1;
  356. }
  357. //----------------------------------------------------------------------
  358. int cmCPackGenerator::InstallProjectViaInstallScript(
  359. bool setDestDir, const char* tempInstallDirectory)
  360. {
  361. const char* cmakeScripts
  362. = this->GetOption("CPACK_INSTALL_SCRIPT");
  363. if ( cmakeScripts && *cmakeScripts )
  364. {
  365. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  366. "- Install scripts: " << cmakeScripts << std::endl);
  367. std::vector<std::string> cmakeScriptsVector;
  368. cmSystemTools::ExpandListArgument(cmakeScripts,
  369. cmakeScriptsVector);
  370. std::vector<std::string>::iterator it;
  371. for ( it = cmakeScriptsVector.begin();
  372. it != cmakeScriptsVector.end();
  373. ++it )
  374. {
  375. std::string installScript = it->c_str();
  376. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  377. "- Install script: " << installScript << std::endl);
  378. if ( setDestDir )
  379. {
  380. // For DESTDIR based packaging, use the *project* CMAKE_INSTALL_PREFIX
  381. // underneath the tempInstallDirectory. The value of the project's
  382. // CMAKE_INSTALL_PREFIX is sent in here as the value of the
  383. // CPACK_INSTALL_PREFIX variable.
  384. std::string dir;
  385. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  386. {
  387. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  388. }
  389. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  390. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  391. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  392. << std::endl);
  393. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  394. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'" << std::endl);
  395. }
  396. else
  397. {
  398. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  399. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  400. "- Using non-DESTDIR install... (this->SetOption)" << std::endl);
  401. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  402. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  403. << "'" << std::endl);
  404. }
  405. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  406. tempInstallDirectory);
  407. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  408. tempInstallDirectory);
  409. int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
  410. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  411. {
  412. return 0;
  413. }
  414. }
  415. }
  416. return 1;
  417. }
  418. //----------------------------------------------------------------------
  419. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  420. bool setDestDir, const char* baseTempInstallDirectory)
  421. {
  422. const char* cmakeProjects
  423. = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  424. const char* cmakeGenerator
  425. = this->GetOption("CPACK_CMAKE_GENERATOR");
  426. if ( cmakeProjects && *cmakeProjects )
  427. {
  428. if ( !cmakeGenerator )
  429. {
  430. cmCPackLogger(cmCPackLog::LOG_ERROR,
  431. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  432. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  433. "is required to install the project."
  434. << std::endl);
  435. return 0;
  436. }
  437. std::vector<std::string> cmakeProjectsVector;
  438. cmSystemTools::ExpandListArgument(cmakeProjects,
  439. cmakeProjectsVector);
  440. std::vector<std::string>::iterator it;
  441. for ( it = cmakeProjectsVector.begin();
  442. it != cmakeProjectsVector.end();
  443. ++it )
  444. {
  445. if ( it+1 == cmakeProjectsVector.end() ||
  446. it+2 == cmakeProjectsVector.end() ||
  447. it+3 == cmakeProjectsVector.end() )
  448. {
  449. cmCPackLogger(cmCPackLog::LOG_ERROR,
  450. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  451. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  452. "directory, install project name, install component, and install "
  453. "subdirectory."
  454. << std::endl);
  455. return 0;
  456. }
  457. std::string installDirectory = it->c_str();
  458. ++it;
  459. std::string installProjectName = it->c_str();
  460. ++it;
  461. std::string installComponent = it->c_str();
  462. ++it;
  463. std::string installSubDirectory = it->c_str();
  464. std::string installFile = installDirectory + "/cmake_install.cmake";
  465. std::vector<std::string> componentsVector;
  466. bool componentInstall = false;
  467. if (this->SupportsComponentInstallation())
  468. {
  469. // Determine the installation types for this project (if provided).
  470. std::string installTypesVar = "CPACK_"
  471. + cmSystemTools::UpperCase(installComponent) + "_INSTALL_TYPES";
  472. const char *installTypes = this->GetOption(installTypesVar.c_str());
  473. if (installTypes && *installTypes)
  474. {
  475. std::vector<std::string> installTypesVector;
  476. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  477. std::vector<std::string>::iterator installTypeIt;
  478. for (installTypeIt = installTypesVector.begin();
  479. installTypeIt != installTypesVector.end();
  480. ++installTypeIt)
  481. {
  482. this->GetInstallationType(installProjectName.c_str(),
  483. installTypeIt->c_str());
  484. }
  485. }
  486. // Determine the set of components that will be used in this project
  487. std::string componentsVar
  488. = "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
  489. const char *components = this->GetOption(componentsVar.c_str());
  490. if (components && *components)
  491. {
  492. cmSystemTools::ExpandListArgument(components, componentsVector);
  493. std::vector<std::string>::iterator compIt;
  494. for (compIt = componentsVector.begin();
  495. compIt != componentsVector.end();
  496. ++compIt)
  497. {
  498. GetComponent(installProjectName.c_str(), compIt->c_str());
  499. }
  500. componentInstall = true;
  501. }
  502. }
  503. if (componentsVector.empty())
  504. {
  505. componentsVector.push_back(installComponent);
  506. }
  507. const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
  508. cmGlobalGenerator* globalGenerator
  509. = this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  510. cmakeGenerator);
  511. // set the global flag for unix style paths on cmSystemTools as
  512. // soon as the generator is set. This allows gmake to be used
  513. // on windows.
  514. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  515. // Does this generator require pre-install?
  516. if ( globalGenerator->GetPreinstallTargetName() )
  517. {
  518. globalGenerator->FindMakeProgram(this->MakefileMap);
  519. const char* cmakeMakeProgram
  520. = this->MakefileMap->GetDefinition("CMAKE_MAKE_PROGRAM");
  521. std::string buildCommand
  522. = globalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  523. installProjectName.c_str(), 0,
  524. globalGenerator->GetPreinstallTargetName(),
  525. buildConfig, false, false);
  526. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  527. "- Install command: " << buildCommand << std::endl);
  528. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  529. "- Run preinstall target for: " << installProjectName << std::endl);
  530. std::string output;
  531. int retVal = 1;
  532. bool resB =
  533. cmSystemTools::RunSingleCommand(buildCommand.c_str(),
  534. &output,
  535. &retVal,
  536. installDirectory.c_str(),
  537. this->GeneratorVerbose, 0);
  538. if ( !resB || retVal )
  539. {
  540. std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  541. tmpFile += "/PreinstallOutput.log";
  542. cmGeneratedFileStream ofs(tmpFile.c_str());
  543. ofs << "# Run command: " << buildCommand.c_str() << std::endl
  544. << "# Directory: " << installDirectory.c_str() << std::endl
  545. << "# Output:" << std::endl
  546. << output.c_str() << std::endl;
  547. cmCPackLogger(cmCPackLog::LOG_ERROR,
  548. "Problem running install command: " << buildCommand.c_str()
  549. << std::endl
  550. << "Please check " << tmpFile.c_str() << " for errors"
  551. << std::endl);
  552. return 0;
  553. }
  554. }
  555. delete globalGenerator;
  556. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  557. "- Install project: " << installProjectName << std::endl);
  558. // Run the installation for each component
  559. std::vector<std::string>::iterator componentIt;
  560. for (componentIt = componentsVector.begin();
  561. componentIt != componentsVector.end();
  562. ++componentIt)
  563. {
  564. std::string tempInstallDirectory = baseTempInstallDirectory;
  565. installComponent = *componentIt;
  566. if (componentInstall)
  567. {
  568. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  569. "- Install component: " << installComponent
  570. << std::endl);
  571. }
  572. cmake cm;
  573. cm.AddCMakePaths();
  574. cm.SetProgressCallback(cmCPackGeneratorProgress, this);
  575. cmGlobalGenerator gg;
  576. gg.SetCMakeInstance(&cm);
  577. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  578. cmMakefile *mf = lg->GetMakefile();
  579. std::string realInstallDirectory = tempInstallDirectory;
  580. if ( !installSubDirectory.empty() && installSubDirectory != "/" )
  581. {
  582. realInstallDirectory += installSubDirectory;
  583. }
  584. if (componentInstall)
  585. {
  586. tempInstallDirectory += "/";
  587. tempInstallDirectory += installComponent;
  588. }
  589. if (!setDestDir)
  590. {
  591. tempInstallDirectory += this->GetPackagingInstallPrefix();
  592. }
  593. if ( setDestDir )
  594. {
  595. // For DESTDIR based packaging, use the *project*
  596. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  597. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  598. // the value of the CPACK_INSTALL_PREFIX variable.
  599. //
  600. std::string dir;
  601. if (this->GetOption("CPACK_INSTALL_PREFIX"))
  602. {
  603. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  604. }
  605. mf->AddDefinition("CMAKE_INSTALL_PREFIX", dir.c_str());
  606. cmCPackLogger(
  607. cmCPackLog::LOG_DEBUG,
  608. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf->AddDefinition)"
  609. << std::endl);
  610. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  611. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  612. << std::endl);
  613. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  614. // exists:
  615. //
  616. if (cmSystemTools::StringStartsWith(dir.c_str(), "/"))
  617. {
  618. dir = tempInstallDirectory + dir;
  619. }
  620. else
  621. {
  622. dir = tempInstallDirectory + "/" + dir;
  623. }
  624. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  625. "- Creating directory: '" << dir << "'" << std::endl);
  626. if ( !cmsys::SystemTools::MakeDirectory(dir.c_str()))
  627. {
  628. cmCPackLogger(cmCPackLog::LOG_ERROR,
  629. "Problem creating temporary directory: "
  630. << dir << std::endl);
  631. return 0;
  632. }
  633. }
  634. else
  635. {
  636. mf->AddDefinition("CMAKE_INSTALL_PREFIX",
  637. tempInstallDirectory.c_str());
  638. if ( !cmsys::SystemTools::MakeDirectory(
  639. tempInstallDirectory.c_str()))
  640. {
  641. cmCPackLogger(cmCPackLog::LOG_ERROR,
  642. "Problem creating temporary directory: "
  643. << tempInstallDirectory << std::endl);
  644. return 0;
  645. }
  646. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  647. "- Using non-DESTDIR install... (mf->AddDefinition)"
  648. << std::endl);
  649. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  650. "- Setting CMAKE_INSTALL_PREFIX to '"
  651. << tempInstallDirectory
  652. << "'" << std::endl);
  653. }
  654. if ( buildConfig && *buildConfig )
  655. {
  656. mf->AddDefinition("BUILD_TYPE", buildConfig);
  657. }
  658. std::string installComponentLowerCase
  659. = cmSystemTools::LowerCase(installComponent);
  660. if ( installComponentLowerCase != "all" )
  661. {
  662. mf->AddDefinition("CMAKE_INSTALL_COMPONENT",
  663. installComponent.c_str());
  664. }
  665. // strip on TRUE, ON, 1, one or several file names, but not on
  666. // FALSE, OFF, 0 and an empty string
  667. if (!cmSystemTools::IsOff(this->GetOption("CPACK_STRIP_FILES")))
  668. {
  669. mf->AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  670. }
  671. int res = mf->ReadListFile(0, installFile.c_str());
  672. if ( cmSystemTools::GetErrorOccuredFlag() || !res )
  673. {
  674. return 0;
  675. }
  676. }
  677. }
  678. }
  679. return 1;
  680. }
  681. //----------------------------------------------------------------------
  682. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  683. {
  684. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  685. return this->MakefileMap->ReadListFile(0, fullPath.c_str());
  686. }
  687. //----------------------------------------------------------------------
  688. void cmCPackGenerator::SetOptionIfNotSet(const char* op,
  689. const char* value)
  690. {
  691. const char* def = this->MakefileMap->GetDefinition(op);
  692. if ( def && *def )
  693. {
  694. return;
  695. }
  696. this->SetOption(op, value);
  697. }
  698. //----------------------------------------------------------------------
  699. void cmCPackGenerator::SetOption(const char* op, const char* value)
  700. {
  701. if ( !op )
  702. {
  703. return;
  704. }
  705. if ( !value )
  706. {
  707. this->MakefileMap->RemoveDefinition(op);
  708. return;
  709. }
  710. cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
  711. << "::SetOption(" << op << ", " << value << ")" << std::endl);
  712. this->MakefileMap->AddDefinition(op, value);
  713. }
  714. //----------------------------------------------------------------------
  715. int cmCPackGenerator::DoPackage()
  716. {
  717. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  718. "Create package using " << this->Name.c_str() << std::endl);
  719. if ( !this->PrepareNames() )
  720. {
  721. return 0;
  722. }
  723. if ( cmSystemTools::IsOn(
  724. this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY")) )
  725. {
  726. const char* toplevelDirectory
  727. = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  728. if ( cmSystemTools::FileExists(toplevelDirectory) )
  729. {
  730. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  731. "Remove toplevel directory: "
  732. << toplevelDirectory << std::endl);
  733. if ( !cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory) )
  734. {
  735. cmCPackLogger(cmCPackLog::LOG_ERROR,
  736. "Problem removing toplevel directory: "
  737. << toplevelDirectory
  738. << std::endl);
  739. return 0;
  740. }
  741. }
  742. }
  743. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  744. "About to install project " << std::endl);
  745. if ( !this->InstallProject() )
  746. {
  747. return 0;
  748. }
  749. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  750. "Done install project " << std::endl);
  751. const char* tempPackageFileName = this->GetOption(
  752. "CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  753. const char* packageFileName = this->GetOption("CPACK_OUTPUT_FILE_PATH");
  754. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  755. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  756. cmsys::Glob gl;
  757. std::string findExpr = tempDirectory;
  758. findExpr += "/*";
  759. gl.RecurseOn();
  760. if ( !gl.FindFiles(findExpr) )
  761. {
  762. cmCPackLogger(cmCPackLog::LOG_ERROR,
  763. "Cannot find any files in the packaging tree" << std::endl);
  764. return 0;
  765. }
  766. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
  767. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Package files to: "
  768. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << std::endl);
  769. if ( cmSystemTools::FileExists(tempPackageFileName) )
  770. {
  771. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove old package file"
  772. << std::endl);
  773. cmSystemTools::RemoveFile(tempPackageFileName);
  774. }
  775. if ( cmSystemTools::IsOn(this->GetOption(
  776. "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
  777. {
  778. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  779. }
  780. // The files to be installed
  781. files = gl.GetFiles();
  782. // For component installations, determine which files go into which
  783. // components.
  784. if (!this->Components.empty())
  785. {
  786. std::vector<std::string>::const_iterator it;
  787. for ( it = files.begin(); it != files.end(); ++ it )
  788. {
  789. // beware we cannot just use tempDirectory as before
  790. // because some generator will "CPACK_INCLUDE_TOPLEVEL_DIRECTORY"
  791. // we really want "CPACK_TEMPORARY_DIRECTORY"
  792. std::string fileN = cmSystemTools::RelativePath(this->GetOption("CPACK_TEMPORARY_DIRECTORY"),
  793. it->c_str());
  794. // Determine which component we are in.
  795. std::string componentName = fileN.substr(0, fileN.find('/'));
  796. // Strip off the component part of the path.
  797. fileN = fileN.substr(fileN.find('/')+1, std::string::npos);
  798. // Add this file to the list of files for the component.
  799. this->Components[componentName].Files.push_back(fileN);
  800. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <" <<fileN<<"> to component <"<<componentName<<">"<<std::endl);
  801. }
  802. }
  803. packageFileNames.clear();
  804. /* Put at least one file name into the list of
  805. * wanted packageFileNames. The specific generator
  806. * may update this during PackageFiles.
  807. * (either putting several names or updating the provided one)
  808. */
  809. packageFileNames.push_back(tempPackageFileName);
  810. toplevel = tempDirectory;
  811. if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag())
  812. {
  813. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
  814. << std::endl);
  815. return 0;
  816. }
  817. /*
  818. * Copy the generated packages to final destination
  819. * - there may be several of them
  820. * - the initially provided name may have changed
  821. * (because the specific generator did 'normalize' it)
  822. */
  823. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Copying final package(s) ["
  824. <<packageFileNames.size()
  825. <<"]:"<<std::endl);
  826. std::vector<std::string>::iterator it;
  827. /* now copy package one by one */
  828. for (it=packageFileNames.begin();it!=packageFileNames.end();++it)
  829. {
  830. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  831. tempPackageFileName = it->c_str();
  832. tmpPF += "/"+cmSystemTools::GetFilenameName(*it);
  833. packageFileName = tmpPF.c_str();
  834. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): "
  835. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  836. << " to "
  837. << (packageFileName ? packageFileName : "(NULL)")
  838. << std::endl);
  839. if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
  840. packageFileName) )
  841. {
  842. cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: "
  843. << (tempPackageFileName ? tempPackageFileName : "(NULL)" )
  844. << " to "
  845. << (packageFileName ? packageFileName : "(NULL)")
  846. << std::endl);
  847. return 0;
  848. }
  849. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- package: "
  850. << packageFileName
  851. << " generated." << std::endl);
  852. }
  853. return 1;
  854. }
  855. //----------------------------------------------------------------------
  856. int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf)
  857. {
  858. this->MakefileMap = mf;
  859. this->Name = name;
  860. if ( !this->SetCMakeRoot() )
  861. {
  862. cmCPackLogger(cmCPackLog::LOG_ERROR,
  863. "Cannot initialize the generator" << std::endl);
  864. return 0;
  865. }
  866. // set the running generator name
  867. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  868. // Load the project specific config file
  869. const char* config =
  870. this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  871. if(config)
  872. {
  873. mf->ReadListFile(config);
  874. }
  875. int result = this->InitializeInternal();
  876. if (cmSystemTools::GetErrorOccuredFlag())
  877. {
  878. return 0;
  879. }
  880. // If a generator subclass did not already set this option in its
  881. // InitializeInternal implementation, and the project did not already set
  882. // it, the default value should be:
  883. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  884. return result;
  885. }
  886. //----------------------------------------------------------------------
  887. int cmCPackGenerator::InitializeInternal()
  888. {
  889. return 1;
  890. }
  891. //----------------------------------------------------------------------
  892. bool cmCPackGenerator::IsSet(const char* name) const
  893. {
  894. return this->MakefileMap->IsSet(name);
  895. }
  896. //----------------------------------------------------------------------
  897. const char* cmCPackGenerator::GetOption(const char* op)
  898. {
  899. const char* ret = this->MakefileMap->GetDefinition(op);
  900. if(!ret)
  901. {
  902. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  903. "Warning, GetOption return NULL for: "
  904. << op
  905. << std::endl);
  906. }
  907. return ret;
  908. }
  909. //----------------------------------------------------------------------
  910. int cmCPackGenerator::SetCMakeRoot()
  911. {
  912. // use the CMAKE_ROOT from cmake which should have been
  913. // found by now
  914. const char* root=
  915. this->MakefileMap->GetDefinition("CMAKE_ROOT");
  916. if(root)
  917. {
  918. this->CMakeRoot = root;
  919. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Looking for CMAKE_ROOT: "
  920. << this->CMakeRoot.c_str() << std::endl);
  921. this->SetOption("CMAKE_ROOT", this->CMakeRoot.c_str());
  922. return 1;
  923. }
  924. cmCPackLogger(cmCPackLog::LOG_ERROR,
  925. "Could not find CMAKE_ROOT !!!"
  926. << std::endl
  927. << "CMake has most likely not been installed correctly."
  928. << std::endl
  929. <<"Modules directory not found in"
  930. << std::endl);
  931. return 0;
  932. }
  933. //----------------------------------------------------------------------
  934. int cmCPackGenerator::PackageFiles()
  935. {
  936. return 0;
  937. }
  938. //----------------------------------------------------------------------
  939. const char* cmCPackGenerator::GetInstallPath()
  940. {
  941. if ( !this->InstallPath.empty() )
  942. {
  943. return this->InstallPath.c_str();
  944. }
  945. #if defined(_WIN32) && !defined(__CYGWIN__)
  946. const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
  947. const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
  948. if ( prgfiles )
  949. {
  950. this->InstallPath = prgfiles;
  951. }
  952. else if ( sysDrive )
  953. {
  954. this->InstallPath = sysDrive;
  955. this->InstallPath += "/Program Files";
  956. }
  957. else
  958. {
  959. this->InstallPath = "c:/Program Files";
  960. }
  961. this->InstallPath += "/";
  962. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  963. this->InstallPath += "-";
  964. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  965. #elif defined(__HAIKU__)
  966. BPath dir;
  967. if (find_directory(B_COMMON_DIRECTORY, &dir) == B_OK)
  968. {
  969. this->InstallPath = dir.Path();
  970. }
  971. else
  972. {
  973. this->InstallPath = "/boot/common";
  974. }
  975. #else
  976. this->InstallPath = "/usr/local/";
  977. #endif
  978. return this->InstallPath.c_str();
  979. }
  980. //----------------------------------------------------------------------
  981. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  982. {
  983. cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
  984. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'" << std::endl);
  985. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  986. }
  987. //----------------------------------------------------------------------
  988. std::string cmCPackGenerator::FindTemplate(const char* name)
  989. {
  990. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
  991. << (name ? name : "(NULL)") << std::endl);
  992. std::string ffile = this->MakefileMap->GetModulesFile(name);
  993. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Found template: "
  994. << ffile.c_str() << std::endl);
  995. return ffile;
  996. }
  997. //----------------------------------------------------------------------
  998. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  999. std::string& outString)
  1000. {
  1001. this->MakefileMap->ConfigureString(inString,
  1002. outString, true, false);
  1003. return true;
  1004. }
  1005. //----------------------------------------------------------------------
  1006. bool cmCPackGenerator::ConfigureFile(const char* inName,
  1007. const char* outName, bool copyOnly /* = false */)
  1008. {
  1009. return this->MakefileMap->ConfigureFile(inName, outName,
  1010. copyOnly, true, false) == 1;
  1011. }
  1012. //----------------------------------------------------------------------
  1013. int cmCPackGenerator::CleanTemporaryDirectory()
  1014. {
  1015. std::string tempInstallDirectoryWithPostfix
  1016. = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1017. const char* tempInstallDirectory = tempInstallDirectoryWithPostfix.c_str();
  1018. if(cmsys::SystemTools::FileExists(tempInstallDirectory))
  1019. {
  1020. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1021. "- Clean temporary : "
  1022. << tempInstallDirectory << std::endl);
  1023. if(!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory))
  1024. {
  1025. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1026. "Problem removing temporary directory: " <<
  1027. tempInstallDirectory
  1028. << std::endl);
  1029. return 0;
  1030. }
  1031. }
  1032. return 1;
  1033. }
  1034. //----------------------------------------------------------------------
  1035. bool cmCPackGenerator::SupportsComponentInstallation() const
  1036. {
  1037. return false;
  1038. }
  1039. //----------------------------------------------------------------------
  1040. cmCPackInstallationType*
  1041. cmCPackGenerator::GetInstallationType(const char *projectName,
  1042. const char *name)
  1043. {
  1044. (void) projectName;
  1045. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1046. cmCPackInstallationType *installType = &this->InstallationTypes[name];
  1047. if (!hasInstallationType)
  1048. {
  1049. // Define the installation type
  1050. std::string macroPrefix = "CPACK_INSTALL_TYPE_"
  1051. + cmsys::SystemTools::UpperCase(name);
  1052. installType->Name = name;
  1053. const char* displayName
  1054. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1055. if (displayName && *displayName)
  1056. {
  1057. installType->DisplayName = displayName;
  1058. }
  1059. else
  1060. {
  1061. installType->DisplayName = installType->Name;
  1062. }
  1063. installType->Index = static_cast<unsigned>(
  1064. this->InstallationTypes.size());
  1065. }
  1066. return installType;
  1067. }
  1068. //----------------------------------------------------------------------
  1069. cmCPackComponent*
  1070. cmCPackGenerator::GetComponent(const char *projectName, const char *name)
  1071. {
  1072. bool hasComponent = this->Components.count(name) != 0;
  1073. cmCPackComponent *component = &this->Components[name];
  1074. if (!hasComponent)
  1075. {
  1076. // Define the component
  1077. std::string macroPrefix = "CPACK_COMPONENT_"
  1078. + cmsys::SystemTools::UpperCase(name);
  1079. component->Name = name;
  1080. const char* displayName
  1081. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1082. if (displayName && *displayName)
  1083. {
  1084. component->DisplayName = displayName;
  1085. }
  1086. else
  1087. {
  1088. component->DisplayName = component->Name;
  1089. }
  1090. component->IsHidden
  1091. = this->IsSet((macroPrefix + "_HIDDEN").c_str());
  1092. component->IsRequired
  1093. = this->IsSet((macroPrefix + "_REQUIRED").c_str());
  1094. component->IsDisabledByDefault
  1095. = this->IsSet((macroPrefix + "_DISABLED").c_str());
  1096. component->IsDownloaded
  1097. = this->IsSet((macroPrefix + "_DOWNLOADED").c_str())
  1098. || cmSystemTools::IsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1099. const char* archiveFile = this->GetOption((macroPrefix +
  1100. "_ARCHIVE_FILE").c_str());
  1101. if (archiveFile && *archiveFile)
  1102. {
  1103. component->ArchiveFile = archiveFile;
  1104. }
  1105. const char* groupName = this->GetOption((macroPrefix + "_GROUP").c_str());
  1106. if (groupName && *groupName)
  1107. {
  1108. component->Group = GetComponentGroup(projectName, groupName);
  1109. component->Group->Components.push_back(component);
  1110. }
  1111. else
  1112. {
  1113. component->Group = 0;
  1114. }
  1115. const char* description
  1116. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1117. if (description && *description)
  1118. {
  1119. component->Description = description;
  1120. }
  1121. // Determine the installation types.
  1122. const char *installTypes
  1123. = this->GetOption((macroPrefix + "_INSTALL_TYPES").c_str());
  1124. if (installTypes && *installTypes)
  1125. {
  1126. std::vector<std::string> installTypesVector;
  1127. cmSystemTools::ExpandListArgument(installTypes, installTypesVector);
  1128. std::vector<std::string>::iterator installTypesIt;
  1129. for (installTypesIt = installTypesVector.begin();
  1130. installTypesIt != installTypesVector.end();
  1131. ++installTypesIt)
  1132. {
  1133. component->InstallationTypes.push_back(
  1134. this->GetInstallationType(projectName, installTypesIt->c_str()));
  1135. }
  1136. }
  1137. // Determine the component dependencies.
  1138. const char *depends = this->GetOption((macroPrefix + "_DEPENDS").c_str());
  1139. if (depends && *depends)
  1140. {
  1141. std::vector<std::string> dependsVector;
  1142. cmSystemTools::ExpandListArgument(depends, dependsVector);
  1143. std::vector<std::string>::iterator dependIt;
  1144. for (dependIt = dependsVector.begin();
  1145. dependIt != dependsVector.end();
  1146. ++dependIt)
  1147. {
  1148. cmCPackComponent *child = GetComponent(projectName,
  1149. dependIt->c_str());
  1150. component->Dependencies.push_back(child);
  1151. child->ReverseDependencies.push_back(component);
  1152. }
  1153. }
  1154. }
  1155. return component;
  1156. }
  1157. //----------------------------------------------------------------------
  1158. cmCPackComponentGroup*
  1159. cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
  1160. {
  1161. (void) projectName;
  1162. std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
  1163. + cmsys::SystemTools::UpperCase(name);
  1164. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1165. cmCPackComponentGroup *group = &this->ComponentGroups[name];
  1166. if (!hasGroup)
  1167. {
  1168. // Define the group
  1169. group->Name = name;
  1170. const char* displayName
  1171. = this->GetOption((macroPrefix + "_DISPLAY_NAME").c_str());
  1172. if (displayName && *displayName)
  1173. {
  1174. group->DisplayName = displayName;
  1175. }
  1176. else
  1177. {
  1178. group->DisplayName = group->Name;
  1179. }
  1180. const char* description
  1181. = this->GetOption((macroPrefix + "_DESCRIPTION").c_str());
  1182. if (description && *description)
  1183. {
  1184. group->Description = description;
  1185. }
  1186. group->IsBold
  1187. = this->IsSet((macroPrefix + "_BOLD_TITLE").c_str());
  1188. group->IsExpandedByDefault
  1189. = this->IsSet((macroPrefix + "_EXPANDED").c_str());
  1190. const char* parentGroupName
  1191. = this->GetOption((macroPrefix + "_PARENT_GROUP").c_str());
  1192. if (parentGroupName && *parentGroupName)
  1193. {
  1194. group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
  1195. group->ParentGroup->Subgroups.push_back(group);
  1196. }
  1197. else
  1198. {
  1199. group->ParentGroup = 0;
  1200. }
  1201. }
  1202. return group;
  1203. }