cmCPackGenerator.cxx 59 KB

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