cmCPackGenerator.cxx 59 KB

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