cmCPackGenerator.cxx 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  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. template <typename ValueType>
  921. void cmCPackGenerator::StoreOptionIfNotSet(const std::string& op,
  922. ValueType value)
  923. {
  924. cmProp def = this->MakefileMap->GetDefinition(op);
  925. if (cmNonempty(def)) {
  926. return;
  927. }
  928. this->StoreOption(op, value);
  929. }
  930. void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
  931. const char* value)
  932. {
  933. this->StoreOptionIfNotSet(op, value);
  934. }
  935. void cmCPackGenerator::SetOptionIfNotSet(const std::string& op, cmProp value)
  936. {
  937. this->StoreOptionIfNotSet(op, value);
  938. }
  939. template <typename ValueType>
  940. void cmCPackGenerator::StoreOption(const std::string& op, ValueType value)
  941. {
  942. if (!value) {
  943. this->MakefileMap->RemoveDefinition(op);
  944. return;
  945. }
  946. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  947. this->GetNameOfClass() << "::SetOption(" << op << ", " << value
  948. << ")" << std::endl);
  949. this->MakefileMap->AddDefinition(op, value);
  950. }
  951. void cmCPackGenerator::SetOption(const std::string& op, const char* value)
  952. {
  953. this->StoreOption(op, value);
  954. }
  955. void cmCPackGenerator::SetOption(const std::string& op, cmProp value)
  956. {
  957. this->StoreOption(op, value);
  958. }
  959. int cmCPackGenerator::DoPackage()
  960. {
  961. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  962. "Create package using " << this->Name << std::endl);
  963. // Prepare CPack internal name and check
  964. // values for many CPACK_xxx vars
  965. if (!this->PrepareNames()) {
  966. return 0;
  967. }
  968. // Digest Component grouping specification
  969. if (!this->PrepareGroupingKind()) {
  970. return 0;
  971. }
  972. if (cmIsOn(this->GetOption("CPACK_REMOVE_TOPLEVEL_DIRECTORY"))) {
  973. cmProp toplevelDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  974. if (cmSystemTools::FileExists(toplevelDirectory)) {
  975. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  976. "Remove toplevel directory: " << toplevelDirectory
  977. << std::endl);
  978. if (!cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory)) {
  979. cmCPackLogger(cmCPackLog::LOG_ERROR,
  980. "Problem removing toplevel directory: "
  981. << toplevelDirectory << std::endl);
  982. return 0;
  983. }
  984. }
  985. }
  986. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  987. "About to install project " << std::endl);
  988. if (!this->InstallProject()) {
  989. return 0;
  990. }
  991. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Done install project " << std::endl);
  992. cmProp tempPackageFileName =
  993. this->GetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME");
  994. cmProp tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  995. cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
  996. cmsys::Glob gl;
  997. std::string findExpr = cmStrCat(tempDirectory, "/*");
  998. gl.RecurseOn();
  999. gl.SetRecurseListDirs(true);
  1000. gl.SetRecurseThroughSymlinks(false);
  1001. if (!gl.FindFiles(findExpr)) {
  1002. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1003. "Cannot find any files in the packaging tree" << std::endl);
  1004. return 0;
  1005. }
  1006. cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
  1007. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1008. "Package files to: "
  1009. << (tempPackageFileName ? *tempPackageFileName : "(NULL)")
  1010. << std::endl);
  1011. if (cmSystemTools::FileExists(tempPackageFileName)) {
  1012. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1013. "Remove old package file" << std::endl);
  1014. cmSystemTools::RemoveFile(tempPackageFileName);
  1015. }
  1016. if (cmIsOn(this->GetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY"))) {
  1017. tempDirectory = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
  1018. }
  1019. // The files to be installed
  1020. this->files = gl.GetFiles();
  1021. this->packageFileNames.clear();
  1022. /* Put at least one file name into the list of
  1023. * wanted packageFileNames. The specific generator
  1024. * may update this during PackageFiles.
  1025. * (either putting several names or updating the provided one)
  1026. */
  1027. this->packageFileNames.emplace_back(tempPackageFileName);
  1028. this->toplevel = *tempDirectory;
  1029. { // scope that enables package generators to run internal scripts with
  1030. // latest CMake policies enabled
  1031. cmMakefile::ScopePushPop pp{ this->MakefileMap };
  1032. this->MakefileMap->SetPolicyVersion(cmVersion::GetCMakeVersion(),
  1033. std::string());
  1034. if (!this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) {
  1035. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1036. "Problem compressing the directory" << std::endl);
  1037. return 0;
  1038. }
  1039. }
  1040. // Run post-build actions
  1041. cmProp postBuildScripts = this->GetOption("CPACK_POST_BUILD_SCRIPTS");
  1042. if (postBuildScripts) {
  1043. this->MakefileMap->AddDefinition("CPACK_PACKAGE_FILES",
  1044. cmJoin(this->packageFileNames, ";"));
  1045. const auto scripts = cmExpandedList(postBuildScripts, false);
  1046. for (const auto& script : scripts) {
  1047. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1048. "Executing post-build script: " << script << std::endl);
  1049. if (!this->MakefileMap->ReadListFile(script)) {
  1050. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1051. "The post-build script not found: " << script
  1052. << std::endl);
  1053. return 0;
  1054. }
  1055. }
  1056. }
  1057. /* Prepare checksum algorithm*/
  1058. cmProp algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
  1059. std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(*algo);
  1060. /*
  1061. * Copy the generated packages to final destination
  1062. * - there may be several of them
  1063. * - the initially provided name may have changed
  1064. * (because the specific generator did 'normalize' it)
  1065. */
  1066. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1067. "Copying final package(s) [" << this->packageFileNames.size()
  1068. << "]:" << std::endl);
  1069. /* now copy package one by one */
  1070. for (std::string const& pkgFileName : this->packageFileNames) {
  1071. std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1072. std::string filename(cmSystemTools::GetFilenameName(pkgFileName));
  1073. tempPackageFileName = cmProp(pkgFileName);
  1074. tmpPF += "/" + filename;
  1075. const char* packageFileName = tmpPF.c_str();
  1076. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1077. "Copy final package(s): "
  1078. << (tempPackageFileName ? *tempPackageFileName : "(NULL)")
  1079. << " to " << (packageFileName ? packageFileName : "(NULL)")
  1080. << std::endl);
  1081. if (!cmSystemTools::CopyFileIfDifferent(pkgFileName, tmpPF)) {
  1082. cmCPackLogger(
  1083. cmCPackLog::LOG_ERROR,
  1084. "Problem copying the package: "
  1085. << (tempPackageFileName ? *tempPackageFileName : "(NULL)") << " to "
  1086. << (packageFileName ? packageFileName : "(NULL)") << std::endl);
  1087. return 0;
  1088. }
  1089. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1090. "- package: " << packageFileName << " generated."
  1091. << std::endl);
  1092. /* Generate checksum file */
  1093. if (crypto) {
  1094. std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
  1095. hashFile += "/" + filename;
  1096. hashFile += "." + cmSystemTools::LowerCase(algo);
  1097. cmsys::ofstream outF(hashFile.c_str());
  1098. if (!outF) {
  1099. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1100. "Cannot create checksum file: " << hashFile
  1101. << std::endl);
  1102. return 0;
  1103. }
  1104. outF << crypto->HashFile(packageFileName) << " " << filename << "\n";
  1105. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1106. "- checksum file: " << hashFile << " generated."
  1107. << std::endl);
  1108. }
  1109. }
  1110. return 1;
  1111. }
  1112. int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
  1113. {
  1114. this->MakefileMap = mf;
  1115. this->Name = name;
  1116. // set the running generator name
  1117. this->SetOption("CPACK_GENERATOR", this->Name.c_str());
  1118. // Load the project specific config file
  1119. cmProp config = this->GetOption("CPACK_PROJECT_CONFIG_FILE");
  1120. if (config) {
  1121. mf->ReadListFile(config);
  1122. }
  1123. int result = this->InitializeInternal();
  1124. if (cmSystemTools::GetErrorOccuredFlag()) {
  1125. return 0;
  1126. }
  1127. // If a generator subclass did not already set this option in its
  1128. // InitializeInternal implementation, and the project did not already set
  1129. // it, the default value should be:
  1130. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/");
  1131. return result;
  1132. }
  1133. int cmCPackGenerator::InitializeInternal()
  1134. {
  1135. return 1;
  1136. }
  1137. bool cmCPackGenerator::IsSet(const std::string& name) const
  1138. {
  1139. return this->MakefileMap->IsSet(name);
  1140. }
  1141. bool cmCPackGenerator::IsOn(const std::string& name) const
  1142. {
  1143. return cmIsOn(this->GetOption(name));
  1144. }
  1145. bool cmCPackGenerator::IsSetToOff(const std::string& op) const
  1146. {
  1147. cmProp ret = this->MakefileMap->GetDefinition(op);
  1148. if (cmNonempty(ret)) {
  1149. return cmIsOff(*ret);
  1150. }
  1151. return false;
  1152. }
  1153. bool cmCPackGenerator::IsSetToEmpty(const std::string& op) const
  1154. {
  1155. cmProp ret = this->MakefileMap->GetDefinition(op);
  1156. if (ret) {
  1157. return ret->empty();
  1158. }
  1159. return false;
  1160. }
  1161. cmProp cmCPackGenerator::GetOption(const std::string& op) const
  1162. {
  1163. cmProp ret = this->MakefileMap->GetDefinition(op);
  1164. if (!ret) {
  1165. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1166. "Warning, GetOption return NULL for: " << op << std::endl);
  1167. }
  1168. return ret;
  1169. }
  1170. std::vector<std::string> cmCPackGenerator::GetOptions() const
  1171. {
  1172. return this->MakefileMap->GetDefinitions();
  1173. }
  1174. int cmCPackGenerator::PackageFiles()
  1175. {
  1176. return 0;
  1177. }
  1178. const char* cmCPackGenerator::GetInstallPath()
  1179. {
  1180. if (!this->InstallPath.empty()) {
  1181. return this->InstallPath.c_str();
  1182. }
  1183. #if defined(_WIN32) && !defined(__CYGWIN__)
  1184. std::string prgfiles;
  1185. std::string sysDrive;
  1186. if (cmsys::SystemTools::GetEnv("ProgramFiles", prgfiles)) {
  1187. this->InstallPath = prgfiles;
  1188. } else if (cmsys::SystemTools::GetEnv("SystemDrive", sysDrive)) {
  1189. this->InstallPath = cmStrCat(sysDrive, "/Program Files");
  1190. } else {
  1191. this->InstallPath = "c:/Program Files";
  1192. }
  1193. this->InstallPath += "/";
  1194. this->InstallPath += this->GetOption("CPACK_PACKAGE_NAME");
  1195. this->InstallPath += "-";
  1196. this->InstallPath += this->GetOption("CPACK_PACKAGE_VERSION");
  1197. #elif defined(__HAIKU__)
  1198. char dir[B_PATH_NAME_LENGTH];
  1199. if (find_directory(B_SYSTEM_DIRECTORY, -1, false, dir, sizeof(dir)) ==
  1200. B_OK) {
  1201. this->InstallPath = dir;
  1202. } else {
  1203. this->InstallPath = "/boot/system";
  1204. }
  1205. #else
  1206. this->InstallPath = "/usr/local/";
  1207. #endif
  1208. return this->InstallPath.c_str();
  1209. }
  1210. const char* cmCPackGenerator::GetPackagingInstallPrefix()
  1211. {
  1212. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1213. "GetPackagingInstallPrefix: '"
  1214. << this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'"
  1215. << std::endl);
  1216. return this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX")->c_str();
  1217. }
  1218. std::string cmCPackGenerator::FindTemplate(const char* name)
  1219. {
  1220. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1221. "Look for template: " << (name ? name : "(NULL)")
  1222. << std::endl);
  1223. // Search CMAKE_MODULE_PATH for a custom template.
  1224. std::string ffile = this->MakefileMap->GetModulesFile(name);
  1225. if (ffile.empty()) {
  1226. // Fall back to our internal builtin default.
  1227. ffile = cmStrCat(cmSystemTools::GetCMakeRoot(), "/Modules/Internal/CPack/",
  1228. name);
  1229. cmSystemTools::ConvertToUnixSlashes(ffile);
  1230. if (!cmSystemTools::FileExists(ffile)) {
  1231. ffile.clear();
  1232. }
  1233. }
  1234. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  1235. "Found template: " << ffile << std::endl);
  1236. return ffile;
  1237. }
  1238. bool cmCPackGenerator::ConfigureString(const std::string& inString,
  1239. std::string& outString)
  1240. {
  1241. this->MakefileMap->ConfigureString(inString, outString, true, false);
  1242. return true;
  1243. }
  1244. bool cmCPackGenerator::ConfigureFile(const std::string& inName,
  1245. const std::string& outName,
  1246. bool copyOnly /* = false */)
  1247. {
  1248. return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
  1249. false) == 1;
  1250. }
  1251. int cmCPackGenerator::CleanTemporaryDirectory()
  1252. {
  1253. std::string tempInstallDirectory =
  1254. this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
  1255. if (cmsys::SystemTools::FileExists(tempInstallDirectory)) {
  1256. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  1257. "- Clean temporary : " << tempInstallDirectory << std::endl);
  1258. if (!cmSystemTools::RepeatedRemoveDirectory(tempInstallDirectory)) {
  1259. cmCPackLogger(cmCPackLog::LOG_ERROR,
  1260. "Problem removing temporary directory: "
  1261. << tempInstallDirectory << std::endl);
  1262. return 0;
  1263. }
  1264. }
  1265. return 1;
  1266. }
  1267. cmInstalledFile const* cmCPackGenerator::GetInstalledFile(
  1268. std::string const& name) const
  1269. {
  1270. cmake const* cm = this->MakefileMap->GetCMakeInstance();
  1271. return cm->GetInstalledFile(name);
  1272. }
  1273. int cmCPackGenerator::PrepareGroupingKind()
  1274. {
  1275. // find a component package method specified by the user
  1276. ComponentPackageMethod method = UNKNOWN_COMPONENT_PACKAGE_METHOD;
  1277. if (this->GetOption("CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE")) {
  1278. method = ONE_PACKAGE;
  1279. }
  1280. if (this->GetOption("CPACK_COMPONENTS_IGNORE_GROUPS")) {
  1281. method = ONE_PACKAGE_PER_COMPONENT;
  1282. }
  1283. if (this->GetOption("CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP")) {
  1284. method = ONE_PACKAGE_PER_GROUP;
  1285. }
  1286. // Second way to specify grouping
  1287. std::string groupingType = *this->GetOption("CPACK_COMPONENTS_GROUPING");
  1288. if (!groupingType.empty()) {
  1289. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1290. "[" << this->Name << "]"
  1291. << " requested component grouping = " << groupingType
  1292. << std::endl);
  1293. if (groupingType == "ALL_COMPONENTS_IN_ONE") {
  1294. method = ONE_PACKAGE;
  1295. } else if (groupingType == "IGNORE") {
  1296. method = ONE_PACKAGE_PER_COMPONENT;
  1297. } else if (groupingType == "ONE_PER_GROUP") {
  1298. method = ONE_PACKAGE_PER_GROUP;
  1299. } else {
  1300. cmCPackLogger(
  1301. cmCPackLog::LOG_WARNING,
  1302. "[" << this->Name << "]"
  1303. << " requested component grouping type <" << groupingType
  1304. << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
  1305. << std::endl);
  1306. }
  1307. }
  1308. // Some components were defined but NO group
  1309. // fallback to default if not group based
  1310. if (method == ONE_PACKAGE_PER_GROUP && this->ComponentGroups.empty() &&
  1311. !this->Components.empty()) {
  1312. if (this->componentPackageMethod == ONE_PACKAGE) {
  1313. method = ONE_PACKAGE;
  1314. } else {
  1315. method = ONE_PACKAGE_PER_COMPONENT;
  1316. }
  1317. cmCPackLogger(
  1318. cmCPackLog::LOG_WARNING,
  1319. "[" << this->Name << "]"
  1320. << " One package per component group requested, "
  1321. << "but NO component groups exist: Ignoring component group."
  1322. << std::endl);
  1323. }
  1324. // if user specified packaging method, override the default packaging
  1325. // method
  1326. if (method != UNKNOWN_COMPONENT_PACKAGE_METHOD) {
  1327. this->componentPackageMethod = method;
  1328. }
  1329. const char* method_names[] = { "ALL_COMPONENTS_IN_ONE", "IGNORE_GROUPS",
  1330. "ONE_PER_GROUP" };
  1331. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  1332. "[" << this->Name << "]"
  1333. << " requested component grouping = "
  1334. << method_names[this->componentPackageMethod]
  1335. << std::endl);
  1336. return 1;
  1337. }
  1338. std::string cmCPackGenerator::GetComponentInstallDirNameSuffix(
  1339. const std::string& componentName)
  1340. {
  1341. return componentName;
  1342. }
  1343. std::string cmCPackGenerator::GetComponentPackageFileName(
  1344. const std::string& initialPackageFileName,
  1345. const std::string& groupOrComponentName, bool isGroupName)
  1346. {
  1347. /*
  1348. * the default behavior is to use the
  1349. * component [group] name as a suffix
  1350. */
  1351. std::string suffix = "-" + groupOrComponentName;
  1352. /* check if we should use DISPLAY name */
  1353. std::string dispNameVar =
  1354. "CPACK_" + this->Name + "_USE_DISPLAY_NAME_IN_FILENAME";
  1355. if (this->IsOn(dispNameVar)) {
  1356. /* the component Group case */
  1357. if (isGroupName) {
  1358. std::string groupDispVar = "CPACK_COMPONENT_GROUP_" +
  1359. cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1360. cmProp groupDispName = this->GetOption(groupDispVar);
  1361. if (groupDispName) {
  1362. suffix = "-" + *groupDispName;
  1363. }
  1364. }
  1365. /* the [single] component case */
  1366. else {
  1367. std::string dispVar = "CPACK_COMPONENT_" +
  1368. cmSystemTools::UpperCase(groupOrComponentName) + "_DISPLAY_NAME";
  1369. cmProp dispName = this->GetOption(dispVar);
  1370. if (dispName) {
  1371. suffix = "-" + *dispName;
  1372. }
  1373. }
  1374. }
  1375. return initialPackageFileName + suffix;
  1376. }
  1377. enum cmCPackGenerator::CPackSetDestdirSupport
  1378. cmCPackGenerator::SupportsSetDestdir() const
  1379. {
  1380. return cmCPackGenerator::SETDESTDIR_SUPPORTED;
  1381. }
  1382. bool cmCPackGenerator::SupportsAbsoluteDestination() const
  1383. {
  1384. return true;
  1385. }
  1386. bool cmCPackGenerator::SupportsComponentInstallation() const
  1387. {
  1388. return false;
  1389. }
  1390. bool cmCPackGenerator::WantsComponentInstallation() const
  1391. {
  1392. return (!this->IsOn("CPACK_MONOLITHIC_INSTALL") &&
  1393. this->SupportsComponentInstallation()
  1394. // check that we have at least one group or component
  1395. && (!this->ComponentGroups.empty() || !this->Components.empty()));
  1396. }
  1397. cmCPackInstallationType* cmCPackGenerator::GetInstallationType(
  1398. const std::string& projectName, const std::string& name)
  1399. {
  1400. (void)projectName;
  1401. bool hasInstallationType = this->InstallationTypes.count(name) != 0;
  1402. cmCPackInstallationType* installType = &this->InstallationTypes[name];
  1403. if (!hasInstallationType) {
  1404. // Define the installation type
  1405. std::string macroPrefix =
  1406. "CPACK_INSTALL_TYPE_" + cmsys::SystemTools::UpperCase(name);
  1407. installType->Name = name;
  1408. cmProp displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1409. if (cmNonempty(displayName)) {
  1410. installType->DisplayName = *displayName;
  1411. } else {
  1412. installType->DisplayName = installType->Name;
  1413. }
  1414. installType->Index = static_cast<unsigned>(this->InstallationTypes.size());
  1415. }
  1416. return installType;
  1417. }
  1418. cmCPackComponent* cmCPackGenerator::GetComponent(
  1419. const std::string& projectName, const std::string& name)
  1420. {
  1421. bool hasComponent = this->Components.count(name) != 0;
  1422. cmCPackComponent* component = &this->Components[name];
  1423. if (!hasComponent) {
  1424. // Define the component
  1425. std::string macroPrefix =
  1426. "CPACK_COMPONENT_" + cmsys::SystemTools::UpperCase(name);
  1427. component->Name = name;
  1428. cmProp displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1429. if (cmNonempty(displayName)) {
  1430. component->DisplayName = *displayName;
  1431. } else {
  1432. component->DisplayName = component->Name;
  1433. }
  1434. component->IsHidden = this->IsOn(macroPrefix + "_HIDDEN");
  1435. component->IsRequired = this->IsOn(macroPrefix + "_REQUIRED");
  1436. component->IsDisabledByDefault = this->IsOn(macroPrefix + "_DISABLED");
  1437. component->IsDownloaded = this->IsOn(macroPrefix + "_DOWNLOADED") ||
  1438. cmIsOn(this->GetOption("CPACK_DOWNLOAD_ALL"));
  1439. cmProp archiveFile = this->GetOption(macroPrefix + "_ARCHIVE_FILE");
  1440. if (cmNonempty(archiveFile)) {
  1441. component->ArchiveFile = *archiveFile;
  1442. }
  1443. cmProp plist = this->GetOption(macroPrefix + "_PLIST");
  1444. if (cmNonempty(plist)) {
  1445. component->Plist = *plist;
  1446. }
  1447. cmProp groupName = this->GetOption(macroPrefix + "_GROUP");
  1448. if (cmNonempty(groupName)) {
  1449. component->Group = this->GetComponentGroup(projectName, groupName);
  1450. component->Group->Components.push_back(component);
  1451. } else {
  1452. component->Group = nullptr;
  1453. }
  1454. cmProp description = this->GetOption(macroPrefix + "_DESCRIPTION");
  1455. if (cmNonempty(description)) {
  1456. component->Description = *description;
  1457. }
  1458. // Determine the installation types.
  1459. cmProp installTypes = this->GetOption(macroPrefix + "_INSTALL_TYPES");
  1460. if (cmNonempty(installTypes)) {
  1461. std::vector<std::string> installTypesVector =
  1462. cmExpandedList(installTypes);
  1463. for (std::string const& installType : installTypesVector) {
  1464. component->InstallationTypes.push_back(
  1465. this->GetInstallationType(projectName, installType));
  1466. }
  1467. }
  1468. // Determine the component dependencies.
  1469. cmProp depends = this->GetOption(macroPrefix + "_DEPENDS");
  1470. if (cmNonempty(depends)) {
  1471. std::vector<std::string> dependsVector = cmExpandedList(depends);
  1472. for (std::string const& depend : dependsVector) {
  1473. cmCPackComponent* child = this->GetComponent(projectName, depend);
  1474. component->Dependencies.push_back(child);
  1475. child->ReverseDependencies.push_back(component);
  1476. }
  1477. }
  1478. }
  1479. return component;
  1480. }
  1481. cmCPackComponentGroup* cmCPackGenerator::GetComponentGroup(
  1482. const std::string& projectName, const std::string& name)
  1483. {
  1484. (void)projectName;
  1485. std::string macroPrefix =
  1486. "CPACK_COMPONENT_GROUP_" + cmsys::SystemTools::UpperCase(name);
  1487. bool hasGroup = this->ComponentGroups.count(name) != 0;
  1488. cmCPackComponentGroup* group = &this->ComponentGroups[name];
  1489. if (!hasGroup) {
  1490. // Define the group
  1491. group->Name = name;
  1492. cmProp displayName = this->GetOption(macroPrefix + "_DISPLAY_NAME");
  1493. if (cmNonempty(displayName)) {
  1494. group->DisplayName = *displayName;
  1495. } else {
  1496. group->DisplayName = group->Name;
  1497. }
  1498. cmProp description = this->GetOption(macroPrefix + "_DESCRIPTION");
  1499. if (cmNonempty(description)) {
  1500. group->Description = *description;
  1501. }
  1502. group->IsBold = this->IsOn(macroPrefix + "_BOLD_TITLE");
  1503. group->IsExpandedByDefault = this->IsOn(macroPrefix + "_EXPANDED");
  1504. cmProp parentGroupName = this->GetOption(macroPrefix + "_PARENT_GROUP");
  1505. if (cmNonempty(parentGroupName)) {
  1506. group->ParentGroup =
  1507. this->GetComponentGroup(projectName, parentGroupName);
  1508. group->ParentGroup->Subgroups.push_back(group);
  1509. } else {
  1510. group->ParentGroup = nullptr;
  1511. }
  1512. }
  1513. return group;
  1514. }