cmCPackGenerator.cxx 57 KB

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