cmCPackGenerator.cxx 57 KB

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