cmCPackGenerator.cxx 59 KB

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