cmCPackGenerator.cxx 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  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. cmProp 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. cmProp 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. cmProp 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. cmProp 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->c_str());
  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. cmProp defFileName =
  142. this->GetOption("CPACK_DEFAULT_PACKAGE_DESCRIPTION_FILE");
  143. if (defFileName && (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. cmProp 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. cmProp 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. cmProp 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. cmProp 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. cmProp 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. cmProp installDirectories = this->GetOption("CPACK_INSTALLED_DIRECTORIES");
  316. if (cmNonempty(installDirectories)) {
  317. std::vector<std::string> installDirectoriesVector =
  318. cmExpandedList(installDirectories);
  319. if (installDirectoriesVector.size() % 2 != 0) {
  320. cmCPackLogger(
  321. cmCPackLog::LOG_ERROR,
  322. "CPACK_INSTALLED_DIRECTORIES should contain pairs of <directory> "
  323. "and "
  324. "<subdirectory>. The <subdirectory> can be '.' to be installed in "
  325. "the toplevel directory of installation."
  326. << std::endl);
  327. return 0;
  328. }
  329. std::vector<std::string>::iterator it;
  330. const std::string& tempDir = tempInstallDirectory;
  331. for (it = installDirectoriesVector.begin();
  332. it != installDirectoriesVector.end(); ++it) {
  333. std::vector<std::pair<std::string, std::string>> symlinkedFiles;
  334. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  335. cmsys::Glob gl;
  336. std::string top = *it;
  337. it++;
  338. std::string subdir = *it;
  339. std::string findExpr = cmStrCat(top, "/*");
  340. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  341. "- Install directory: " << top << std::endl);
  342. gl.RecurseOn();
  343. gl.SetRecurseListDirs(true);
  344. gl.SetRecurseThroughSymlinks(false);
  345. if (!gl.FindFiles(findExpr)) {
  346. cmCPackLogger(cmCPackLog::LOG_ERROR,
  347. "Cannot find any files in the installed directory"
  348. << std::endl);
  349. return 0;
  350. }
  351. this->files = gl.GetFiles();
  352. for (std::string const& gf : this->files) {
  353. bool skip = false;
  354. std::string inFile = gf;
  355. if (cmSystemTools::FileIsDirectory(gf) &&
  356. !cmSystemTools::FileIsSymlink(gf)) {
  357. inFile += '/';
  358. }
  359. for (cmsys::RegularExpression& reg : ignoreFilesRegex) {
  360. if (reg.find(inFile)) {
  361. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  362. "Ignore file: " << inFile << std::endl);
  363. skip = true;
  364. }
  365. }
  366. if (skip) {
  367. continue;
  368. }
  369. std::string filePath = cmStrCat(tempDir, '/', subdir, '/',
  370. cmSystemTools::RelativePath(top, gf));
  371. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  372. "Copy file: " << inFile << " -> " << filePath
  373. << std::endl);
  374. /* If the file is a symlink we will have to re-create it */
  375. if (cmSystemTools::FileIsSymlink(inFile)) {
  376. std::string targetFile;
  377. std::string inFileRelative =
  378. cmSystemTools::RelativePath(top, inFile);
  379. cmSystemTools::ReadSymlink(inFile, targetFile);
  380. symlinkedFiles.emplace_back(std::move(targetFile),
  381. std::move(inFileRelative));
  382. }
  383. /* If it is not a symlink then do a plain copy */
  384. else if (!(cmSystemTools::CopyFileIfDifferent(inFile, filePath) &&
  385. cmFileTimes::Copy(inFile, filePath))) {
  386. cmCPackLogger(cmCPackLog::LOG_ERROR,
  387. "Problem copying file: " << inFile << " -> "
  388. << filePath << std::endl);
  389. return 0;
  390. }
  391. }
  392. /* rebuild symlinks in the installed tree */
  393. if (!symlinkedFiles.empty()) {
  394. std::string goToDir = cmStrCat(tempDir, '/', subdir);
  395. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  396. "Change dir to: " << goToDir << std::endl);
  397. cmWorkingDirectory workdir(goToDir);
  398. if (workdir.Failed()) {
  399. cmCPackLogger(cmCPackLog::LOG_ERROR,
  400. "Failed to change working directory to "
  401. << goToDir << " : "
  402. << std::strerror(workdir.GetLastResult())
  403. << std::endl);
  404. return 0;
  405. }
  406. for (auto const& symlinked : symlinkedFiles) {
  407. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  408. "Will create a symlink: " << symlinked.second << "--> "
  409. << symlinked.first
  410. << std::endl);
  411. // make sure directory exists for symlink
  412. std::string destDir =
  413. cmSystemTools::GetFilenamePath(symlinked.second);
  414. if (!destDir.empty() &&
  415. !cmSystemTools::MakeDirectory(destDir, default_dir_mode)) {
  416. cmCPackLogger(cmCPackLog::LOG_ERROR,
  417. "Cannot create dir: "
  418. << destDir << "\nTrying to create symlink: "
  419. << symlinked.second << "--> " << symlinked.first
  420. << std::endl);
  421. }
  422. if (!cmSystemTools::CreateSymlink(symlinked.first,
  423. symlinked.second)) {
  424. cmCPackLogger(cmCPackLog::LOG_ERROR,
  425. "Cannot create symlink: "
  426. << symlinked.second << "--> " << symlinked.first
  427. << std::endl);
  428. return 0;
  429. }
  430. }
  431. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  432. "Going back to: " << workdir.GetOldDirectory()
  433. << std::endl);
  434. }
  435. }
  436. }
  437. return 1;
  438. }
  439. int cmCPackGenerator::InstallProjectViaInstallScript(
  440. bool setDestDir, const std::string& tempInstallDirectory)
  441. {
  442. cmProp cmakeScripts = this->GetOption("CPACK_INSTALL_SCRIPTS");
  443. {
  444. cmProp const cmakeScript = this->GetOption("CPACK_INSTALL_SCRIPT");
  445. if (cmakeScript && cmakeScripts) {
  446. cmCPackLogger(
  447. cmCPackLog::LOG_WARNING,
  448. "Both CPACK_INSTALL_SCRIPTS and CPACK_INSTALL_SCRIPT are set, "
  449. "the latter will be ignored."
  450. << std::endl);
  451. } else if (cmakeScript && !cmakeScripts) {
  452. cmakeScripts = cmakeScript;
  453. }
  454. }
  455. if (cmakeScripts && !cmakeScripts->empty()) {
  456. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  457. "- Install scripts: " << cmakeScripts << std::endl);
  458. std::vector<std::string> cmakeScriptsVector = cmExpandedList(cmakeScripts);
  459. for (std::string const& installScript : cmakeScriptsVector) {
  460. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  461. "- Install script: " << installScript << std::endl);
  462. if (setDestDir) {
  463. // For DESTDIR based packaging, use the *project*
  464. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  465. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as the
  466. // value of the CPACK_INSTALL_PREFIX variable.
  467. std::string dir;
  468. if (this->GetOption("CPACK_INSTALL_PREFIX")) {
  469. dir += *this->GetOption("CPACK_INSTALL_PREFIX");
  470. }
  471. this->SetOption("CMAKE_INSTALL_PREFIX", dir.c_str());
  472. cmCPackLogger(
  473. cmCPackLog::LOG_DEBUG,
  474. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (this->SetOption)"
  475. << std::endl);
  476. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  477. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  478. << std::endl);
  479. } else {
  480. this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
  481. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  482. "- Using non-DESTDIR install... (this->SetOption)"
  483. << std::endl);
  484. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  485. "- Setting CMAKE_INSTALL_PREFIX to '"
  486. << tempInstallDirectory << "'" << std::endl);
  487. }
  488. this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
  489. tempInstallDirectory.c_str());
  490. this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
  491. tempInstallDirectory.c_str());
  492. bool res = this->MakefileMap->ReadListFile(installScript);
  493. if (cmSystemTools::GetErrorOccuredFlag() || !res) {
  494. return 0;
  495. }
  496. }
  497. }
  498. return 1;
  499. }
  500. int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
  501. bool setDestDir, const std::string& baseTempInstallDirectory,
  502. const mode_t* default_dir_mode)
  503. {
  504. cmProp cmakeProjects = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
  505. cmProp cmakeGenerator = this->GetOption("CPACK_CMAKE_GENERATOR");
  506. std::string absoluteDestFiles;
  507. if (cmNonempty(cmakeProjects)) {
  508. if (!cmakeGenerator) {
  509. cmCPackLogger(cmCPackLog::LOG_ERROR,
  510. "CPACK_INSTALL_CMAKE_PROJECTS is specified, but "
  511. "CPACK_CMAKE_GENERATOR is not. CPACK_CMAKE_GENERATOR "
  512. "is required to install the project."
  513. << std::endl);
  514. return 0;
  515. }
  516. std::vector<std::string> cmakeProjectsVector =
  517. cmExpandedList(cmakeProjects);
  518. std::vector<std::string>::iterator it;
  519. for (it = cmakeProjectsVector.begin(); it != cmakeProjectsVector.end();
  520. ++it) {
  521. if (it + 1 == cmakeProjectsVector.end() ||
  522. it + 2 == cmakeProjectsVector.end() ||
  523. it + 3 == cmakeProjectsVector.end()) {
  524. cmCPackLogger(
  525. cmCPackLog::LOG_ERROR,
  526. "Not enough items on list: CPACK_INSTALL_CMAKE_PROJECTS. "
  527. "CPACK_INSTALL_CMAKE_PROJECTS should hold quadruplet of install "
  528. "directory, install project name, install component, and install "
  529. "subdirectory."
  530. << std::endl);
  531. return 0;
  532. }
  533. std::string installDirectory = *it;
  534. ++it;
  535. std::string installProjectName = *it;
  536. ++it;
  537. cmCPackInstallCMakeProject project;
  538. project.Directory = installDirectory;
  539. project.ProjectName = installProjectName;
  540. project.Component = *it;
  541. ++it;
  542. project.SubDirectory = *it;
  543. std::vector<std::string> componentsVector;
  544. bool componentInstall = false;
  545. /*
  546. * We do a component install iff
  547. * - the CPack generator support component
  548. * - the user did not request Monolithic install
  549. * (this works at CPack time too)
  550. */
  551. if (this->SupportsComponentInstallation() &&
  552. !(this->IsOn("CPACK_MONOLITHIC_INSTALL"))) {
  553. // Determine the installation types for this project (if provided).
  554. std::string installTypesVar = "CPACK_" +
  555. cmSystemTools::UpperCase(project.Component) + "_INSTALL_TYPES";
  556. cmProp installTypes = this->GetOption(installTypesVar);
  557. if (cmNonempty(installTypes)) {
  558. std::vector<std::string> installTypesVector =
  559. cmExpandedList(installTypes);
  560. for (std::string const& installType : installTypesVector) {
  561. project.InstallationTypes.push_back(
  562. this->GetInstallationType(project.ProjectName, installType));
  563. }
  564. }
  565. // Determine the set of components that will be used in this project
  566. std::string componentsVar =
  567. "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(project.Component);
  568. cmProp components = this->GetOption(componentsVar);
  569. if (cmNonempty(components)) {
  570. cmExpandList(components, componentsVector);
  571. for (std::string const& comp : componentsVector) {
  572. project.Components.push_back(
  573. this->GetComponent(project.ProjectName, comp));
  574. }
  575. componentInstall = true;
  576. }
  577. }
  578. if (componentsVector.empty()) {
  579. componentsVector.push_back(project.Component);
  580. }
  581. std::vector<std::string> buildConfigs;
  582. // Try get configuration names given via `-C` CLI option
  583. cmExpandList(this->GetOption("CPACK_BUILD_CONFIG"), buildConfigs);
  584. // Remove duplicates
  585. std::sort(buildConfigs.begin(), buildConfigs.end());
  586. buildConfigs.erase(std::unique(buildConfigs.begin(), buildConfigs.end()),
  587. buildConfigs.end());
  588. // Ensure we have at least one configuration.
  589. if (buildConfigs.empty()) {
  590. buildConfigs.emplace_back();
  591. }
  592. std::unique_ptr<cmGlobalGenerator> globalGenerator =
  593. this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
  594. cmakeGenerator);
  595. if (!globalGenerator) {
  596. cmCPackLogger(cmCPackLog::LOG_ERROR,
  597. "Specified package generator not found. "
  598. "CPACK_CMAKE_GENERATOR value is invalid."
  599. << std::endl);
  600. return 0;
  601. }
  602. // set the global flag for unix style paths on cmSystemTools as
  603. // soon as the generator is set. This allows gmake to be used
  604. // on windows.
  605. cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
  606. // Run the installation for the selected build configurations
  607. for (auto const& buildConfig : buildConfigs) {
  608. if (!this->RunPreinstallTarget(project.ProjectName, project.Directory,
  609. globalGenerator.get(), buildConfig)) {
  610. return 0;
  611. }
  612. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  613. "- Install project: " << project.ProjectName << " ["
  614. << buildConfig << ']'
  615. << std::endl);
  616. // Run the installation for each component
  617. for (std::string const& component : componentsVector) {
  618. if (!this->InstallCMakeProject(
  619. setDestDir, project.Directory, baseTempInstallDirectory,
  620. default_dir_mode, component, componentInstall,
  621. project.SubDirectory, buildConfig, absoluteDestFiles)) {
  622. return 0;
  623. }
  624. }
  625. }
  626. this->CMakeProjects.emplace_back(std::move(project));
  627. }
  628. }
  629. this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
  630. absoluteDestFiles.c_str());
  631. return 1;
  632. }
  633. int cmCPackGenerator::RunPreinstallTarget(
  634. const std::string& installProjectName, const std::string& installDirectory,
  635. cmGlobalGenerator* globalGenerator, const std::string& buildConfig)
  636. {
  637. // Does this generator require pre-install?
  638. if (const char* preinstall = globalGenerator->GetPreinstallTargetName()) {
  639. std::string buildCommand = globalGenerator->GenerateCMakeBuildCommand(
  640. preinstall, buildConfig, "", "", false);
  641. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  642. "- Install command: " << buildCommand << std::endl);
  643. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  644. "- Run preinstall target for: " << installProjectName
  645. << std::endl);
  646. std::string output;
  647. int retVal = 1;
  648. bool resB = cmSystemTools::RunSingleCommand(
  649. buildCommand, &output, &output, &retVal, installDirectory.c_str(),
  650. this->GeneratorVerbose, cmDuration::zero());
  651. if (!resB || retVal) {
  652. std::string tmpFile = cmStrCat(
  653. this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/PreinstallOutput.log");
  654. cmGeneratedFileStream ofs(tmpFile);
  655. ofs << "# Run command: " << buildCommand << std::endl
  656. << "# Directory: " << installDirectory << std::endl
  657. << "# Output:" << std::endl
  658. << output << std::endl;
  659. cmCPackLogger(cmCPackLog::LOG_ERROR,
  660. "Problem running install command: "
  661. << buildCommand << std::endl
  662. << "Please check " << tmpFile << " for errors"
  663. << std::endl);
  664. return 0;
  665. }
  666. }
  667. return 1;
  668. }
  669. int cmCPackGenerator::InstallCMakeProject(
  670. bool setDestDir, const std::string& installDirectory,
  671. const std::string& baseTempInstallDirectory, const mode_t* default_dir_mode,
  672. const std::string& component, bool componentInstall,
  673. const std::string& installSubDirectory, const std::string& buildConfig,
  674. std::string& absoluteDestFiles)
  675. {
  676. std::string tempInstallDirectory = baseTempInstallDirectory;
  677. std::string installFile = installDirectory + "/cmake_install.cmake";
  678. if (componentInstall) {
  679. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  680. "- Install component: " << component << std::endl);
  681. }
  682. cmake cm(cmake::RoleScript, cmState::CPack);
  683. cm.SetHomeDirectory("");
  684. cm.SetHomeOutputDirectory("");
  685. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  686. cm.AddCMakePaths();
  687. cm.SetProgressCallback([this](const std::string& msg, float prog) {
  688. this->DisplayVerboseOutput(msg, prog);
  689. });
  690. cm.SetTrace(this->Trace);
  691. cm.SetTraceExpand(this->TraceExpand);
  692. cmGlobalGenerator gg(&cm);
  693. cmMakefile mf(&gg, cm.GetCurrentSnapshot());
  694. if (!installSubDirectory.empty() && installSubDirectory != "/" &&
  695. installSubDirectory != ".") {
  696. tempInstallDirectory += installSubDirectory;
  697. }
  698. if (componentInstall) {
  699. tempInstallDirectory += "/";
  700. // Some CPack generators would rather chose
  701. // the local installation directory suffix.
  702. // Some (e.g. RPM) use
  703. // one install directory for each component **GROUP**
  704. // instead of the default
  705. // one install directory for each component.
  706. tempInstallDirectory += this->GetComponentInstallDirNameSuffix(component);
  707. if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) {
  708. tempInstallDirectory += "/";
  709. tempInstallDirectory += *this->GetOption("CPACK_PACKAGE_FILE_NAME");
  710. }
  711. }
  712. cmProp default_dir_inst_permissions =
  713. this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
  714. if (cmNonempty(default_dir_inst_permissions)) {
  715. mf.AddDefinition("CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS",
  716. default_dir_inst_permissions);
  717. }
  718. if (!setDestDir) {
  719. tempInstallDirectory += this->GetPackagingInstallPrefix();
  720. }
  721. if (setDestDir) {
  722. // For DESTDIR based packaging, use the *project*
  723. // CMAKE_INSTALL_PREFIX underneath the tempInstallDirectory. The
  724. // value of the project's CMAKE_INSTALL_PREFIX is sent in here as
  725. // the value of the CPACK_INSTALL_PREFIX variable.
  726. //
  727. // If DESTDIR has been 'internally set ON' this means that
  728. // the underlying CPack specific generator did ask for that
  729. // In this case we may override CPACK_INSTALL_PREFIX with
  730. // CPACK_PACKAGING_INSTALL_PREFIX
  731. // I know this is tricky and awkward but it's the price for
  732. // CPACK_SET_DESTDIR backward compatibility.
  733. if (cmIsInternallyOn(this->GetOption("CPACK_SET_DESTDIR"))) {
  734. this->SetOption(
  735. "CPACK_INSTALL_PREFIX",
  736. this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX").GetCStr());
  737. }
  738. std::string dir;
  739. if (this->GetOption("CPACK_INSTALL_PREFIX")) {
  740. dir += *this->GetOption("CPACK_INSTALL_PREFIX");
  741. }
  742. mf.AddDefinition("CMAKE_INSTALL_PREFIX", dir);
  743. cmCPackLogger(
  744. cmCPackLog::LOG_DEBUG,
  745. "- Using DESTDIR + CPACK_INSTALL_PREFIX... (mf.AddDefinition)"
  746. << std::endl);
  747. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  748. "- Setting CMAKE_INSTALL_PREFIX to '" << dir << "'"
  749. << std::endl);
  750. // Make sure that DESTDIR + CPACK_INSTALL_PREFIX directory
  751. // exists:
  752. //
  753. if (cmHasLiteralPrefix(dir, "/")) {
  754. dir = tempInstallDirectory + dir;
  755. } else {
  756. dir = tempInstallDirectory + "/" + dir;
  757. }
  758. /*
  759. * We must re-set DESTDIR for each component
  760. * We must not add the CPACK_INSTALL_PREFIX part because
  761. * it will be added using the override of CMAKE_INSTALL_PREFIX
  762. * The main reason for this awkward trick is that
  763. * are using DESTDIR for 2 different reasons:
  764. * - Because it was asked by the CPack Generator or the user
  765. * using CPACK_SET_DESTDIR
  766. * - Because it was already used for component install
  767. * in order to put things in subdirs...
  768. */
  769. cmSystemTools::PutEnv("DESTDIR=" + tempInstallDirectory);
  770. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  771. "- Creating directory: '" << dir << "'" << std::endl);
  772. if (!cmsys::SystemTools::MakeDirectory(dir, default_dir_mode)) {
  773. cmCPackLogger(cmCPackLog::LOG_ERROR,
  774. "Problem creating temporary directory: " << dir
  775. << std::endl);
  776. return 0;
  777. }
  778. } else {
  779. mf.AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
  780. if (!cmsys::SystemTools::MakeDirectory(tempInstallDirectory,
  781. default_dir_mode)) {
  782. cmCPackLogger(cmCPackLog::LOG_ERROR,
  783. "Problem creating temporary directory: "
  784. << tempInstallDirectory << std::endl);
  785. return 0;
  786. }
  787. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  788. "- Using non-DESTDIR install... (mf.AddDefinition)"
  789. << std::endl);
  790. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  791. "- Setting CMAKE_INSTALL_PREFIX to '" << tempInstallDirectory
  792. << "'" << std::endl);
  793. }
  794. if (!buildConfig.empty()) {
  795. mf.AddDefinition("BUILD_TYPE", buildConfig);
  796. }
  797. std::string installComponentLowerCase = cmSystemTools::LowerCase(component);
  798. if (installComponentLowerCase != "all") {
  799. mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component);
  800. }
  801. // strip on TRUE, ON, 1, one or several file names, but not on
  802. // FALSE, OFF, 0 and an empty string
  803. if (!cmIsOff(this->GetOption("CPACK_STRIP_FILES"))) {
  804. mf.AddDefinition("CMAKE_INSTALL_DO_STRIP", "1");
  805. }
  806. // Remember the list of files before installation
  807. // of the current component (if we are in component install)
  808. std::string const& InstallPrefix = tempInstallDirectory;
  809. std::vector<std::string> filesBefore;
  810. std::string findExpr = tempInstallDirectory;
  811. if (componentInstall) {
  812. cmsys::Glob glB;
  813. findExpr += "/*";
  814. glB.RecurseOn();
  815. glB.SetRecurseListDirs(true);
  816. glB.SetRecurseThroughSymlinks(false);
  817. glB.FindFiles(findExpr);
  818. filesBefore = glB.GetFiles();
  819. std::sort(filesBefore.begin(), filesBefore.end());
  820. }
  821. // If CPack was asked to warn on ABSOLUTE INSTALL DESTINATION
  822. // then forward request to cmake_install.cmake script
  823. if (this->IsOn("CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION")) {
  824. mf.AddDefinition("CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION", "1");
  825. }
  826. // If current CPack generator does support
  827. // ABSOLUTE INSTALL DESTINATION or CPack has been asked for
  828. // then ask cmake_install.cmake script to error out
  829. // as soon as it occurs (before installing file)
  830. if (!this->SupportsAbsoluteDestination() ||
  831. this->IsOn("CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION")) {
  832. mf.AddDefinition("CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION", "1");
  833. }
  834. std::vector<std::string> custom_variables;
  835. this->MakefileMap->GetDefExpandList("CPACK_CUSTOM_INSTALL_VARIABLES",
  836. custom_variables);
  837. for (auto const& custom_variable : custom_variables) {
  838. std::string value;
  839. auto i = custom_variable.find('=');
  840. if (i != std::string::npos) {
  841. value = custom_variable.substr(i + 1);
  842. }
  843. mf.AddDefinition(custom_variable.substr(0, i), value);
  844. }
  845. // do installation
  846. bool res = mf.ReadListFile(installFile);
  847. // forward definition of CMAKE_ABSOLUTE_DESTINATION_FILES
  848. // to CPack (may be used by generators like CPack RPM or DEB)
  849. // in order to transparently handle ABSOLUTE PATH
  850. if (cmProp def = mf.GetDefinition("CMAKE_ABSOLUTE_DESTINATION_FILES")) {
  851. mf.AddDefinition("CPACK_ABSOLUTE_DESTINATION_FILES", *def);
  852. }
  853. // Now rebuild the list of files after installation
  854. // of the current component (if we are in component install)
  855. if (componentInstall) {
  856. cmsys::Glob glA;
  857. glA.RecurseOn();
  858. glA.SetRecurseListDirs(true);
  859. glA.SetRecurseThroughSymlinks(false);
  860. glA.FindFiles(findExpr);
  861. std::vector<std::string> filesAfter = glA.GetFiles();
  862. std::sort(filesAfter.begin(), filesAfter.end());
  863. std::vector<std::string>::iterator diff;
  864. std::vector<std::string> result(filesAfter.size());
  865. diff = std::set_difference(filesAfter.begin(), filesAfter.end(),
  866. filesBefore.begin(), filesBefore.end(),
  867. result.begin());
  868. std::vector<std::string>::iterator fit;
  869. std::string localFileName;
  870. // Populate the File field of each component
  871. for (fit = result.begin(); fit != diff; ++fit) {
  872. localFileName = cmSystemTools::RelativePath(InstallPrefix, *fit);
  873. localFileName =
  874. localFileName.substr(localFileName.find_first_not_of('/'));
  875. this->Components[component].Files.push_back(localFileName);
  876. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  877. "Adding file <" << localFileName << "> to component <"
  878. << component << ">" << std::endl);
  879. }
  880. }
  881. if (cmProp d = mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
  882. if (!absoluteDestFiles.empty()) {
  883. absoluteDestFiles += ";";
  884. }
  885. absoluteDestFiles += *d;
  886. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  887. "Got some ABSOLUTE DESTINATION FILES: " << absoluteDestFiles
  888. << std::endl);
  889. // define component specific var
  890. if (componentInstall) {
  891. std::string absoluteDestFileComponent =
  892. std::string("CPACK_ABSOLUTE_DESTINATION_FILES") + "_" +
  893. this->GetComponentInstallDirNameSuffix(component);
  894. if (nullptr != this->GetOption(absoluteDestFileComponent)) {
  895. std::string absoluteDestFilesListComponent =
  896. cmStrCat(this->GetOption(absoluteDestFileComponent), ';', *d);
  897. this->SetOption(absoluteDestFileComponent,
  898. absoluteDestFilesListComponent.c_str());
  899. } else {
  900. this->SetOption(
  901. absoluteDestFileComponent,
  902. mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES").GetCStr());
  903. }
  904. }
  905. }
  906. if (cmSystemTools::GetErrorOccuredFlag() || !res) {
  907. return 0;
  908. }
  909. return 1;
  910. }
  911. bool cmCPackGenerator::ReadListFile(const char* moduleName)
  912. {
  913. bool retval;
  914. std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
  915. retval = this->MakefileMap->ReadListFile(fullPath);
  916. // include FATAL_ERROR and ERROR in the return status
  917. retval = retval && (!cmSystemTools::GetErrorOccuredFlag());
  918. return retval;
  919. }
  920. void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
  921. const char* value)
  922. {
  923. cmProp def = this->MakefileMap->GetDefinition(op);
  924. if (cmNonempty(def)) {
  925. return;
  926. }
  927. this->SetOption(op, value);
  928. }
  929. void cmCPackGenerator::SetOption(const std::string& op, const char* value)
  930. {
  931. if (!value) {
  932. this->MakefileMap->RemoveDefinition(op);
  933. return;
  934. }
  935. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  936. this->GetNameOfClass() << "::SetOption(" << op << ", " << value
  937. << ")" << std::endl);
  938. this->MakefileMap->AddDefinition(op, value);
  939. }
  940. int cmCPackGenerator::DoPackage()
  941. {
  942. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  943. "Create package using " << this->Name << std::endl);
  944. // Prepare CPack internal name and check
  945. // values for many CPACK_xxx vars
  946. if (!this->PrepareNames()) {
  947. return 0;
  948. }
  949. // Digest Component grouping specification
  950. if (!this->PrepareGroupingKind()) {
  951. return 0;
  952. }
  953. if (cmIsOn(this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY"))) {
  954. cmProp toplevelDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  955. if (cmSystemTools::FileExists(toplevelDirectory)) {
  956. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  957. "Remove toplevel directory: " << toplevelDirectory
  958. << std::endl);
  959. if (!cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory)) {
  960. cmCPackLogger(cmCPackLog::LOG_ERROR,
  961. "Problem removing toplevel directory: "
  962. << toplevelDirectory << std::endl);
  963. return 0;
  964. }
  965. }
  966. }
  967. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  968. "About to install project " << std::endl);
  969. if (!this->InstallProject()) {
  970. return 0;
  971. }
  972. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Done install project " << std::endl);
  973. cmProp tempPackageFileName =
  974. this->GetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  975. cmProp tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  976. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  977. cmsys::Glob gl;
  978. std::string findExpr = cmStrCat(tempDirectory, "/*");
  979. gl.RecurseOn();
  980. gl.SetRecurseListDirs(true);
  981. gl.SetRecurseThroughSymlinks(false);
  982. if (!gl.FindFiles(findExpr)) {
  983. cmCPackLogger(cmCPackLog::LOG_ERROR,
  984. "Cannot find any files in the packaging tree" << std::endl);
  985. return 0;
  986. }
  987. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
  988. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  989. "Package files to: "
  990. << (tempPackageFileName ? *tempPackageFileName : "(NULL)")
  991. << std::endl);
  992. if (cmSystemTools::FileExists(tempPackageFileName)) {
  993. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  994. "Remove old package file" << std::endl);
  995. cmSystemTools::RemoveFile(tempPackageFileName);
  996. }
  997. if (cmIsOn(this->GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))) {
  998. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  999. }
  1000. // The files to be installed
  1001. this->files = gl.GetFiles();
  1002. this->packageFileNames.clear();
  1003. /* Put at least one file name into the list of
  1004. * wanted packageFileNames. The specific generator
  1005. * may update this during PackageFiles.
  1006. * (either putting several names or updating the provided one)
  1007. */
  1008. this->packageFileNames.emplace_back(tempPackageFileName);
  1009. this->toplevel = *tempDirectory;
  1010. { // scope that enables package generators to run internal scripts with
  1011. // latest CMake policies enabled
  1012. cmMakefile::ScopePushPop pp{ this->MakefileMap };
  1013. this->MakefileMap->SetPolicyVersion(cmVersion::GetCMakeVersion(),
  1014. std::string());
  1015. if (!this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) {
  1016. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1017. "Problem compressing the directory" << std::endl);
  1018. return 0;
  1019. }
  1020. }
  1021. // Run post-build actions
  1022. cmProp postBuildScripts = this->GetOption("CPACK_POST_BUILD_SCRIPTS");
  1023. if (postBuildScripts) {
  1024. this->MakefileMap->AddDefinition("CPACK_PACKAGE_FILES",
  1025. cmJoin(this->packageFileNames, ";"));
  1026. const auto scripts = cmExpandedList(postBuildScripts, false);
  1027. for (const auto& script : scripts) {
  1028. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1029. "Executing post-build script: " << script << std::endl);
  1030. if (!this->MakefileMap->ReadListFile(script)) {
  1031. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1032. "The post-build script not found: " << script
  1033. << std::endl);
  1034. return 0;
  1035. }
  1036. }
  1037. }
  1038. /* Prepare checksum algorithm*/
  1039. cmProp algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
  1040. std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(*algo);
  1041. /*
  1042. * Copy the generated packages to final destination
  1043. * - there may be several of them
  1044. * - the initially provided name may have changed
  1045. * (because the specific generator did 'normalize' it)
  1046. */
  1047. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1048. "Copying final package(s) [" << this->packageFileNames.size()
  1049. << "]:" << std::endl);
  1050. /* now copy package one by one */
  1051. for (std::string const& pkgFileName : this->packageFileNames) {
  1052. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1053. std::string filename(cmSystemTools::GetFilenameName(pkgFileName));
  1054. tempPackageFileName = cmProp(pkgFileName);
  1055. tmpPF += "/" + filename;
  1056. const char* packageFileName = tmpPF.c_str();
  1057. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1058. "Copy final package(s): "
  1059. << (tempPackageFileName ? *tempPackageFileName : "(NULL)")
  1060. << " to " << (packageFileName ? packageFileName : "(NULL)")
  1061. << std::endl);
  1062. if (!cmSystemTools::CopyFileIfDifferent(pkgFileName, tmpPF)) {
  1063. cmCPackLogger(
  1064. cmCPackLog::LOG_ERROR,
  1065. "Problem copying the package: "
  1066. << (tempPackageFileName ? *tempPackageFileName : "(NULL)") << " to "
  1067. << (packageFileName ? packageFileName : "(NULL)") << std::endl);
  1068. return 0;
  1069. }
  1070. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1071. "- package: " << packageFileName << " generated."
  1072. << std::endl);
  1073. /* Generate checksum file */
  1074. if (crypto) {
  1075. std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1076. hashFile += "/" + filename;
  1077. hashFile += "." + cmSystemTools::LowerCase(algo);
  1078. cmsys::ofstream outF(hashFile.c_str());
  1079. if (!outF) {
  1080. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1081. "Cannot create checksum file: " << hashFile
  1082. << std::endl);
  1083. return 0;
  1084. }
  1085. outF << crypto->HashFile(packageFileName) << " " << filename << "\n";
  1086. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1087. "- checksum file: " << hashFile << " generated."
  1088. << std::endl);
  1089. }
  1090. }
  1091. return 1;
  1092. }
  1093. int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
  1094. {
  1095. this->MakefileMap = mf;
  1096. this->Name = name;
  1097. // set the running generator name
  1098. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  1099. // Load the project specific config file
  1100. cmProp config = this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  1101. if (config) {
  1102. mf->ReadListFile(config);
  1103. }
  1104. int result = this->InitializeInternal();
  1105. if (cmSystemTools::GetErrorOccuredFlag()) {
  1106. return 0;
  1107. }
  1108. // If a generator subclass did not already set this option in its
  1109. // InitializeInternal implementation, and the project did not already set
  1110. // it, the default value should be:
  1111. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  1112. return result;
  1113. }
  1114. int cmCPackGenerator::InitializeInternal()
  1115. {
  1116. return 1;
  1117. }
  1118. bool cmCPackGenerator::IsSet(const std::string& name) const
  1119. {
  1120. return this->MakefileMap->IsSet(name);
  1121. }
  1122. bool cmCPackGenerator::IsOn(const std::string& name) const
  1123. {
  1124. return cmIsOn(this->GetOption(name));
  1125. }
  1126. bool cmCPackGenerator::IsSetToOff(const std::string& op) const
  1127. {
  1128. cmProp ret = this->MakefileMap->GetDefinition(op);
  1129. if (cmNonempty(ret)) {
  1130. return cmIsOff(*ret);
  1131. }
  1132. return false;
  1133. }
  1134. bool cmCPackGenerator::IsSetToEmpty(const std::string& op) const
  1135. {
  1136. cmProp ret = this->MakefileMap->GetDefinition(op);
  1137. if (ret) {
  1138. return ret->empty();
  1139. }
  1140. return false;
  1141. }
  1142. cmProp cmCPackGenerator::GetOption(const std::string& op) const
  1143. {
  1144. cmProp ret = this->MakefileMap->GetDefinition(op);
  1145. if (!ret) {
  1146. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1147. "Warning, GetOption return NULL for: " << op << std::endl);
  1148. }
  1149. return ret;
  1150. }
  1151. std::vector<std::string> cmCPackGenerator::GetOptions() const
  1152. {
  1153. return this->MakefileMap->GetDefinitions();
  1154. }
  1155. int cmCPackGenerator::PackageFiles()
  1156. {
  1157. return 0;
  1158. }
  1159. const char* cmCPackGenerator::GetInstallPath()
  1160. {
  1161. if (!this->InstallPath.empty()) {
  1162. return this->InstallPath.c_str();
  1163. }
  1164. #if defined(_WIN32) && !defined(__CYGWIN__)
  1165. std::string prgfiles;
  1166. std::string sysDrive;
  1167. if (cmsys::SystemTools::GetEnv("ProgramFiles", prgfiles)) {
  1168. this->InstallPath = prgfiles;
  1169. } else if (cmsys::SystemTools::GetEnv("SystemDrive", sysDrive)) {
  1170. this->InstallPath = cmStrCat(sysDrive, "/Program Files");
  1171. } else {
  1172. this->InstallPath = "c:/Program Files";
  1173. }
  1174. this->InstallPath += "/";
  1175. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1176. this->InstallPath += "-";
  1177. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1178. #elif defined(__HAIKU__)
  1179. char dir[B_PATH_NAME_LENGTH];
  1180. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) ==
  1181. B_OK) {
  1182. this->InstallPath = dir;
  1183. } else {
  1184. this->InstallPath = "/boot/system";
  1185. }
  1186. #else
  1187. this->InstallPath = "/usr/local/";
  1188. #endif
  1189. return this->InstallPath.c_str();
  1190. }
  1191. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1192. {
  1193. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1194. "GetPackagingInstallPrefix: '"
  1195. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'"
  1196. << std::endl);
  1197. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX")->c_str();
  1198. }
  1199. std::string cmCPackGenerator::FindTemplate(const char* name)
  1200. {
  1201. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1202. "Look for template: " << (name ? name : "(NULL)")
  1203. << std::endl);
  1204. // Search CMAKE_MODULE_PATH for a custom template.
  1205. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1206. if (ffile.empty()) {
  1207. // Fall back to our internal builtin default.
  1208. ffile = cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules/Internal/CPack/",
  1209. name);
  1210. cmSystemTools::ConvertToUnixSlashes(ffile);
  1211. if (!cmSystemTools::FileExists(ffile)) {
  1212. ffile.clear();
  1213. }
  1214. }
  1215. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1216. "Found template: " << ffile << std::endl);
  1217. return ffile;
  1218. }
  1219. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1220. std::string& outString)
  1221. {
  1222. this->MakefileMap->ConfigureString(inString, outString, true, false);
  1223. return true;
  1224. }
  1225. bool cmCPackGenerator::ConfigureFile(const std::string& inName,
  1226. const std::string& outName,
  1227. bool copyOnly /* = false */)
  1228. {
  1229. return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
  1230. false) == 1;
  1231. }
  1232. int cmCPackGenerator::CleanTemporaryDirectory()
  1233. {
  1234. std::string tempInstallDirectory =
  1235. this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1236. if (cmsys::SystemTools::FileExists(tempInstallDirectory)) {
  1237. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1238. "- Clean temporary : " << tempInstallDirectory << std::endl);
  1239. if (!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory)) {
  1240. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1241. "Problem removing temporary directory: "
  1242. << tempInstallDirectory << std::endl);
  1243. return 0;
  1244. }
  1245. }
  1246. return 1;
  1247. }
  1248. cmInstalledFile const* cmCPackGenerator::GetInstalledFile(
  1249. std::string const& name) const
  1250. {
  1251. cmake const* cm = this->MakefileMap->GetCMakeInstance();
  1252. return cm->GetInstalledFile(name);
  1253. }
  1254. int cmCPackGenerator::PrepareGroupingKind()
  1255. {
  1256. // find a component package method specified by the user
  1257. ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
  1258. if (this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")) {
  1259. method = ONE_PACKAGE;
  1260. }
  1261. if (this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS")) {
  1262. method = ONE_PACKAGE_PER_COMPONENT;
  1263. }
  1264. if (this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP")) {
  1265. method = ONE_PACKAGE_PER_GROUP;
  1266. }
  1267. // Second way to specify grouping
  1268. std::string groupingType = *this->GetOption("CPACK_COMPONENTS_GROUPING");
  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. cmProp groupDispName = this->GetOption(groupDispVar);
  1342. if (groupDispName) {
  1343. suffix = "-" + *groupDispName;
  1344. }
  1345. }
  1346. /* the [single] component case */
  1347. else {
  1348. std::string dispVar = "CPACK_COMPONENT_" +
  1349. cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1350. cmProp dispName = this->GetOption(dispVar);
  1351. if (dispName) {
  1352. suffix = "-" + *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. cmProp 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. cmProp 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. cmProp archiveFile = this->GetOption(macroPrefix + "_ARCHIVE_FILE");
  1421. if (cmNonempty(archiveFile)) {
  1422. component->ArchiveFile = *archiveFile;
  1423. }
  1424. cmProp plist = this->GetOption(macroPrefix + "_PLIST");
  1425. if (cmNonempty(plist)) {
  1426. component->Plist = *plist;
  1427. }
  1428. cmProp 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. cmProp description = this->GetOption(macroPrefix + "_DESCRIPTION");
  1436. if (cmNonempty(description)) {
  1437. component->Description = *description;
  1438. }
  1439. // Determine the installation types.
  1440. cmProp 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. cmProp 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. cmProp displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1474. if (cmNonempty(displayName)) {
  1475. group->DisplayName = *displayName;
  1476. } else {
  1477. group->DisplayName = group->Name;
  1478. }
  1479. cmProp 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. cmProp parentGroupName = this->GetOption(macroPrefix + "_PARENT_GROUP");
  1486. if (cmNonempty(parentGroupName)) {
  1487. group->ParentGroup =
  1488. this->GetComponentGroup(projectName, parentGroupName);
  1489. group->ParentGroup->Subgroups.push_back(group);
  1490. } else {
  1491. group->ParentGroup = nullptr;
  1492. }
  1493. }
  1494. return group;
  1495. }