cmCPackGenerator.cxx 59 KB

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