cmCPackGenerator.cxx 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCPackGenerator.h"
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <memory>
  7. #include <utility>
  8. #include "cmsys/FStream.hxx"
  9. #include "cmsys/Glob.hxx"
  10. #include "cmsys/RegularExpression.hxx"
  11. #include "cmCPackComponentGroup.h"
  12. #include "cmCPackLog.h"
  13. #include "cmCryptoHash.h"
  14. #include "cmDuration.h"
  15. #include "cmFSPermissions.h"
  16. #include "cmFileTimes.h"
  17. #include "cmGeneratedFileStream.h"
  18. #include "cmGlobalGenerator.h"
  19. #include "cmMakefile.h"
  20. #include "cmProperty.h"
  21. #include "cmState.h"
  22. #include "cmStateSnapshot.h"
  23. #include "cmStringAlgorithms.h"
  24. #include "cmSystemTools.h"
  25. #include "cmVersion.h"
  26. #include "cmWorkingDirectory.h"
  27. #include "cmXMLSafe.h"
  28. #include "cmake.h"
  29. #if defined(__HAIKU__)
  30. # include <FindDirectory.h>
  31. # include <StorageDefs.h>
  32. #endif
  33. cmCPackGenerator::cmCPackGenerator()
  34. {
  35. this->GeneratorVerbose = cmSystemTools::OUTPUT_NONE;
  36. this->MakefileMap = nullptr;
  37. this->Logger = nullptr;
  38. this->componentPackageMethod = ONE_PACKAGE_PER_GROUP;
  39. }
  40. cmCPackGenerator::~cmCPackGenerator()
  41. {
  42. this->MakefileMap = nullptr;
  43. }
  44. void cmCPackGenerator::DisplayVerboseOutput(const std::string& msg,
  45. float progress)
  46. {
  47. (void)progress;
  48. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
  49. }
  50. int cmCPackGenerator::PrepareNames()
  51. {
  52. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Create temp directory." << std::endl);
  53. // checks CPACK_SET_DESTDIR support
  54. if (this->IsOn("CPACK_SET_DESTDIR")) {
  55. if (SETDESTDIR_UNSUPPORTED == this->SupportsSetDestdir()) {
  56. cmCPackLogger(cmCPackLog::LOG_ERROR,
  57. "CPACK_SET_DESTDIR is set to ON but the '"
  58. << this->Name << "' generator does NOT support it."
  59. << std::endl);
  60. return 0;
  61. }
  62. if (SETDESTDIR_SHOULD_NOT_BE_USED == this->SupportsSetDestdir()) {
  63. cmCPackLogger(cmCPackLog::LOG_WARNING,
  64. "CPACK_SET_DESTDIR is set to ON but it is "
  65. << "usually a bad idea to do that with '" << this->Name
  66. << "' generator. Use at your own risk." << std::endl);
  67. }
  68. }
  69. std::string tempDirectory =
  70. cmStrCat(this->GetOption("CPACK_PACKAGE_DIRECTORY"), "/_CPack_Packages/");
  71. const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
  72. if (toplevelTag) {
  73. tempDirectory += toplevelTag;
  74. tempDirectory += "/";
  75. }
  76. tempDirectory += this->GetOption("CPACK_GENERATOR");
  77. std::string topDirectory = tempDirectory;
  78. const char* pfname = this->GetOption("CPACK_PACKAGE_FILE_NAME");
  79. if (!pfname) {
  80. cmCPackLogger(cmCPackLog::LOG_ERROR,
  81. "CPACK_PACKAGE_FILE_NAME not specified" << std::endl);
  82. return 0;
  83. }
  84. std::string outName = pfname;
  85. tempDirectory += "/" + outName;
  86. if (!this->GetOutputExtension()) {
  87. cmCPackLogger(cmCPackLog::LOG_ERROR,
  88. "No output extension specified" << std::endl);
  89. return 0;
  90. }
  91. outName += this->GetOutputExtension();
  92. const char* pdir = this->GetOption("CPACK_PACKAGE_DIRECTORY");
  93. if (!pdir) {
  94. cmCPackLogger(cmCPackLog::LOG_ERROR,
  95. "CPACK_PACKAGE_DIRECTORY not specified" << std::endl);
  96. return 0;
  97. }
  98. std::string destFile = pdir;
  99. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PREFIX", destFile.c_str());
  100. destFile += "/" + outName;
  101. std::string outFile = topDirectory + "/" + outName;
  102. this->SetOptionIfNotSet("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
  103. this->SetOptionIfNotSet("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
  104. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_NAME", outName.c_str());
  105. this->SetOptionIfNotSet("CPACK_OUTPUT_FILE_PATH", destFile.c_str());
  106. this->SetOptionIfNotSet("CPACK_TEMPORARY_PACKAGE_FILE_NAME",
  107. outFile.c_str());
  108. this->SetOptionIfNotSet("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
  109. this->SetOptionIfNotSet(
  110. "CPACK_NATIVE_INSTALL_DIRECTORY",
  111. cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
  112. this->SetOptionIfNotSet("CPACK_TEMPORARY_INSTALL_DIRECTORY",
  113. tempDirectory.c_str());
  114. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  115. "Look for: CPACK_PACKAGE_DESCRIPTION_FILE" << std::endl);
  116. const char* descFileName = this->GetOption("CPACK_PACKAGE_DESCRIPTION_FILE");
  117. if (descFileName && !this->GetOption("CPACK_PACKAGE_DESCRIPTION")) {
  118. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  119. "Look for: " << descFileName << std::endl);
  120. if (!cmSystemTools::FileExists(descFileName)) {
  121. cmCPackLogger(cmCPackLog::LOG_ERROR,
  122. "Cannot find description file name: ["
  123. << descFileName << "]" << std::endl);
  124. return 0;
  125. }
  126. cmsys::ifstream ifs(descFileName);
  127. if (!ifs) {
  128. cmCPackLogger(cmCPackLog::LOG_ERROR,
  129. "Cannot open description file name: " << descFileName
  130. << std::endl);
  131. return 0;
  132. }
  133. std::ostringstream ostr;
  134. std::string line;
  135. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  136. "Read description file: " << descFileName << std::endl);
  137. while (ifs && cmSystemTools::GetLineFromStream(ifs, line)) {
  138. ostr << cmXMLSafe(line) << std::endl;
  139. }
  140. this->SetOption("CPACK_PACKAGE_DESCRIPTION", ostr.str().c_str());
  141. const char* defFileName =
  142. this->GetOption("CPACK_DEFAULT_PACKAGE_DESCRIPTION_FILE");
  143. if (defFileName && !strcmp(defFileName, descFileName)) {
  144. this->SetOption("CPACK_USED_DEFAULT_PACKAGE_DESCRIPTION_FILE", "ON");
  145. }
  146. }
  147. if (!this->GetOption("CPACK_PACKAGE_DESCRIPTION")) {
  148. cmCPackLogger(
  149. cmCPackLog::LOG_ERROR,
  150. "Project description not specified. Please specify "
  151. "CPACK_PACKAGE_DESCRIPTION or CPACK_PACKAGE_DESCRIPTION_FILE."
  152. << std::endl);
  153. return 0;
  154. }
  155. const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM");
  156. if (algoSignature) {
  157. if (!cmCryptoHash::New(algoSignature)) {
  158. cmCPackLogger(cmCPackLog::LOG_ERROR,
  159. "Cannot recognize algorithm: " << algoSignature
  160. << std::endl);
  161. return 0;
  162. }
  163. }
  164. this->SetOptionIfNotSet("CPACK_REMOVE_TOPLEVEL_DIRECTORY", "1");
  165. return 1;
  166. }
  167. int cmCPackGenerator::InstallProject()
  168. {
  169. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
  170. this->CleanTemporaryDirectory();
  171. std::string bareTempInstallDirectory =
  172. this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  173. std::string tempInstallDirectoryStr = bareTempInstallDirectory;
  174. bool setDestDir = cmIsOn(this->GetOption("CPACK_SET_DESTDIR")) |
  175. cmIsInternallyOn(this->GetOption("CPACK_SET_DESTDIR"));
  176. if (!setDestDir) {
  177. tempInstallDirectoryStr += this->GetPackagingInstallPrefix();
  178. }
  179. const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
  180. int res = 1;
  181. if (!cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory)) {
  182. cmCPackLogger(cmCPackLog::LOG_ERROR,
  183. "Problem creating temporary directory: "
  184. << (tempInstallDirectory ? tempInstallDirectory : "(NULL)")
  185. << std::endl);
  186. return 0;
  187. }
  188. if (setDestDir) {
  189. std::string destDir = cmStrCat("DESTDIR=", tempInstallDirectory);
  190. cmSystemTools::PutEnv(destDir);
  191. } else {
  192. // Make sure there is no destdir
  193. cmSystemTools::PutEnv("DESTDIR=");
  194. }
  195. // prepare default created directory permissions
  196. mode_t default_dir_mode_v = 0;
  197. mode_t* default_dir_mode = nullptr;
  198. const char* default_dir_install_permissions =
  199. this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
  200. if (cmNonempty(default_dir_install_permissions)) {
  201. std::vector<std::string> items =
  202. cmExpandedList(default_dir_install_permissions);
  203. for (const auto& arg : items) {
  204. if (!cmFSPermissions::stringToModeT(arg, default_dir_mode_v)) {
  205. cmCPackLogger(cmCPackLog::LOG_ERROR,
  206. "Invalid permission value '"
  207. << arg
  208. << "'."
  209. " CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS "
  210. "value is invalid."
  211. << std::endl);
  212. return 0;
  213. }
  214. }
  215. default_dir_mode = &default_dir_mode_v;
  216. }
  217. // If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
  218. // as listed
  219. if (!this->InstallProjectViaInstallCommands(setDestDir,
  220. tempInstallDirectory)) {
  221. return 0;
  222. }
  223. // If the CPackConfig file sets CPACK_INSTALL_SCRIPT(S) then run them
  224. // as listed
  225. if (!this->InstallProjectViaInstallScript(setDestDir,
  226. tempInstallDirectory)) {
  227. return 0;
  228. }
  229. // If the CPackConfig file sets CPACK_INSTALLED_DIRECTORIES
  230. // then glob it and copy it to CPACK_TEMPORARY_DIRECTORY
  231. // This is used in Source packaging
  232. if (!this->InstallProjectViaInstalledDirectories(
  233. setDestDir, tempInstallDirectory, default_dir_mode)) {
  234. return 0;
  235. }
  236. // If the project is a CMAKE project then run pre-install
  237. // and then read the cmake_install script to run it
  238. if (!this->InstallProjectViaInstallCMakeProjects(
  239. setDestDir, bareTempInstallDirectory, default_dir_mode)) {
  240. return 0;
  241. }
  242. // Run pre-build actions
  243. const char* preBuildScripts = this->GetOption("CPACK_PRE_BUILD_SCRIPTS");
  244. if (preBuildScripts) {
  245. const auto scripts = cmExpandedList(preBuildScripts, false);
  246. for (const auto& script : scripts) {
  247. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  248. "Executing pre-build script: " << script << std::endl);
  249. if (!this->MakefileMap->ReadListFile(script)) {
  250. cmCPackLogger(cmCPackLog::LOG_ERROR,
  251. "The pre-build script not found: " << script
  252. << std::endl);
  253. return 0;
  254. }
  255. }
  256. }
  257. if (setDestDir) {
  258. cmSystemTools::PutEnv("DESTDIR=");
  259. }
  260. return res;
  261. }
  262. int cmCPackGenerator::InstallProjectViaInstallCommands(
  263. bool setDestDir, const std::string& tempInstallDirectory)
  264. {
  265. (void)setDestDir;
  266. const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
  267. if (cmNonempty(installCommands)) {
  268. std::string tempInstallDirectoryEnv =
  269. cmStrCat("CMAKE_INSTALL_PREFIX=", tempInstallDirectory);
  270. cmSystemTools::PutEnv(tempInstallDirectoryEnv);
  271. std::vector<std::string> installCommandsVector =
  272. cmExpandedList(installCommands);
  273. for (std::string const& ic : installCommandsVector) {
  274. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ic << std::endl);
  275. std::string output;
  276. int retVal = 1;
  277. bool resB = cmSystemTools::RunSingleCommand(
  278. ic, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
  279. cmDuration::zero());
  280. if (!resB || retVal) {
  281. std::string tmpFile = cmStrCat(
  282. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/InstallOutput.log");
  283. cmGeneratedFileStream ofs(tmpFile);
  284. ofs << "# Run command: " << ic << std::endl
  285. << "# Output:" << std::endl
  286. << output << std::endl;
  287. cmCPackLogger(cmCPackLog::LOG_ERROR,
  288. "Problem running install command: "
  289. << ic << std::endl
  290. << "Please check " << tmpFile << " for errors"
  291. << std::endl);
  292. return 0;
  293. }
  294. }
  295. }
  296. return 1;
  297. }
  298. int cmCPackGenerator::InstallProjectViaInstalledDirectories(
  299. bool setDestDir, const std::string& tempInstallDirectory,
  300. const mode_t* default_dir_mode)
  301. {
  302. (void)setDestDir;
  303. (void)tempInstallDirectory;
  304. std::vector<cmsys::RegularExpression> ignoreFilesRegex;
  305. const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
  306. if (cpackIgnoreFiles) {
  307. std::vector<std::string> ignoreFilesRegexString =
  308. cmExpandedList(cpackIgnoreFiles);
  309. for (std::string const& ifr : ignoreFilesRegexString) {
  310. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  311. "Create ignore files regex for: " << ifr << std::endl);
  312. ignoreFilesRegex.emplace_back(ifr);
  313. }
  314. }
  315. const char* installDirectories =
  316. this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  317. if (cmNonempty(installDirectories)) {
  318. std::vector<std::string> installDirectoriesVector =
  319. cmExpandedList(installDirectories);
  320. if (installDirectoriesVector.size() % 2 != 0) {
  321. cmCPackLogger(
  322. cmCPackLog::LOG_ERROR,
  323. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> "
  324. "and "
  325. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  326. "the toplevel directory of installation."
  327. << std::endl);
  328. return 0;
  329. }
  330. std::vector<std::string>::iterator it;
  331. const std::string& tempDir = tempInstallDirectory;
  332. for (it = installDirectoriesVector.begin();
  333. it != installDirectoriesVector.end(); ++it) {
  334. std::vector<std::pair<std::string, std::string>> symlinkedFiles;
  335. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  336. cmsys::Glob gl;
  337. std::string top = *it;
  338. it++;
  339. std::string subdir = *it;
  340. std::string findExpr = cmStrCat(top, "/*");
  341. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  342. "- Install directory: " << top << std::endl);
  343. gl.RecurseOn();
  344. gl.SetRecurseListDirs(true);
  345. gl.SetRecurseThroughSymlinks(false);
  346. if (!gl.FindFiles(findExpr)) {
  347. cmCPackLogger(cmCPackLog::LOG_ERROR,
  348. "Cannot find any files in the installed directory"
  349. << std::endl);
  350. return 0;
  351. }
  352. this->files = gl.GetFiles();
  353. for (std::string const& gf : this->files) {
  354. bool skip = false;
  355. std::string inFile = gf;
  356. if (cmSystemTools::FileIsDirectory(gf)) {
  357. inFile += '/';
  358. }
  359. for (cmsys::RegularExpression& reg : ignoreFilesRegex) {
  360. if (reg.find(inFile)) {
  361. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  362. "Ignore file: " << inFile << std::endl);
  363. skip = true;
  364. }
  365. }
  366. if (skip) {
  367. continue;
  368. }
  369. std::string filePath = cmStrCat(tempDir, '/', subdir, '/',
  370. cmSystemTools::RelativePath(top, gf));
  371. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  372. "Copy file: " << inFile << " -> " << filePath
  373. << std::endl);
  374. /* If the file is a symlink we will have to re-create it */
  375. if (cmSystemTools::FileIsSymlink(inFile)) {
  376. std::string targetFile;
  377. std::string inFileRelative =
  378. cmSystemTools::RelativePath(top, inFile);
  379. cmSystemTools::ReadSymlink(inFile, targetFile);
  380. symlinkedFiles.emplace_back(std::move(targetFile),
  381. std::move(inFileRelative));
  382. }
  383. /* If it is not a symlink then do a plain copy */
  384. else if (!(cmSystemTools::CopyFileIfDifferent(inFile, filePath) &&
  385. cmFileTimes::Copy(inFile, filePath))) {
  386. cmCPackLogger(cmCPackLog::LOG_ERROR,
  387. "Problem copying file: " << inFile << " -> "
  388. << filePath << std::endl);
  389. return 0;
  390. }
  391. }
  392. /* rebuild symlinks in the installed tree */
  393. if (!symlinkedFiles.empty()) {
  394. std::string goToDir = cmStrCat(tempDir, '/', subdir);
  395. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  396. "Change dir to: " << goToDir << std::endl);
  397. cmWorkingDirectory workdir(goToDir);
  398. if (workdir.Failed()) {
  399. cmCPackLogger(cmCPackLog::LOG_ERROR,
  400. "Failed to change working directory to "
  401. << goToDir << " : "
  402. << std::strerror(workdir.GetLastResult())
  403. << std::endl);
  404. return 0;
  405. }
  406. for (auto const& symlinked : symlinkedFiles) {
  407. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  408. "Will create a symlink: " << symlinked.second << "--> "
  409. << symlinked.first
  410. << std::endl);
  411. // make sure directory exists for symlink
  412. std::string destDir =
  413. cmSystemTools::GetFilenamePath(symlinked.second);
  414. if (!destDir.empty() &&
  415. !cmSystemTools::MakeDirectory(destDir, default_dir_mode)) {
  416. cmCPackLogger(cmCPackLog::LOG_ERROR,
  417. "Cannot create dir: "
  418. << destDir << "\nTrying to create symlink: "
  419. << symlinked.second << "--> " << symlinked.first
  420. << std::endl);
  421. }
  422. if (!cmSystemTools::CreateSymlink(symlinked.first,
  423. symlinked.second)) {
  424. cmCPackLogger(cmCPackLog::LOG_ERROR,
  425. "Cannot create symlink: "
  426. << symlinked.second << "--> " << symlinked.first
  427. << std::endl);
  428. return 0;
  429. }
  430. }
  431. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  432. "Going back to: " << workdir.GetOldDirectory()
  433. << std::endl);
  434. }
  435. }
  436. }
  437. return 1;
  438. }
  439. int cmCPackGenerator::InstallProjectViaInstallScript(
  440. bool setDestDir, const std::string& tempInstallDirectory)
  441. {
  442. const char* cmakeScripts = this->GetOption("CPACK_INSTALL_SCRIPTS");
  443. {
  444. const char* const cmakeScript = this->GetOption("CPACK_INSTALL_SCRIPT");
  445. if (cmakeScript && cmakeScripts) {
  446. cmCPackLogger(
  447. cmCPackLog::LOG_WARNING,
  448. "Both CPACK_INSTALL_SCRIPTS and CPACK_INSTALL_SCRIPT are set, "
  449. "the latter will be ignored."
  450. << std::endl);
  451. } else if (cmakeScript && !cmakeScripts) {
  452. cmakeScripts = cmakeScript;
  453. }
  454. }
  455. if (cmakeScripts && *cmakeScripts) {
  456. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  457. "- Install scripts: " << cmakeScripts << std::endl);
  458. std::vector<std::string> cmakeScriptsVector = cmExpandedList(cmakeScripts);
  459. for (std::string const& installScript : cmakeScriptsVector) {
  460. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  461. "- Install script: " << installScript << std::endl);
  462. if (setDestDir) {
  463. // For DESTDIR based packaging, use the *project*
  464. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  465. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as the
  466. // value of the CPACK_INSTALL_PREFIX variable.
  467. std::string dir;
  468. if (this->GetOption("CPACK_INSTALL_PREFIX")) {
  469. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  470. }
  471. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  472. cmCPackLogger(
  473. cmCPackLog::LOG_DEBUG,
  474. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  475. << std::endl);
  476. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  477. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  478. << std::endl);
  479. } else {
  480. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
  481. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  482. "- Using non-DESTDIR install... (this->SetOption)"
  483. << std::endl);
  484. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  485. "- Setting CMAKE_INSTALL_PREFIX to '"
  486. << tempInstallDirectory << "'" << std::endl);
  487. }
  488. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  489. tempInstallDirectory.c_str());
  490. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  491. tempInstallDirectory.c_str());
  492. bool res = this->MakefileMap->ReadListFile(installScript);
  493. if (cmSystemTools::GetErrorOccuredFlag() || !res) {
  494. return 0;
  495. }
  496. }
  497. }
  498. return 1;
  499. }
  500. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  501. bool setDestDir, const std::string& baseTempInstallDirectory,
  502. const mode_t* default_dir_mode)
  503. {
  504. const char* cmakeProjects = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  505. const char* cmakeGenerator = this->GetOption("CPACK_CMAKE_GENERATOR");
  506. std::string absoluteDestFiles;
  507. if (cmNonempty(cmakeProjects)) {
  508. if (!cmakeGenerator) {
  509. cmCPackLogger(cmCPackLog::LOG_ERROR,
  510. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  511. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  512. "is required to install the project."
  513. << std::endl);
  514. return 0;
  515. }
  516. std::vector<std::string> cmakeProjectsVector =
  517. cmExpandedList(cmakeProjects);
  518. std::vector<std::string>::iterator it;
  519. for (it = cmakeProjectsVector.begin(); it != cmakeProjectsVector.end();
  520. ++it) {
  521. if (it + 1 == cmakeProjectsVector.end() ||
  522. it + 2 == cmakeProjectsVector.end() ||
  523. it + 3 == cmakeProjectsVector.end()) {
  524. cmCPackLogger(
  525. cmCPackLog::LOG_ERROR,
  526. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  527. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  528. "directory, install project name, install component, and install "
  529. "subdirectory."
  530. << std::endl);
  531. return 0;
  532. }
  533. std::string installDirectory = *it;
  534. ++it;
  535. std::string installProjectName = *it;
  536. ++it;
  537. cmCPackInstallCMakeProject project;
  538. project.Directory = installDirectory;
  539. project.ProjectName = installProjectName;
  540. project.Component = *it;
  541. ++it;
  542. project.SubDirectory = *it;
  543. std::vector<std::string> componentsVector;
  544. bool componentInstall = false;
  545. /*
  546. * We do a component install iff
  547. * - the CPack generator support component
  548. * - the user did not request Monolithic install
  549. * (this works at CPack time too)
  550. */
  551. if (this->SupportsComponentInstallation() &&
  552. !(this->IsOn("CPACK_MONOLITHIC_INSTALL"))) {
  553. // Determine the installation types for this project (if provided).
  554. std::string installTypesVar = "CPACK_" +
  555. cmSystemTools::UpperCase(project.Component) + "_INSTALL_TYPES";
  556. const char* installTypes = this->GetOption(installTypesVar);
  557. if (cmNonempty(installTypes)) {
  558. std::vector<std::string> installTypesVector =
  559. cmExpandedList(installTypes);
  560. for (std::string const& installType : installTypesVector) {
  561. project.InstallationTypes.push_back(
  562. this->GetInstallationType(project.ProjectName, installType));
  563. }
  564. }
  565. // Determine the set of components that will be used in this project
  566. std::string componentsVar =
  567. "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(project.Component);
  568. const char* components = this->GetOption(componentsVar);
  569. if (cmNonempty(components)) {
  570. cmExpandList(components, componentsVector);
  571. for (std::string const& comp : componentsVector) {
  572. project.Components.push_back(
  573. this->GetComponent(project.ProjectName, comp));
  574. }
  575. componentInstall = true;
  576. }
  577. }
  578. if (componentsVector.empty()) {
  579. componentsVector.push_back(project.Component);
  580. }
  581. std::vector<std::string> buildConfigs;
  582. // Try get configuration names given via `-C` CLI option
  583. {
  584. const char* const buildConfigCstr =
  585. this->GetOption("CPACK_BUILD_CONFIG");
  586. auto buildConfig = buildConfigCstr ? buildConfigCstr : std::string{};
  587. cmExpandList(buildConfig, buildConfigs);
  588. }
  589. // Remove duplicates
  590. std::sort(buildConfigs.begin(), buildConfigs.end());
  591. buildConfigs.erase(std::unique(buildConfigs.begin(), buildConfigs.end()),
  592. buildConfigs.end());
  593. // Ensure we have at least one configuration.
  594. if (buildConfigs.empty()) {
  595. buildConfigs.emplace_back();
  596. }
  597. std::unique_ptr<cmGlobalGenerator> globalGenerator =
  598. this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  599. cmakeGenerator);
  600. if (!globalGenerator) {
  601. cmCPackLogger(cmCPackLog::LOG_ERROR,
  602. "Specified package generator not found. "
  603. "CPACK_CMAKE_GENERATOR value is invalid."
  604. << std::endl);
  605. return 0;
  606. }
  607. // set the global flag for unix style paths on cmSystemTools as
  608. // soon as the generator is set. This allows gmake to be used
  609. // on windows.
  610. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  611. // Run the installation for the selected build configurations
  612. for (auto const& buildConfig : buildConfigs) {
  613. if (!this->RunPreinstallTarget(project.ProjectName, project.Directory,
  614. globalGenerator.get(), buildConfig)) {
  615. return 0;
  616. }
  617. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  618. "- Install project: " << project.ProjectName << " ["
  619. << buildConfig << ']'
  620. << std::endl);
  621. // Run the installation for each component
  622. for (std::string const& component : componentsVector) {
  623. if (!this->InstallCMakeProject(
  624. setDestDir, project.Directory, baseTempInstallDirectory,
  625. default_dir_mode, component, componentInstall,
  626. project.SubDirectory, buildConfig, absoluteDestFiles)) {
  627. return 0;
  628. }
  629. }
  630. }
  631. this->CMakeProjects.emplace_back(std::move(project));
  632. }
  633. }
  634. this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
  635. absoluteDestFiles.c_str());
  636. return 1;
  637. }
  638. int cmCPackGenerator::RunPreinstallTarget(
  639. const std::string& installProjectName, const std::string& installDirectory,
  640. cmGlobalGenerator* globalGenerator, const std::string& buildConfig)
  641. {
  642. // Does this generator require pre-install?
  643. if (const char* preinstall = globalGenerator->GetPreinstallTargetName()) {
  644. std::string buildCommand = globalGenerator->GenerateCMakeBuildCommand(
  645. preinstall, buildConfig, "", false);
  646. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  647. "- Install command: " << buildCommand << std::endl);
  648. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  649. "- Run preinstall target for: " << installProjectName
  650. << std::endl);
  651. std::string output;
  652. int retVal = 1;
  653. bool resB = cmSystemTools::RunSingleCommand(
  654. buildCommand, &output, &output, &retVal, installDirectory.c_str(),
  655. this->GeneratorVerbose, cmDuration::zero());
  656. if (!resB || retVal) {
  657. std::string tmpFile = cmStrCat(
  658. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/PreinstallOutput.log");
  659. cmGeneratedFileStream ofs(tmpFile);
  660. ofs << "# Run command: " << buildCommand << std::endl
  661. << "# Directory: " << installDirectory << std::endl
  662. << "# Output:" << std::endl
  663. << output << std::endl;
  664. cmCPackLogger(cmCPackLog::LOG_ERROR,
  665. "Problem running install command: "
  666. << buildCommand << std::endl
  667. << "Please check " << tmpFile << " for errors"
  668. << std::endl);
  669. return 0;
  670. }
  671. }
  672. return 1;
  673. }
  674. int cmCPackGenerator::InstallCMakeProject(
  675. bool setDestDir, const std::string& installDirectory,
  676. const std::string& baseTempInstallDirectory, const mode_t* default_dir_mode,
  677. const std::string& component, bool componentInstall,
  678. const std::string& installSubDirectory, const std::string& buildConfig,
  679. std::string& absoluteDestFiles)
  680. {
  681. std::string tempInstallDirectory = baseTempInstallDirectory;
  682. std::string installFile = installDirectory + "/cmake_install.cmake";
  683. if (componentInstall) {
  684. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  685. "- Install component: " << component << std::endl);
  686. }
  687. cmake cm(cmake::RoleScript, cmState::CPack);
  688. cm.SetHomeDirectory("");
  689. cm.SetHomeOutputDirectory("");
  690. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  691. cm.AddCMakePaths();
  692. cm.SetProgressCallback([this](const std::string& msg, float prog) {
  693. this->DisplayVerboseOutput(msg, prog);
  694. });
  695. cm.SetTrace(this->Trace);
  696. cm.SetTraceExpand(this->TraceExpand);
  697. cmGlobalGenerator gg(&cm);
  698. cmMakefile mf(&gg, cm.GetCurrentSnapshot());
  699. if (!installSubDirectory.empty() && installSubDirectory != "/" &&
  700. installSubDirectory != ".") {
  701. tempInstallDirectory += installSubDirectory;
  702. }
  703. if (componentInstall) {
  704. tempInstallDirectory += "/";
  705. // Some CPack generators would rather chose
  706. // the local installation directory suffix.
  707. // Some (e.g. RPM) use
  708. // one install directory for each component **GROUP**
  709. // instead of the default
  710. // one install directory for each component.
  711. tempInstallDirectory += this->GetComponentInstallDirNameSuffix(component);
  712. if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) {
  713. tempInstallDirectory += "/";
  714. tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
  715. }
  716. }
  717. const char* default_dir_inst_permissions =
  718. this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
  719. if (cmNonempty(default_dir_inst_permissions)) {
  720. mf.AddDefinition("CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS",
  721. default_dir_inst_permissions);
  722. }
  723. if (!setDestDir) {
  724. tempInstallDirectory += this->GetPackagingInstallPrefix();
  725. }
  726. if (setDestDir) {
  727. // For DESTDIR based packaging, use the *project*
  728. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  729. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  730. // the value of the CPACK_INSTALL_PREFIX variable.
  731. //
  732. // If DESTDIR has been 'internally set ON' this means that
  733. // the underlying CPack specific generator did ask for that
  734. // In this case we may override CPACK_INSTALL_PREFIX with
  735. // CPACK_PACKAGING_INSTALL_PREFIX
  736. // I know this is tricky and awkward but it's the price for
  737. // CPACK_SET_DESTDIR backward compatibility.
  738. if (cmIsInternallyOn(this->GetOption("CPACK_SET_DESTDIR"))) {
  739. this->SetOption("CPACK_INSTALL_PREFIX",
  740. this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX"));
  741. }
  742. std::string dir;
  743. if (this->GetOption("CPACK_INSTALL_PREFIX")) {
  744. dir += this->GetOption("CPACK_INSTALL_PREFIX");
  745. }
  746. mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir);
  747. cmCPackLogger(
  748. cmCPackLog::LOG_DEBUG,
  749. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf.AddDefinition)"
  750. << std::endl);
  751. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  752. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  753. << std::endl);
  754. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  755. // exists:
  756. //
  757. if (cmHasLiteralPrefix(dir, "/")) {
  758. dir = tempInstallDirectory + dir;
  759. } else {
  760. dir = tempInstallDirectory + "/" + dir;
  761. }
  762. /*
  763. * We must re-set DESTDIR for each component
  764. * We must not add the CPACK_INSTALL_PREFIX part because
  765. * it will be added using the override of CMAKE_INSTALL_PREFIX
  766. * The main reason for this awkward trick is that
  767. * are using DESTDIR for 2 different reasons:
  768. * - Because it was asked by the CPack Generator or the user
  769. * using CPACK_SET_DESTDIR
  770. * - Because it was already used for component install
  771. * in order to put things in subdirs...
  772. */
  773. cmSystemTools::PutEnv("DESTDIR=" + tempInstallDirectory);
  774. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  775. "- Creating directory: '" << dir << "'" << std::endl);
  776. if (!cmsys::SystemTools::MakeDirectory(dir, default_dir_mode)) {
  777. cmCPackLogger(cmCPackLog::LOG_ERROR,
  778. "Problem creating temporary directory: " << dir
  779. << std::endl);
  780. return 0;
  781. }
  782. } else {
  783. mf.AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  784. if (!cmsys::SystemTools::MakeDirectory(tempInstallDirectory,
  785. default_dir_mode)) {
  786. cmCPackLogger(cmCPackLog::LOG_ERROR,
  787. "Problem creating temporary directory: "
  788. << tempInstallDirectory << std::endl);
  789. return 0;
  790. }
  791. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  792. "- Using non-DESTDIR install... (mf.AddDefinition)"
  793. << std::endl);
  794. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  795. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  796. << "'" << std::endl);
  797. }
  798. if (!buildConfig.empty()) {
  799. mf.AddDefinition("BUILD_TYPE", buildConfig);
  800. }
  801. std::string installComponentLowerCase = cmSystemTools::LowerCase(component);
  802. if (installComponentLowerCase != "all") {
  803. mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component);
  804. }
  805. // strip on TRUE, ON, 1, one or several file names, but not on
  806. // FALSE, OFF, 0 and an empty string
  807. if (!cmIsOff(this->GetOption("CPACK_STRIP_FILES"))) {
  808. mf.AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  809. }
  810. // Remember the list of files before installation
  811. // of the current component (if we are in component install)
  812. std::string const& InstallPrefix = tempInstallDirectory;
  813. std::vector<std::string> filesBefore;
  814. std::string findExpr = tempInstallDirectory;
  815. if (componentInstall) {
  816. cmsys::Glob glB;
  817. findExpr += "/*";
  818. glB.RecurseOn();
  819. glB.SetRecurseListDirs(true);
  820. glB.SetRecurseThroughSymlinks(false);
  821. glB.FindFiles(findExpr);
  822. filesBefore = glB.GetFiles();
  823. std::sort(filesBefore.begin(), filesBefore.end());
  824. }
  825. // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION
  826. // then forward request to cmake_install.cmake script
  827. if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION")) {
  828. mf.AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1");
  829. }
  830. // If current CPack generator does support
  831. // ABSOLUTE INSTALL DESTINATION or CPack has been asked for
  832. // then ask cmake_install.cmake script to error out
  833. // as soon as it occurs (before installing file)
  834. if (!this->SupportsAbsoluteDestination() ||
  835. this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION")) {
  836. mf.AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", "1");
  837. }
  838. // do installation
  839. bool res = mf.ReadListFile(installFile);
  840. // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
  841. // to CPack (may be used by generators like CPack RPM or DEB)
  842. // in order to transparently handle ABSOLUTE PATH
  843. if (cmProp def = mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) {
  844. mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", *def);
  845. }
  846. // Now rebuild the list of files after installation
  847. // of the current component (if we are in component install)
  848. if (componentInstall) {
  849. cmsys::Glob glA;
  850. glA.RecurseOn();
  851. glA.SetRecurseListDirs(true);
  852. glA.SetRecurseThroughSymlinks(false);
  853. glA.FindFiles(findExpr);
  854. std::vector<std::string> filesAfter = glA.GetFiles();
  855. std::sort(filesAfter.begin(), filesAfter.end());
  856. std::vector<std::string>::iterator diff;
  857. std::vector<std::string> result(filesAfter.size());
  858. diff = std::set_difference(filesAfter.begin(), filesAfter.end(),
  859. filesBefore.begin(), filesBefore.end(),
  860. result.begin());
  861. std::vector<std::string>::iterator fit;
  862. std::string localFileName;
  863. // Populate the File field of each component
  864. for (fit = result.begin(); fit != diff; ++fit) {
  865. localFileName = cmSystemTools::RelativePath(InstallPrefix, *fit);
  866. localFileName =
  867. localFileName.substr(localFileName.find_first_not_of('/'));
  868. this->Components[component].Files.push_back(localFileName);
  869. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  870. "Adding file <" << localFileName << "> to component <"
  871. << component << ">" << std::endl);
  872. }
  873. }
  874. if (cmProp d = mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
  875. if (!absoluteDestFiles.empty()) {
  876. absoluteDestFiles += ";";
  877. }
  878. absoluteDestFiles += *d;
  879. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  880. "Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles
  881. << std::endl);
  882. // define component specific var
  883. if (componentInstall) {
  884. std::string absoluteDestFileComponent =
  885. std::string("CPACK_ABSOLUTE_DESTINATION_FILES") + "_" +
  886. this->GetComponentInstallDirNameSuffix(component);
  887. if (nullptr != this->GetOption(absoluteDestFileComponent)) {
  888. std::string absoluteDestFilesListComponent =
  889. cmStrCat(this->GetOption(absoluteDestFileComponent), ';', *d);
  890. this->SetOption(absoluteDestFileComponent,
  891. absoluteDestFilesListComponent.c_str());
  892. } else {
  893. this->SetOption(
  894. absoluteDestFileComponent,
  895. cmToCStr(mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")));
  896. }
  897. }
  898. }
  899. if (cmSystemTools::GetErrorOccuredFlag() || !res) {
  900. return 0;
  901. }
  902. return 1;
  903. }
  904. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  905. {
  906. bool retval;
  907. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  908. retval = this->MakefileMap->ReadListFile(fullPath);
  909. // include FATAL_ERROR and ERROR in the return status
  910. retval = retval && (!cmSystemTools::GetErrorOccuredFlag());
  911. return retval;
  912. }
  913. void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
  914. const char* value)
  915. {
  916. cmProp def = this->MakefileMap->GetDefinition(op);
  917. if (cmNonempty(def)) {
  918. return;
  919. }
  920. this->SetOption(op, value);
  921. }
  922. void cmCPackGenerator::SetOption(const std::string& op, const char* value)
  923. {
  924. if (!value) {
  925. this->MakefileMap->RemoveDefinition(op);
  926. return;
  927. }
  928. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  929. this->GetNameOfClass() << "::SetOption(" << op << ", " << value
  930. << ")" << std::endl);
  931. this->MakefileMap->AddDefinition(op, value);
  932. }
  933. int cmCPackGenerator::DoPackage()
  934. {
  935. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  936. "Create package using " << this->Name << std::endl);
  937. // Prepare CPack internal name and check
  938. // values for many CPACK_xxx vars
  939. if (!this->PrepareNames()) {
  940. return 0;
  941. }
  942. // Digest Component grouping specification
  943. if (!this->PrepareGroupingKind()) {
  944. return 0;
  945. }
  946. if (cmIsOn(this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY"))) {
  947. const char* toplevelDirectory =
  948. this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  949. if (cmSystemTools::FileExists(toplevelDirectory)) {
  950. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  951. "Remove toplevel directory: " << toplevelDirectory
  952. << std::endl);
  953. if (!cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory)) {
  954. cmCPackLogger(cmCPackLog::LOG_ERROR,
  955. "Problem removing toplevel directory: "
  956. << toplevelDirectory << std::endl);
  957. return 0;
  958. }
  959. }
  960. }
  961. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  962. "About to install project " << std::endl);
  963. if (!this->InstallProject()) {
  964. return 0;
  965. }
  966. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Done install project " << std::endl);
  967. const char* tempPackageFileName =
  968. this->GetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  969. const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  970. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  971. cmsys::Glob gl;
  972. std::string findExpr = cmStrCat(tempDirectory, "/*");
  973. gl.RecurseOn();
  974. gl.SetRecurseListDirs(true);
  975. gl.SetRecurseThroughSymlinks(false);
  976. if (!gl.FindFiles(findExpr)) {
  977. cmCPackLogger(cmCPackLog::LOG_ERROR,
  978. "Cannot find any files in the packaging tree" << std::endl);
  979. return 0;
  980. }
  981. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
  982. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  983. "Package files to: "
  984. << (tempPackageFileName ? tempPackageFileName : "(NULL)")
  985. << std::endl);
  986. if (cmSystemTools::FileExists(tempPackageFileName)) {
  987. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  988. "Remove old package file" << std::endl);
  989. cmSystemTools::RemoveFile(tempPackageFileName);
  990. }
  991. if (cmIsOn(this->GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))) {
  992. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  993. }
  994. // The files to be installed
  995. this->files = gl.GetFiles();
  996. this->packageFileNames.clear();
  997. /* Put at least one file name into the list of
  998. * wanted packageFileNames. The specific generator
  999. * may update this during PackageFiles.
  1000. * (either putting several names or updating the provided one)
  1001. */
  1002. this->packageFileNames.emplace_back(tempPackageFileName ? tempPackageFileName
  1003. : "");
  1004. this->toplevel = tempDirectory;
  1005. { // scope that enables package generators to run internal scripts with
  1006. // latest CMake policies enabled
  1007. cmMakefile::ScopePushPop pp{ this->MakefileMap };
  1008. this->MakefileMap->SetPolicyVersion(cmVersion::GetCMakeVersion(),
  1009. std::string());
  1010. if (!this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) {
  1011. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1012. "Problem compressing the directory" << std::endl);
  1013. return 0;
  1014. }
  1015. }
  1016. // Run post-build actions
  1017. const char* postBuildScripts = this->GetOption("CPACK_POST_BUILD_SCRIPTS");
  1018. if (postBuildScripts) {
  1019. this->MakefileMap->AddDefinition("CPACK_PACKAGE_FILES",
  1020. cmJoin(this->packageFileNames, ";"));
  1021. const auto scripts = cmExpandedList(postBuildScripts, false);
  1022. for (const auto& script : scripts) {
  1023. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1024. "Executing post-build script: " << script << std::endl);
  1025. if (!this->MakefileMap->ReadListFile(script)) {
  1026. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1027. "The post-build script not found: " << script
  1028. << std::endl);
  1029. return 0;
  1030. }
  1031. }
  1032. }
  1033. /* Prepare checksum algorithm*/
  1034. const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
  1035. std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : "");
  1036. /*
  1037. * Copy the generated packages to final destination
  1038. * - there may be several of them
  1039. * - the initially provided name may have changed
  1040. * (because the specific generator did 'normalize' it)
  1041. */
  1042. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1043. "Copying final package(s) [" << this->packageFileNames.size()
  1044. << "]:" << std::endl);
  1045. /* now copy package one by one */
  1046. for (std::string const& pkgFileName : this->packageFileNames) {
  1047. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1048. std::string filename(cmSystemTools::GetFilenameName(pkgFileName));
  1049. tempPackageFileName = pkgFileName.c_str();
  1050. tmpPF += "/" + filename;
  1051. const char* packageFileName = tmpPF.c_str();
  1052. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1053. "Copy final package(s): "
  1054. << (tempPackageFileName ? tempPackageFileName : "(NULL)")
  1055. << " to " << (packageFileName ? packageFileName : "(NULL)")
  1056. << std::endl);
  1057. if (!cmSystemTools::CopyFileIfDifferent(pkgFileName, tmpPF)) {
  1058. cmCPackLogger(
  1059. cmCPackLog::LOG_ERROR,
  1060. "Problem copying the package: "
  1061. << (tempPackageFileName ? tempPackageFileName : "(NULL)") << " to "
  1062. << (packageFileName ? packageFileName : "(NULL)") << std::endl);
  1063. return 0;
  1064. }
  1065. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1066. "- package: " << packageFileName << " generated."
  1067. << std::endl);
  1068. /* Generate checksum file */
  1069. if (crypto) {
  1070. std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1071. hashFile += "/" + filename;
  1072. hashFile += "." + cmSystemTools::LowerCase(algo);
  1073. cmsys::ofstream outF(hashFile.c_str());
  1074. if (!outF) {
  1075. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1076. "Cannot create checksum file: " << hashFile
  1077. << std::endl);
  1078. return 0;
  1079. }
  1080. outF << crypto->HashFile(packageFileName) << " " << filename << "\n";
  1081. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1082. "- checksum file: " << hashFile << " generated."
  1083. << std::endl);
  1084. }
  1085. }
  1086. return 1;
  1087. }
  1088. int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
  1089. {
  1090. this->MakefileMap = mf;
  1091. this->Name = name;
  1092. // set the running generator name
  1093. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  1094. // Load the project specific config file
  1095. const char* config = this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  1096. if (config) {
  1097. mf->ReadListFile(config);
  1098. }
  1099. int result = this->InitializeInternal();
  1100. if (cmSystemTools::GetErrorOccuredFlag()) {
  1101. return 0;
  1102. }
  1103. // If a generator subclass did not already set this option in its
  1104. // InitializeInternal implementation, and the project did not already set
  1105. // it, the default value should be:
  1106. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  1107. return result;
  1108. }
  1109. int cmCPackGenerator::InitializeInternal()
  1110. {
  1111. return 1;
  1112. }
  1113. bool cmCPackGenerator::IsSet(const std::string& name) const
  1114. {
  1115. return this->MakefileMap->IsSet(name);
  1116. }
  1117. bool cmCPackGenerator::IsOn(const std::string& name) const
  1118. {
  1119. return cmIsOn(this->GetOption(name));
  1120. }
  1121. bool cmCPackGenerator::IsSetToOff(const std::string& op) const
  1122. {
  1123. cmProp ret = this->MakefileMap->GetDefinition(op);
  1124. if (cmNonempty(ret)) {
  1125. return cmIsOff(*ret);
  1126. }
  1127. return false;
  1128. }
  1129. bool cmCPackGenerator::IsSetToEmpty(const std::string& op) const
  1130. {
  1131. cmProp ret = this->MakefileMap->GetDefinition(op);
  1132. if (ret) {
  1133. return ret->empty();
  1134. }
  1135. return false;
  1136. }
  1137. const char* cmCPackGenerator::GetOption(const std::string& op) const
  1138. {
  1139. cmProp ret = this->MakefileMap->GetDefinition(op);
  1140. if (!ret) {
  1141. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1142. "Warning, GetOption return NULL for: " << op << std::endl);
  1143. return nullptr;
  1144. }
  1145. return ret->c_str();
  1146. }
  1147. std::vector<std::string> cmCPackGenerator::GetOptions() const
  1148. {
  1149. return this->MakefileMap->GetDefinitions();
  1150. }
  1151. int cmCPackGenerator::PackageFiles()
  1152. {
  1153. return 0;
  1154. }
  1155. const char* cmCPackGenerator::GetInstallPath()
  1156. {
  1157. if (!this->InstallPath.empty()) {
  1158. return this->InstallPath.c_str();
  1159. }
  1160. #if defined(_WIN32) && !defined(__CYGWIN__)
  1161. std::string prgfiles;
  1162. std::string sysDrive;
  1163. if (cmsys::SystemTools::GetEnv("ProgramFiles", prgfiles)) {
  1164. this->InstallPath = prgfiles;
  1165. } else if (cmsys::SystemTools::GetEnv("SystemDrive", sysDrive)) {
  1166. this->InstallPath = cmStrCat(sysDrive, "/Program Files");
  1167. } else {
  1168. this->InstallPath = "c:/Program Files";
  1169. }
  1170. this->InstallPath += "/";
  1171. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1172. this->InstallPath += "-";
  1173. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1174. #elif defined(__HAIKU__)
  1175. char dir[B_PATH_NAME_LENGTH];
  1176. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) ==
  1177. B_OK) {
  1178. this->InstallPath = dir;
  1179. } else {
  1180. this->InstallPath = "/boot/system";
  1181. }
  1182. #else
  1183. this->InstallPath = "/usr/local/";
  1184. #endif
  1185. return this->InstallPath.c_str();
  1186. }
  1187. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1188. {
  1189. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1190. "GetPackagingInstallPrefix: '"
  1191. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'"
  1192. << std::endl);
  1193. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX");
  1194. }
  1195. std::string cmCPackGenerator::FindTemplate(const char* name)
  1196. {
  1197. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1198. "Look for template: " << (name ? name : "(NULL)")
  1199. << std::endl);
  1200. // Search CMAKE_MODULE_PATH for a custom template.
  1201. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1202. if (ffile.empty()) {
  1203. // Fall back to our internal builtin default.
  1204. ffile = cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules/Internal/CPack/",
  1205. name);
  1206. cmSystemTools::ConvertToUnixSlashes(ffile);
  1207. if (!cmSystemTools::FileExists(ffile)) {
  1208. ffile.clear();
  1209. }
  1210. }
  1211. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1212. "Found template: " << ffile << std::endl);
  1213. return ffile;
  1214. }
  1215. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1216. std::string& outString)
  1217. {
  1218. this->MakefileMap->ConfigureString(inString, outString, true, false);
  1219. return true;
  1220. }
  1221. bool cmCPackGenerator::ConfigureFile(const std::string& inName,
  1222. const std::string& outName,
  1223. bool copyOnly /* = false */)
  1224. {
  1225. return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
  1226. false) == 1;
  1227. }
  1228. int cmCPackGenerator::CleanTemporaryDirectory()
  1229. {
  1230. std::string tempInstallDirectory =
  1231. this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1232. if (cmsys::SystemTools::FileExists(tempInstallDirectory)) {
  1233. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1234. "- Clean temporary : " << tempInstallDirectory << std::endl);
  1235. if (!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory)) {
  1236. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1237. "Problem removing temporary directory: "
  1238. << tempInstallDirectory << std::endl);
  1239. return 0;
  1240. }
  1241. }
  1242. return 1;
  1243. }
  1244. cmInstalledFile const* cmCPackGenerator::GetInstalledFile(
  1245. std::string const& name) const
  1246. {
  1247. cmake const* cm = this->MakefileMap->GetCMakeInstance();
  1248. return cm->GetInstalledFile(name);
  1249. }
  1250. int cmCPackGenerator::PrepareGroupingKind()
  1251. {
  1252. // find a component package method specified by the user
  1253. ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
  1254. if (this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")) {
  1255. method = ONE_PACKAGE;
  1256. }
  1257. if (this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS")) {
  1258. method = ONE_PACKAGE_PER_COMPONENT;
  1259. }
  1260. if (this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP")) {
  1261. method = ONE_PACKAGE_PER_GROUP;
  1262. }
  1263. std::string groupingType;
  1264. // Second way to specify grouping
  1265. if (nullptr != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
  1266. groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING");
  1267. }
  1268. if (!groupingType.empty()) {
  1269. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1270. "[" << this->Name << "]"
  1271. << " requested component grouping = " << groupingType
  1272. << std::endl);
  1273. if (groupingType == "ALL_COMPONENTS_IN_ONE") {
  1274. method = ONE_PACKAGE;
  1275. } else if (groupingType == "IGNORE") {
  1276. method = ONE_PACKAGE_PER_COMPONENT;
  1277. } else if (groupingType == "ONE_PER_GROUP") {
  1278. method = ONE_PACKAGE_PER_GROUP;
  1279. } else {
  1280. cmCPackLogger(
  1281. cmCPackLog::LOG_WARNING,
  1282. "[" << this->Name << "]"
  1283. << " requested component grouping type <" << groupingType
  1284. << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
  1285. << std::endl);
  1286. }
  1287. }
  1288. // Some components were defined but NO group
  1289. // fallback to default if not group based
  1290. if (method == ONE_PACKAGE_PER_GROUP && this->ComponentGroups.empty() &&
  1291. !this->Components.empty()) {
  1292. if (this->componentPackageMethod == ONE_PACKAGE) {
  1293. method = ONE_PACKAGE;
  1294. } else {
  1295. method = ONE_PACKAGE_PER_COMPONENT;
  1296. }
  1297. cmCPackLogger(
  1298. cmCPackLog::LOG_WARNING,
  1299. "[" << this->Name << "]"
  1300. << " One package per component group requested, "
  1301. << "but NO component groups exist: Ignoring component group."
  1302. << std::endl);
  1303. }
  1304. // if user specified packaging method, override the default packaging
  1305. // method
  1306. if (method != UNKNOWN_COMPONENT_PACKAGE_METHOD) {
  1307. this->componentPackageMethod = method;
  1308. }
  1309. const char* method_names[] = { "ALL_COMPONENTS_IN_ONE", "IGNORE_GROUPS",
  1310. "ONE_PER_GROUP" };
  1311. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1312. "[" << this->Name << "]"
  1313. << " requested component grouping = "
  1314. << method_names[this->componentPackageMethod]
  1315. << std::endl);
  1316. return 1;
  1317. }
  1318. std::string cmCPackGenerator::GetComponentInstallDirNameSuffix(
  1319. const std::string& componentName)
  1320. {
  1321. return componentName;
  1322. }
  1323. std::string cmCPackGenerator::GetComponentPackageFileName(
  1324. const std::string& initialPackageFileName,
  1325. const std::string& groupOrComponentName, bool isGroupName)
  1326. {
  1327. /*
  1328. * the default behavior is to use the
  1329. * component [group] name as a suffix
  1330. */
  1331. std::string suffix = "-" + groupOrComponentName;
  1332. /* check if we should use DISPLAY name */
  1333. std::string dispNameVar =
  1334. "CPACK_" + this->Name + "_USE_DISPLAY_NAME_IN_FILENAME";
  1335. if (this->IsOn(dispNameVar)) {
  1336. /* the component Group case */
  1337. if (isGroupName) {
  1338. std::string groupDispVar = "CPACK_COMPONENT_GROUP_" +
  1339. cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1340. const char* groupDispName = this->GetOption(groupDispVar);
  1341. if (groupDispName) {
  1342. suffix = "-" + std::string(groupDispName);
  1343. }
  1344. }
  1345. /* the [single] component case */
  1346. else {
  1347. std::string dispVar = "CPACK_COMPONENT_" +
  1348. cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1349. const char* dispName = this->GetOption(dispVar);
  1350. if (dispName) {
  1351. suffix = "-" + std::string(dispName);
  1352. }
  1353. }
  1354. }
  1355. return initialPackageFileName + suffix;
  1356. }
  1357. enum cmCPackGenerator::CPackSetDestdirSupport
  1358. cmCPackGenerator::SupportsSetDestdir() const
  1359. {
  1360. return cmCPackGenerator::SETDESTDIR_SUPPORTED;
  1361. }
  1362. bool cmCPackGenerator::SupportsAbsoluteDestination() const
  1363. {
  1364. return true;
  1365. }
  1366. bool cmCPackGenerator::SupportsComponentInstallation() const
  1367. {
  1368. return false;
  1369. }
  1370. bool cmCPackGenerator::WantsComponentInstallation() const
  1371. {
  1372. return (!this->IsOn("CPACK_MONOLITHIC_INSTALL") &&
  1373. this->SupportsComponentInstallation()
  1374. // check that we have at least one group or component
  1375. && (!this->ComponentGroups.empty() || !this->Components.empty()));
  1376. }
  1377. cmCPackInstallationType* cmCPackGenerator::GetInstallationType(
  1378. const std::string& projectName, const std::string& name)
  1379. {
  1380. (void)projectName;
  1381. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1382. cmCPackInstallationType* installType = &this->InstallationTypes[name];
  1383. if (!hasInstallationType) {
  1384. // Define the installation type
  1385. std::string macroPrefix =
  1386. "CPACK_INSTALL_TYPE_" + cmsys::SystemTools::UpperCase(name);
  1387. installType->Name = name;
  1388. const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1389. if (cmNonempty(displayName)) {
  1390. installType->DisplayName = displayName;
  1391. } else {
  1392. installType->DisplayName = installType->Name;
  1393. }
  1394. installType->Index = static_cast<unsigned>(this->InstallationTypes.size());
  1395. }
  1396. return installType;
  1397. }
  1398. cmCPackComponent* cmCPackGenerator::GetComponent(
  1399. const std::string& projectName, const std::string& name)
  1400. {
  1401. bool hasComponent = this->Components.count(name) != 0;
  1402. cmCPackComponent* component = &this->Components[name];
  1403. if (!hasComponent) {
  1404. // Define the component
  1405. std::string macroPrefix =
  1406. "CPACK_COMPONENT_" + cmsys::SystemTools::UpperCase(name);
  1407. component->Name = name;
  1408. const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1409. if (cmNonempty(displayName)) {
  1410. component->DisplayName = displayName;
  1411. } else {
  1412. component->DisplayName = component->Name;
  1413. }
  1414. component->IsHidden = this->IsOn(macroPrefix + "_HIDDEN");
  1415. component->IsRequired = this->IsOn(macroPrefix + "_REQUIRED");
  1416. component->IsDisabledByDefault = this->IsOn(macroPrefix + "_DISABLED");
  1417. component->IsDownloaded = this->IsOn(macroPrefix + "_DOWNLOADED") ||
  1418. cmIsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1419. const char* archiveFile = this->GetOption(macroPrefix + "_ARCHIVE_FILE");
  1420. if (cmNonempty(archiveFile)) {
  1421. component->ArchiveFile = archiveFile;
  1422. }
  1423. const char* plist = this->GetOption(macroPrefix + "_PLIST");
  1424. if (cmNonempty(plist)) {
  1425. component->Plist = plist;
  1426. }
  1427. const char* groupName = this->GetOption(macroPrefix + "_GROUP");
  1428. if (cmNonempty(groupName)) {
  1429. component->Group = this->GetComponentGroup(projectName, groupName);
  1430. component->Group->Components.push_back(component);
  1431. } else {
  1432. component->Group = nullptr;
  1433. }
  1434. const char* description = this->GetOption(macroPrefix + "_DESCRIPTION");
  1435. if (cmNonempty(description)) {
  1436. component->Description = description;
  1437. }
  1438. // Determine the installation types.
  1439. const char* installTypes = this->GetOption(macroPrefix + "_INSTALL_TYPES");
  1440. if (cmNonempty(installTypes)) {
  1441. std::vector<std::string> installTypesVector =
  1442. cmExpandedList(installTypes);
  1443. for (std::string const& installType : installTypesVector) {
  1444. component->InstallationTypes.push_back(
  1445. this->GetInstallationType(projectName, installType));
  1446. }
  1447. }
  1448. // Determine the component dependencies.
  1449. const char* depends = this->GetOption(macroPrefix + "_DEPENDS");
  1450. if (cmNonempty(depends)) {
  1451. std::vector<std::string> dependsVector = cmExpandedList(depends);
  1452. for (std::string const& depend : dependsVector) {
  1453. cmCPackComponent* child = this->GetComponent(projectName, depend);
  1454. component->Dependencies.push_back(child);
  1455. child->ReverseDependencies.push_back(component);
  1456. }
  1457. }
  1458. }
  1459. return component;
  1460. }
  1461. cmCPackComponentGroup* cmCPackGenerator::GetComponentGroup(
  1462. const std::string& projectName, const std::string& name)
  1463. {
  1464. (void)projectName;
  1465. std::string macroPrefix =
  1466. "CPACK_COMPONENT_GROUP_" + cmsys::SystemTools::UpperCase(name);
  1467. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1468. cmCPackComponentGroup* group = &this->ComponentGroups[name];
  1469. if (!hasGroup) {
  1470. // Define the group
  1471. group->Name = name;
  1472. const char* displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1473. if (cmNonempty(displayName)) {
  1474. group->DisplayName = displayName;
  1475. } else {
  1476. group->DisplayName = group->Name;
  1477. }
  1478. const char* description = this->GetOption(macroPrefix + "_DESCRIPTION");
  1479. if (cmNonempty(description)) {
  1480. group->Description = description;
  1481. }
  1482. group->IsBold = this->IsOn(macroPrefix + "_BOLD_TITLE");
  1483. group->IsExpandedByDefault = this->IsOn(macroPrefix + "_EXPANDED");
  1484. const char* parentGroupName =
  1485. this->GetOption(macroPrefix + "_PARENT_GROUP");
  1486. if (cmNonempty(parentGroupName)) {
  1487. group->ParentGroup =
  1488. this->GetComponentGroup(projectName, parentGroupName);
  1489. group->ParentGroup->Subgroups.push_back(group);
  1490. } else {
  1491. group->ParentGroup = nullptr;
  1492. }
  1493. }
  1494. return group;
  1495. }