cmCPackGenerator.cxx 59 KB

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