cmCPackGenerator.cxx 42 KB

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