cmCPackIFWInstaller.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 "cmCPackIFWInstaller.h"
  4. #include <cstddef>
  5. #include <sstream>
  6. #include <utility>
  7. #include "cmCPackIFWCommon.h"
  8. #include "cmCPackIFWGenerator.h"
  9. #include "cmCPackIFWPackage.h"
  10. #include "cmCPackIFWRepository.h"
  11. #include "cmCPackLog.h" // IWYU pragma: keep
  12. #include "cmGeneratedFileStream.h"
  13. #include "cmStringAlgorithms.h"
  14. #include "cmSystemTools.h"
  15. #include "cmValue.h"
  16. #include "cmXMLParser.h"
  17. #include "cmXMLWriter.h"
  18. cmCPackIFWInstaller::cmCPackIFWInstaller() = default;
  19. void cmCPackIFWInstaller::printSkippedOptionWarning(
  20. const std::string& optionName, const std::string& optionValue)
  21. {
  22. cmCPackIFWLogger(
  23. WARNING,
  24. "Option "
  25. << optionName << " is set to \"" << optionValue
  26. << "\" but will be skipped because the specified file does not exist."
  27. << std::endl);
  28. }
  29. void cmCPackIFWInstaller::ConfigureFromOptions()
  30. {
  31. // Name;
  32. if (cmValue optIFW_PACKAGE_NAME =
  33. this->GetOption("CPACK_IFW_PACKAGE_NAME")) {
  34. this->Name = *optIFW_PACKAGE_NAME;
  35. } else if (cmValue optPACKAGE_NAME = this->GetOption("CPACK_PACKAGE_NAME")) {
  36. this->Name = *optPACKAGE_NAME;
  37. } else {
  38. this->Name = "Your package";
  39. }
  40. // Title;
  41. if (cmValue optIFW_PACKAGE_TITLE =
  42. this->GetOption("CPACK_IFW_PACKAGE_TITLE")) {
  43. this->Title = *optIFW_PACKAGE_TITLE;
  44. } else if (cmValue optPACKAGE_DESCRIPTION_SUMMARY =
  45. this->GetOption("CPACK_PACKAGE_DESCRIPTION_SUMMARY")) {
  46. this->Title = *optPACKAGE_DESCRIPTION_SUMMARY;
  47. } else {
  48. this->Title = "Your package description";
  49. }
  50. // Version;
  51. if (cmValue option = this->GetOption("CPACK_PACKAGE_VERSION")) {
  52. this->Version = *option;
  53. } else {
  54. this->Version = "1.0.0";
  55. }
  56. // Publisher
  57. if (cmValue optIFW_PACKAGE_PUBLISHER =
  58. this->GetOption("CPACK_IFW_PACKAGE_PUBLISHER")) {
  59. this->Publisher = *optIFW_PACKAGE_PUBLISHER;
  60. } else if (cmValue optPACKAGE_VENDOR =
  61. this->GetOption("CPACK_PACKAGE_VENDOR")) {
  62. this->Publisher = *optPACKAGE_VENDOR;
  63. }
  64. // ProductUrl
  65. if (cmValue option = this->GetOption("CPACK_IFW_PRODUCT_URL")) {
  66. this->ProductUrl = *option;
  67. }
  68. // ApplicationIcon
  69. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_ICON")) {
  70. if (cmSystemTools::FileExists(option)) {
  71. this->InstallerApplicationIcon = *option;
  72. } else {
  73. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_ICON", option);
  74. }
  75. }
  76. // WindowIcon
  77. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_WINDOW_ICON")) {
  78. if (cmSystemTools::FileExists(option)) {
  79. this->InstallerWindowIcon = *option;
  80. } else {
  81. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_WINDOW_ICON", option);
  82. }
  83. }
  84. // RemoveTargetDir
  85. if (this->IsSetToOff("CPACK_IFW_PACKAGE_REMOVE_TARGET_DIR")) {
  86. this->RemoveTargetDir = "false";
  87. } else if (this->IsOn("CPACK_IFW_PACKAGE_REMOVE_TARGET_DIR")) {
  88. this->RemoveTargetDir = "true";
  89. } else {
  90. this->RemoveTargetDir.clear();
  91. }
  92. // Logo
  93. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_LOGO")) {
  94. if (cmSystemTools::FileExists(option)) {
  95. this->Logo = *option;
  96. } else {
  97. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_LOGO", option);
  98. }
  99. }
  100. // Watermark
  101. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_WATERMARK")) {
  102. if (cmSystemTools::FileExists(option)) {
  103. this->Watermark = *option;
  104. } else {
  105. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_WATERMARK", option);
  106. }
  107. }
  108. // Banner
  109. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_BANNER")) {
  110. if (cmSystemTools::FileExists(option)) {
  111. this->Banner = *option;
  112. } else {
  113. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_BANNER", option);
  114. }
  115. }
  116. // Background
  117. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_BACKGROUND")) {
  118. if (cmSystemTools::FileExists(option)) {
  119. this->Background = *option;
  120. } else {
  121. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_BACKGROUND", option);
  122. }
  123. }
  124. // WizardStyle
  125. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_WIZARD_STYLE")) {
  126. // Setting the user value in any case
  127. this->WizardStyle = *option;
  128. // Check known values
  129. if (this->WizardStyle != "Modern" && this->WizardStyle != "Aero" &&
  130. this->WizardStyle != "Mac" && this->WizardStyle != "Classic") {
  131. cmCPackIFWLogger(
  132. WARNING,
  133. "Option CPACK_IFW_PACKAGE_WIZARD_STYLE has unknown value \""
  134. << option << "\". Expected values are: Modern, Aero, Mac, Classic."
  135. << std::endl);
  136. }
  137. }
  138. // StyleSheet
  139. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_STYLE_SHEET")) {
  140. if (cmSystemTools::FileExists(option)) {
  141. this->StyleSheet = *option;
  142. } else {
  143. this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_STYLE_SHEET", option);
  144. }
  145. }
  146. // WizardDefaultWidth
  147. if (cmValue option =
  148. this->GetOption("CPACK_IFW_PACKAGE_WIZARD_DEFAULT_WIDTH")) {
  149. this->WizardDefaultWidth = *option;
  150. }
  151. // WizardDefaultHeight
  152. if (cmValue option =
  153. this->GetOption("CPACK_IFW_PACKAGE_WIZARD_DEFAULT_HEIGHT")) {
  154. this->WizardDefaultHeight = *option;
  155. }
  156. // WizardShowPageList
  157. if (cmValue option =
  158. this->GetOption("CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST")) {
  159. if (!this->IsVersionLess("4.0")) {
  160. if (this->IsSetToOff("CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST")) {
  161. this->WizardShowPageList = "false";
  162. } else if (this->IsOn("CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST")) {
  163. this->WizardShowPageList = "true";
  164. } else {
  165. this->WizardShowPageList.clear();
  166. }
  167. } else {
  168. std::string currentVersionMsg;
  169. if (this->Generator) {
  170. currentVersionMsg =
  171. "QtIFW version " + this->Generator->FrameworkVersion;
  172. } else {
  173. currentVersionMsg = "an older QtIFW version";
  174. }
  175. cmCPackIFWLogger(
  176. WARNING,
  177. "Option CPACK_IFW_PACKAGE_WIZARD_SHOW_PAGE_LIST is set to \""
  178. << option
  179. << "\", but it is only supported with QtIFW version 4.0 or later. "
  180. "It is being ignored because you are using "
  181. << currentVersionMsg << std::endl);
  182. }
  183. }
  184. // TitleColor
  185. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_TITLE_COLOR")) {
  186. this->TitleColor = *option;
  187. }
  188. // Start menu
  189. if (cmValue optIFW_START_MENU_DIR =
  190. this->GetOption("CPACK_IFW_PACKAGE_START_MENU_DIRECTORY")) {
  191. this->StartMenuDir = *optIFW_START_MENU_DIR;
  192. } else {
  193. this->StartMenuDir = this->Name;
  194. }
  195. // Default target directory for installation
  196. if (cmValue optIFW_TARGET_DIRECTORY =
  197. this->GetOption("CPACK_IFW_TARGET_DIRECTORY")) {
  198. this->TargetDir = *optIFW_TARGET_DIRECTORY;
  199. } else if (cmValue optPACKAGE_INSTALL_DIRECTORY =
  200. this->GetOption("CPACK_PACKAGE_INSTALL_DIRECTORY")) {
  201. this->TargetDir =
  202. cmStrCat("@ApplicationsDir@/", optPACKAGE_INSTALL_DIRECTORY);
  203. } else {
  204. this->TargetDir = "@RootDir@/usr/local";
  205. }
  206. // Default target directory for installation with administrator rights
  207. if (cmValue option = this->GetOption("CPACK_IFW_ADMIN_TARGET_DIRECTORY")) {
  208. this->AdminTargetDir = *option;
  209. }
  210. // Maintenance tool
  211. if (cmValue optIFW_MAINTENANCE_TOOL =
  212. this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_NAME")) {
  213. this->MaintenanceToolName = *optIFW_MAINTENANCE_TOOL;
  214. }
  215. // Maintenance tool ini file
  216. if (cmValue optIFW_MAINTENANCE_TOOL_INI =
  217. this->GetOption("CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_INI_FILE")) {
  218. this->MaintenanceToolIniFile = *optIFW_MAINTENANCE_TOOL_INI;
  219. }
  220. // Allow non-ASCII characters
  221. if (this->GetOption("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS")) {
  222. if (this->IsOn("CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS")) {
  223. this->AllowNonAsciiCharacters = "true";
  224. } else {
  225. this->AllowNonAsciiCharacters = "false";
  226. }
  227. }
  228. // DisableCommandLineInterface
  229. if (this->GetOption("CPACK_IFW_PACKAGE_DISABLE_COMMAND_LINE_INTERFACE")) {
  230. if (this->IsOn("CPACK_IFW_PACKAGE_DISABLE_COMMAND_LINE_INTERFACE")) {
  231. this->DisableCommandLineInterface = "true";
  232. } else if (this->IsSetToOff(
  233. "CPACK_IFW_PACKAGE_DISABLE_COMMAND_LINE_INTERFACE")) {
  234. this->DisableCommandLineInterface = "false";
  235. }
  236. }
  237. // Space in path
  238. if (this->GetOption("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH")) {
  239. if (this->IsOn("CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH")) {
  240. this->AllowSpaceInPath = "true";
  241. } else {
  242. this->AllowSpaceInPath = "false";
  243. }
  244. }
  245. // Control script
  246. if (cmValue optIFW_CONTROL_SCRIPT =
  247. this->GetOption("CPACK_IFW_PACKAGE_CONTROL_SCRIPT")) {
  248. this->ControlScript = *optIFW_CONTROL_SCRIPT;
  249. }
  250. // Resources
  251. if (cmValue optIFW_PACKAGE_RESOURCES =
  252. this->GetOption("CPACK_IFW_PACKAGE_RESOURCES")) {
  253. this->Resources.clear();
  254. cmExpandList(optIFW_PACKAGE_RESOURCES, this->Resources);
  255. }
  256. // ProductImages
  257. if (cmValue productImages =
  258. this->GetOption("CPACK_IFW_PACKAGE_PRODUCT_IMAGES")) {
  259. this->ProductImages.clear();
  260. cmExpandList(productImages, this->ProductImages);
  261. }
  262. // Run program, run program arguments, and run program description
  263. if (cmValue program = this->GetOption("CPACK_IFW_PACKAGE_RUN_PROGRAM")) {
  264. this->RunProgram = *program;
  265. }
  266. if (cmValue arguments =
  267. this->GetOption("CPACK_IFW_PACKAGE_RUN_PROGRAM_ARGUMENTS")) {
  268. this->RunProgramArguments.clear();
  269. cmExpandList(arguments, this->RunProgramArguments);
  270. }
  271. if (cmValue description =
  272. this->GetOption("CPACK_IFW_PACKAGE_RUN_PROGRAM_DESCRIPTION")) {
  273. this->RunProgramDescription = *description;
  274. }
  275. #ifdef __APPLE__
  276. // Code signing identity for signing the generated app bundle
  277. if (cmValue id = this->GetOption("CPACK_IFW_PACKAGE_SIGNING_IDENTITY")) {
  278. this->SigningIdentity = *id;
  279. }
  280. #endif
  281. }
  282. /** \class cmCPackIFWResourcesParser
  283. * \brief Helper class that parse resources form .qrc (Qt)
  284. */
  285. class cmCPackIFWResourcesParser : public cmXMLParser
  286. {
  287. public:
  288. explicit cmCPackIFWResourcesParser(cmCPackIFWInstaller* i)
  289. : installer(i)
  290. {
  291. this->path = i->Directory + "/resources";
  292. }
  293. bool ParseResource(size_t r)
  294. {
  295. this->hasFiles = false;
  296. this->hasErrors = false;
  297. this->basePath =
  298. cmSystemTools::GetFilenamePath(this->installer->Resources[r]);
  299. this->ParseFile(this->installer->Resources[r].data());
  300. return this->hasFiles && !this->hasErrors;
  301. }
  302. cmCPackIFWInstaller* installer;
  303. bool file = false;
  304. bool hasFiles = false;
  305. bool hasErrors = false;
  306. std::string path, basePath;
  307. protected:
  308. void StartElement(const std::string& name, const char** /*atts*/) override
  309. {
  310. this->file = name == "file";
  311. if (this->file) {
  312. this->hasFiles = true;
  313. }
  314. }
  315. void CharacterDataHandler(const char* data, int length) override
  316. {
  317. if (this->file) {
  318. std::string content(data, data + length);
  319. content = cmTrimWhitespace(content);
  320. std::string source = this->basePath + "/" + content;
  321. std::string destination = this->path + "/" + content;
  322. if (!cmSystemTools::CopyFileIfDifferent(source, destination)) {
  323. this->hasErrors = true;
  324. }
  325. }
  326. }
  327. void EndElement(const std::string& /*name*/) override {}
  328. };
  329. void cmCPackIFWInstaller::GenerateInstallerFile()
  330. {
  331. // Lazy directory initialization
  332. if (this->Directory.empty() && this->Generator) {
  333. this->Directory = this->Generator->toplevel;
  334. }
  335. // Output stream
  336. cmGeneratedFileStream fout(this->Directory + "/config/config.xml");
  337. cmXMLWriter xout(fout);
  338. xout.StartDocument();
  339. this->WriteGeneratedByToStrim(xout);
  340. xout.StartElement("Installer");
  341. xout.Element("Name", this->Name);
  342. xout.Element("Version", this->Version);
  343. xout.Element("Title", this->Title);
  344. if (!this->Publisher.empty()) {
  345. xout.Element("Publisher", this->Publisher);
  346. }
  347. if (!this->ProductUrl.empty()) {
  348. xout.Element("ProductUrl", this->ProductUrl);
  349. }
  350. // Logo
  351. if (!this->Logo.empty()) {
  352. std::string srcName = cmSystemTools::GetFilenameName(this->Logo);
  353. std::string suffix = cmSystemTools::GetFilenameLastExtension(srcName);
  354. std::string name = "cm_logo." + suffix;
  355. std::string path = this->Directory + "/config/" + name;
  356. cmsys::SystemTools::CopyFileIfDifferent(this->Logo, path);
  357. xout.Element("Logo", name);
  358. }
  359. // Banner
  360. if (!this->Banner.empty()) {
  361. std::string name = cmSystemTools::GetFilenameName(this->Banner);
  362. std::string path = this->Directory + "/config/" + name;
  363. cmsys::SystemTools::CopyFileIfDifferent(this->Banner, path);
  364. xout.Element("Banner", name);
  365. }
  366. // Watermark
  367. if (!this->Watermark.empty()) {
  368. std::string name = cmSystemTools::GetFilenameName(this->Watermark);
  369. std::string path = this->Directory + "/config/" + name;
  370. cmsys::SystemTools::CopyFileIfDifferent(this->Watermark, path);
  371. xout.Element("Watermark", name);
  372. }
  373. // Background
  374. if (!this->Background.empty()) {
  375. std::string name = cmSystemTools::GetFilenameName(this->Background);
  376. std::string path = this->Directory + "/config/" + name;
  377. cmsys::SystemTools::CopyFileIfDifferent(this->Background, path);
  378. xout.Element("Background", name);
  379. }
  380. // Attributes introduced in QtIFW 1.4.0
  381. if (!this->IsVersionLess("1.4")) {
  382. // ApplicationIcon
  383. if (!this->InstallerApplicationIcon.empty()) {
  384. std::string srcName =
  385. cmSystemTools::GetFilenameName(this->InstallerApplicationIcon);
  386. std::string suffix = cmSystemTools::GetFilenameLastExtension(srcName);
  387. std::string name = "cm_appicon." + suffix;
  388. std::string path = this->Directory + "/config/" + name;
  389. cmsys::SystemTools::CopyFileIfDifferent(this->InstallerApplicationIcon,
  390. path);
  391. // The actual file is looked up by attaching a '.icns' (macOS),
  392. // '.ico' (Windows). No functionality on Unix.
  393. name = cmSystemTools::GetFilenameWithoutExtension(name);
  394. xout.Element("InstallerApplicationIcon", name);
  395. }
  396. // WindowIcon
  397. if (!this->InstallerWindowIcon.empty()) {
  398. std::string srcName =
  399. cmSystemTools::GetFilenameName(this->InstallerWindowIcon);
  400. std::string suffix = cmSystemTools::GetFilenameLastExtension(srcName);
  401. std::string name = "cm_winicon." + suffix;
  402. std::string path = this->Directory + "/config/" + name;
  403. cmsys::SystemTools::CopyFileIfDifferent(this->InstallerWindowIcon, path);
  404. xout.Element("InstallerWindowIcon", name);
  405. }
  406. }
  407. // Attributes introduced in QtIFW 2.0.0
  408. if (!this->IsVersionLess("2.0")) {
  409. // WizardDefaultWidth
  410. if (!this->WizardDefaultWidth.empty()) {
  411. xout.Element("WizardDefaultWidth", this->WizardDefaultWidth);
  412. }
  413. // WizardDefaultHeight
  414. if (!this->WizardDefaultHeight.empty()) {
  415. xout.Element("WizardDefaultHeight", this->WizardDefaultHeight);
  416. }
  417. // Start menu directory
  418. if (!this->StartMenuDir.empty()) {
  419. xout.Element("StartMenuDir", this->StartMenuDir);
  420. }
  421. // Maintenance tool
  422. if (!this->MaintenanceToolName.empty()) {
  423. xout.Element("MaintenanceToolName", this->MaintenanceToolName);
  424. }
  425. // Maintenance tool ini file
  426. if (!this->MaintenanceToolIniFile.empty()) {
  427. xout.Element("MaintenanceToolIniFile", this->MaintenanceToolIniFile);
  428. }
  429. if (!this->AllowNonAsciiCharacters.empty()) {
  430. xout.Element("AllowNonAsciiCharacters", this->AllowNonAsciiCharacters);
  431. }
  432. if (!this->AllowSpaceInPath.empty()) {
  433. xout.Element("AllowSpaceInPath", this->AllowSpaceInPath);
  434. }
  435. // Control script (copy to config dir)
  436. if (!this->ControlScript.empty()) {
  437. std::string name = cmSystemTools::GetFilenameName(this->ControlScript);
  438. std::string path = this->Directory + "/config/" + name;
  439. cmsys::SystemTools::CopyFileIfDifferent(this->ControlScript, path);
  440. xout.Element("ControlScript", name);
  441. }
  442. } else {
  443. // CPack IFW default policy
  444. xout.Comment("CPack IFW default policy for QtIFW less 2.0");
  445. xout.Element("AllowNonAsciiCharacters", "true");
  446. xout.Element("AllowSpaceInPath", "true");
  447. }
  448. // Target dir
  449. if (!this->TargetDir.empty()) {
  450. xout.Element("TargetDir", this->TargetDir);
  451. }
  452. // Admin target dir
  453. if (!this->AdminTargetDir.empty()) {
  454. xout.Element("AdminTargetDir", this->AdminTargetDir);
  455. }
  456. // Remote repositories
  457. if (!this->RemoteRepositories.empty()) {
  458. xout.StartElement("RemoteRepositories");
  459. for (cmCPackIFWRepository* r : this->RemoteRepositories) {
  460. r->WriteRepositoryConfig(xout);
  461. }
  462. xout.EndElement();
  463. }
  464. // Attributes introduced in QtIFW 3.0.0
  465. if (!this->IsVersionLess("3.0")) {
  466. // WizardStyle
  467. if (!this->WizardStyle.empty()) {
  468. xout.Element("WizardStyle", this->WizardStyle);
  469. }
  470. // Stylesheet (copy to config dir)
  471. if (!this->StyleSheet.empty()) {
  472. std::string name = cmSystemTools::GetFilenameName(this->StyleSheet);
  473. std::string path = this->Directory + "/config/" + name;
  474. cmsys::SystemTools::CopyFileIfDifferent(this->StyleSheet, path);
  475. xout.Element("StyleSheet", name);
  476. }
  477. // TitleColor
  478. if (!this->TitleColor.empty()) {
  479. xout.Element("TitleColor", this->TitleColor);
  480. }
  481. }
  482. // Attributes introduced in QtIFW 4.0.0
  483. if (!this->IsVersionLess("4.0")) {
  484. // WizardShowPageList
  485. if (!this->WizardShowPageList.empty()) {
  486. xout.Element("WizardShowPageList", this->WizardShowPageList);
  487. }
  488. // DisableCommandLineInterface
  489. if (!this->DisableCommandLineInterface.empty()) {
  490. xout.Element("DisableCommandLineInterface",
  491. this->DisableCommandLineInterface);
  492. }
  493. // RunProgram
  494. if (!this->RunProgram.empty()) {
  495. xout.Element("RunProgram", this->RunProgram);
  496. }
  497. // RunProgramArguments
  498. if (!this->RunProgramArguments.empty()) {
  499. xout.StartElement("RunProgramArguments");
  500. for (const auto& arg : this->RunProgramArguments) {
  501. xout.Element("Argument", arg);
  502. }
  503. xout.EndElement();
  504. }
  505. // RunProgramDescription
  506. if (!this->RunProgramDescription.empty()) {
  507. xout.Element("RunProgramDescription", this->RunProgramDescription);
  508. }
  509. }
  510. if (!this->RemoveTargetDir.empty()) {
  511. xout.Element("RemoveTargetDir", this->RemoveTargetDir);
  512. }
  513. // Product images (copy to config dir)
  514. if (!this->IsVersionLess("4.0") && !this->ProductImages.empty()) {
  515. xout.StartElement("ProductImages");
  516. for (auto const& srcImg : this->ProductImages) {
  517. std::string name = cmSystemTools::GetFilenameName(srcImg);
  518. std::string dstImg = this->Directory + "/config/" + name;
  519. cmsys::SystemTools::CopyFileIfDifferent(srcImg, dstImg);
  520. xout.Element("Image", name);
  521. }
  522. xout.EndElement();
  523. }
  524. // Resources (copy to resources dir)
  525. if (!this->Resources.empty()) {
  526. std::vector<std::string> resources;
  527. cmCPackIFWResourcesParser parser(this);
  528. for (size_t i = 0; i < this->Resources.size(); i++) {
  529. if (parser.ParseResource(i)) {
  530. std::string name = cmSystemTools::GetFilenameName(this->Resources[i]);
  531. std::string path = this->Directory + "/resources/" + name;
  532. cmsys::SystemTools::CopyFileIfDifferent(this->Resources[i], path);
  533. resources.push_back(std::move(name));
  534. } else {
  535. cmCPackIFWLogger(WARNING,
  536. "Can't copy resources from \""
  537. << this->Resources[i]
  538. << "\". Resource will be skipped." << std::endl);
  539. }
  540. }
  541. this->Resources = resources;
  542. }
  543. xout.EndElement();
  544. xout.EndDocument();
  545. }
  546. void cmCPackIFWInstaller::GeneratePackageFiles()
  547. {
  548. if (this->Packages.empty() || this->Generator->IsOnePackage()) {
  549. // Generate default package
  550. cmCPackIFWPackage package;
  551. package.Generator = this->Generator;
  552. package.Installer = this;
  553. // Check package group
  554. if (cmValue option = this->GetOption("CPACK_IFW_PACKAGE_GROUP")) {
  555. package.ConfigureFromGroup(option);
  556. std::string forcedOption = "CPACK_IFW_COMPONENT_GROUP_" +
  557. cmsys::SystemTools::UpperCase(option) + "_FORCED_INSTALLATION";
  558. if (!this->GetOption(forcedOption)) {
  559. package.ForcedInstallation = "true";
  560. }
  561. } else {
  562. package.ConfigureFromOptions();
  563. }
  564. package.GeneratePackageFile();
  565. return;
  566. }
  567. // Generate packages meta information
  568. for (auto& p : this->Packages) {
  569. cmCPackIFWPackage* package = p.second;
  570. package->GeneratePackageFile();
  571. }
  572. }