cmCPackPackageMakerGenerator.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 "cmCPackPackageMakerGenerator.h"
  4. #include <cassert>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <map>
  8. #include <sstream>
  9. #include <string>
  10. #include "cmsys/FStream.hxx"
  11. #include "cmsys/RegularExpression.hxx"
  12. #include "cmCPackComponentGroup.h"
  13. #include "cmCPackLog.h"
  14. #include "cmDuration.h"
  15. #include "cmGeneratedFileStream.h"
  16. #include "cmStringAlgorithms.h"
  17. #include "cmSystemTools.h"
  18. #include "cmValue.h"
  19. #include "cmXMLWriter.h"
  20. static inline unsigned int getVersion(unsigned int major, unsigned int minor)
  21. {
  22. assert(major < 256 && minor < 256);
  23. return ((major & 0xFF) << 16 | minor);
  24. }
  25. cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
  26. {
  27. this->PackageMakerVersion = 0.0;
  28. this->PackageCompatibilityVersion = getVersion(10, 4);
  29. }
  30. cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator() = default;
  31. bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
  32. {
  33. return this->PackageCompatibilityVersion >= getVersion(10, 4);
  34. }
  35. int cmCPackPackageMakerGenerator::PackageFiles()
  36. {
  37. // TODO: Use toplevel
  38. // It is used! Is this an obsolete comment?
  39. std::string resDir; // Where this package's resources will go.
  40. std::string packageDirFileName =
  41. this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  42. if (this->Components.empty()) {
  43. packageDirFileName += ".pkg";
  44. resDir =
  45. cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/Resources");
  46. } else {
  47. packageDirFileName += ".mpkg";
  48. if (!cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str())) {
  49. cmCPackLogger(cmCPackLog::LOG_ERROR,
  50. "unable to create package directory " << packageDirFileName
  51. << std::endl);
  52. return 0;
  53. }
  54. resDir = cmStrCat(packageDirFileName, "/Contents");
  55. if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) {
  56. cmCPackLogger(cmCPackLog::LOG_ERROR,
  57. "unable to create package subdirectory " << resDir
  58. << std::endl);
  59. return 0;
  60. }
  61. resDir += "/Resources";
  62. if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) {
  63. cmCPackLogger(cmCPackLog::LOG_ERROR,
  64. "unable to create package subdirectory " << resDir
  65. << std::endl);
  66. return 0;
  67. }
  68. resDir += "/en.lproj";
  69. }
  70. cmValue preflight = this->GetOption("CPACK_PREFLIGHT_SCRIPT");
  71. cmValue postflight = this->GetOption("CPACK_POSTFLIGHT_SCRIPT");
  72. cmValue postupgrade = this->GetOption("CPACK_POSTUPGRADE_SCRIPT");
  73. if (this->Components.empty()) {
  74. // Create directory structure
  75. std::string preflightDirName = resDir + "/PreFlight";
  76. std::string postflightDirName = resDir + "/PostFlight";
  77. // if preflight or postflight scripts not there create directories
  78. // of the same name, I think this makes it work
  79. if (!preflight) {
  80. if (!cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())) {
  81. cmCPackLogger(cmCPackLog::LOG_ERROR,
  82. "Problem creating installer directory: "
  83. << preflightDirName << std::endl);
  84. return 0;
  85. }
  86. }
  87. if (!postflight) {
  88. if (!cmsys::SystemTools::MakeDirectory(postflightDirName.c_str())) {
  89. cmCPackLogger(cmCPackLog::LOG_ERROR,
  90. "Problem creating installer directory: "
  91. << postflightDirName << std::endl);
  92. return 0;
  93. }
  94. }
  95. // if preflight, postflight, or postupgrade are set
  96. // then copy them into the resource directory and make
  97. // them executable
  98. if (preflight) {
  99. this->CopyInstallScript(resDir, preflight, "preflight");
  100. }
  101. if (postflight) {
  102. this->CopyInstallScript(resDir, postflight, "postflight");
  103. }
  104. if (postupgrade) {
  105. this->CopyInstallScript(resDir, postupgrade, "postupgrade");
  106. }
  107. } else if (postflight) {
  108. // create a postflight component to house the script
  109. this->PostFlightComponent.Name = "PostFlight";
  110. this->PostFlightComponent.DisplayName = "PostFlight";
  111. this->PostFlightComponent.Description = "PostFlight";
  112. this->PostFlightComponent.IsHidden = true;
  113. // empty directory for pkg contents
  114. std::string packageDir = toplevel + "/" + PostFlightComponent.Name;
  115. if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str())) {
  116. cmCPackLogger(cmCPackLog::LOG_ERROR,
  117. "Problem creating component packages directory: "
  118. << packageDir << std::endl);
  119. return 0;
  120. }
  121. // create package
  122. std::string packageFileDir = packageDirFileName + "/Contents/Packages/";
  123. if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str())) {
  124. cmCPackLogger(
  125. cmCPackLog::LOG_ERROR,
  126. "Problem creating component PostFlight Packages directory: "
  127. << packageFileDir << std::endl);
  128. return 0;
  129. }
  130. std::string packageFile =
  131. packageFileDir + this->GetPackageName(PostFlightComponent);
  132. if (!this->GenerateComponentPackage(
  133. packageFile.c_str(), packageDir.c_str(), PostFlightComponent)) {
  134. return 0;
  135. }
  136. // copy postflight script into resource directory of .pkg
  137. std::string resourceDir = packageFile + "/Contents/Resources";
  138. this->CopyInstallScript(resourceDir, postflight, "postflight");
  139. }
  140. if (!this->Components.empty()) {
  141. // Create the directory where component packages will be built.
  142. std::string basePackageDir =
  143. cmStrCat(packageDirFileName, "/Contents/Packages");
  144. if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) {
  145. cmCPackLogger(cmCPackLog::LOG_ERROR,
  146. "Problem creating component packages directory: "
  147. << basePackageDir << std::endl);
  148. return 0;
  149. }
  150. // Create the directory where downloaded component packages will
  151. // be placed.
  152. cmValue userUploadDirectory = this->GetOption("CPACK_UPLOAD_DIRECTORY");
  153. std::string uploadDirectory;
  154. if (userUploadDirectory && !userUploadDirectory->empty()) {
  155. uploadDirectory = userUploadDirectory;
  156. } else {
  157. uploadDirectory =
  158. cmStrCat(this->GetOption("CPACK_PACKAGE_DIRECTORY"), "/CPackUploads");
  159. }
  160. // Create packages for each component
  161. bool warnedAboutDownloadCompatibility = false;
  162. std::map<std::string, cmCPackComponent>::iterator compIt;
  163. for (compIt = this->Components.begin(); compIt != this->Components.end();
  164. ++compIt) {
  165. std::string packageFile;
  166. if (compIt->second.IsDownloaded) {
  167. if (this->PackageCompatibilityVersion >= getVersion(10, 5) &&
  168. this->PackageMakerVersion >= 3.0) {
  169. // Build this package within the upload directory.
  170. packageFile = uploadDirectory;
  171. if (!cmSystemTools::FileExists(uploadDirectory.c_str())) {
  172. if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) {
  173. cmCPackLogger(cmCPackLog::LOG_ERROR,
  174. "Unable to create package upload directory "
  175. << uploadDirectory << std::endl);
  176. return 0;
  177. }
  178. }
  179. } else if (!warnedAboutDownloadCompatibility) {
  180. if (this->PackageCompatibilityVersion < getVersion(10, 5)) {
  181. cmCPackLogger(
  182. cmCPackLog::LOG_WARNING,
  183. "CPack warning: please set CPACK_OSX_PACKAGE_VERSION to 10.5 "
  184. "or greater enable downloaded packages. CPack will build a "
  185. "non-downloaded package."
  186. << std::endl);
  187. }
  188. if (this->PackageMakerVersion < 3) {
  189. cmCPackLogger(cmCPackLog::LOG_WARNING,
  190. "CPack warning: unable to build downloaded "
  191. "packages with PackageMaker versions prior "
  192. "to 3.0. CPack will build a non-downloaded package."
  193. << std::endl);
  194. }
  195. warnedAboutDownloadCompatibility = true;
  196. }
  197. }
  198. if (packageFile.empty()) {
  199. // Build this package within the overall distribution
  200. // metapackage.
  201. packageFile = basePackageDir;
  202. // We're not downloading this component, even if the user
  203. // requested it.
  204. compIt->second.IsDownloaded = false;
  205. }
  206. packageFile += '/';
  207. packageFile += GetPackageName(compIt->second);
  208. std::string packageDir = cmStrCat(toplevel, '/', compIt->first);
  209. if (!this->GenerateComponentPackage(
  210. packageFile.c_str(), packageDir.c_str(), compIt->second)) {
  211. return 0;
  212. }
  213. }
  214. }
  215. this->SetOption("CPACK_MODULE_VERSION_SUFFIX", "");
  216. // Copy or create all of the resource files we need.
  217. if (!this->CopyCreateResourceFile("License", resDir) ||
  218. !this->CopyCreateResourceFile("ReadMe", resDir) ||
  219. !this->CopyCreateResourceFile("Welcome", resDir) ||
  220. !this->CopyResourcePlistFile("Info.plist") ||
  221. !this->CopyResourcePlistFile("Description.plist")) {
  222. cmCPackLogger(cmCPackLog::LOG_ERROR,
  223. "Problem copying the resource files" << std::endl);
  224. return 0;
  225. }
  226. if (this->Components.empty()) {
  227. // Use PackageMaker to build the package.
  228. std::ostringstream pkgCmd;
  229. pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  230. << "\" -build -p \"" << packageDirFileName << "\"";
  231. if (this->Components.empty()) {
  232. pkgCmd << " -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  233. } else {
  234. pkgCmd << " -mi \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
  235. << "/packages/";
  236. }
  237. pkgCmd << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
  238. << "/Resources\" -i \""
  239. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
  240. << "/Info.plist\" -d \""
  241. << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
  242. << "/Description.plist\"";
  243. if (this->PackageMakerVersion > 2.0) {
  244. pkgCmd << " -v";
  245. }
  246. if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) {
  247. return 0;
  248. }
  249. } else {
  250. // We have built the package in place. Generate the
  251. // distribution.dist file to describe it for the installer.
  252. WriteDistributionFile(packageDirFileName.c_str(), "PACKAGEMAKER");
  253. }
  254. std::string tmpFile = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
  255. "/hdiutilOutput.log");
  256. std::ostringstream dmgCmd;
  257. dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
  258. << "\" create -ov -fs HFS+ -format UDZO -srcfolder \""
  259. << packageDirFileName << "\" \"" << packageFileNames[0] << "\"";
  260. std::string output;
  261. int retVal = 1;
  262. int numTries = 10;
  263. bool res = false;
  264. while (numTries > 0) {
  265. res = cmSystemTools::RunSingleCommand(
  266. dmgCmd.str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose,
  267. cmDuration::zero());
  268. if (res && !retVal) {
  269. numTries = -1;
  270. break;
  271. }
  272. cmSystemTools::Delay(500);
  273. numTries--;
  274. }
  275. if (!res || retVal) {
  276. cmGeneratedFileStream ofs(tmpFile);
  277. ofs << "# Run command: " << dmgCmd.str() << std::endl
  278. << "# Output:" << std::endl
  279. << output << std::endl;
  280. cmCPackLogger(cmCPackLog::LOG_ERROR,
  281. "Problem running hdiutil command: "
  282. << dmgCmd.str() << std::endl
  283. << "Please check " << tmpFile << " for errors"
  284. << std::endl);
  285. return 0;
  286. }
  287. return 1;
  288. }
  289. int cmCPackPackageMakerGenerator::InitializeInternal()
  290. {
  291. cmCPackLogger(cmCPackLog::LOG_WARNING,
  292. "The PackageMaker generator is deprecated "
  293. "and will be removed in a future version.\n");
  294. this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
  295. // Starting with Xcode 4.3, PackageMaker is a separate app, and you
  296. // can put it anywhere you want. So... use a variable for its location.
  297. // People who put it in unexpected places can use the variable to tell
  298. // us where it is.
  299. //
  300. // Use the following locations, in "most recent installation" order,
  301. // to search for the PackageMaker app. Assume people who copy it into
  302. // the new Xcode 4.3 app in "/Applications" will copy it into the nested
  303. // Applications folder inside the Xcode bundle itself. Or directly in
  304. // the "/Applications" directory.
  305. //
  306. // If found, save result in the CPACK_INSTALLER_PROGRAM variable.
  307. std::vector<std::string> paths;
  308. paths.emplace_back("/Applications/Xcode.app/Contents/Applications"
  309. "/PackageMaker.app/Contents/MacOS");
  310. paths.emplace_back("/Applications/Utilities"
  311. "/PackageMaker.app/Contents/MacOS");
  312. paths.emplace_back("/Applications"
  313. "/PackageMaker.app/Contents/MacOS");
  314. paths.emplace_back("/Developer/Applications/Utilities"
  315. "/PackageMaker.app/Contents/MacOS");
  316. paths.emplace_back("/Developer/Applications"
  317. "/PackageMaker.app/Contents/MacOS");
  318. std::string pkgPath;
  319. cmValue inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM");
  320. if (inst_program && !inst_program->empty()) {
  321. pkgPath = inst_program;
  322. } else {
  323. pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false);
  324. if (pkgPath.empty()) {
  325. cmCPackLogger(cmCPackLog::LOG_ERROR,
  326. "Cannot find PackageMaker compiler" << std::endl);
  327. return 0;
  328. }
  329. this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath);
  330. }
  331. // Get path to the real PackageMaker, not a symlink:
  332. pkgPath = cmSystemTools::GetRealPath(pkgPath);
  333. // Up from there to find the version.plist file in the "Contents" dir:
  334. std::string contents_dir;
  335. contents_dir = cmSystemTools::GetFilenamePath(pkgPath);
  336. contents_dir = cmSystemTools::GetFilenamePath(contents_dir);
  337. std::string versionFile = contents_dir + "/version.plist";
  338. if (!cmSystemTools::FileExists(versionFile.c_str())) {
  339. cmCPackLogger(cmCPackLog::LOG_ERROR,
  340. "Cannot find PackageMaker compiler version file: "
  341. << versionFile << std::endl);
  342. return 0;
  343. }
  344. cmsys::ifstream ifs(versionFile.c_str());
  345. if (!ifs) {
  346. cmCPackLogger(cmCPackLog::LOG_ERROR,
  347. "Cannot open PackageMaker compiler version file"
  348. << std::endl);
  349. return 0;
  350. }
  351. // Check the PackageMaker version
  352. cmsys::RegularExpression rexKey("<key>CFBundleShortVersionString</key>");
  353. cmsys::RegularExpression rexVersion("<string>([0-9]+.[0-9.]+)</string>");
  354. std::string line;
  355. bool foundKey = false;
  356. while (cmSystemTools::GetLineFromStream(ifs, line)) {
  357. if (rexKey.find(line)) {
  358. foundKey = true;
  359. break;
  360. }
  361. }
  362. if (!foundKey) {
  363. cmCPackLogger(
  364. cmCPackLog::LOG_ERROR,
  365. "Cannot find CFBundleShortVersionString in the PackageMaker compiler "
  366. "version file"
  367. << std::endl);
  368. return 0;
  369. }
  370. if (!cmSystemTools::GetLineFromStream(ifs, line) || !rexVersion.find(line)) {
  371. cmCPackLogger(cmCPackLog::LOG_ERROR,
  372. "Problem reading the PackageMaker compiler version file: "
  373. << versionFile << std::endl);
  374. return 0;
  375. }
  376. this->PackageMakerVersion = atof(rexVersion.match(1).c_str());
  377. if (this->PackageMakerVersion < 1.0) {
  378. cmCPackLogger(cmCPackLog::LOG_ERROR,
  379. "Require PackageMaker 1.0 or higher" << std::endl);
  380. return 0;
  381. }
  382. cmCPackLogger(cmCPackLog::LOG_DEBUG,
  383. "PackageMaker version is: " << this->PackageMakerVersion
  384. << std::endl);
  385. // Determine the package compatibility version. If it wasn't
  386. // specified by the user, we define it based on which features the
  387. // user requested.
  388. cmValue packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION");
  389. if (packageCompat && !packageCompat->empty()) {
  390. unsigned int majorVersion = 10;
  391. unsigned int minorVersion = 5;
  392. int res =
  393. sscanf(packageCompat->c_str(), "%u.%u", &majorVersion, &minorVersion);
  394. if (res == 2) {
  395. this->PackageCompatibilityVersion =
  396. getVersion(majorVersion, minorVersion);
  397. }
  398. } else if (this->GetOption("CPACK_DOWNLOAD_SITE")) {
  399. this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5");
  400. this->PackageCompatibilityVersion = getVersion(10, 5);
  401. } else if (this->GetOption("CPACK_COMPONENTS_ALL")) {
  402. this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4");
  403. this->PackageCompatibilityVersion = getVersion(10, 4);
  404. } else {
  405. this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3");
  406. this->PackageCompatibilityVersion = getVersion(10, 3);
  407. }
  408. std::vector<std::string> no_paths;
  409. pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false);
  410. if (pkgPath.empty()) {
  411. cmCPackLogger(cmCPackLog::LOG_ERROR,
  412. "Cannot find hdiutil compiler" << std::endl);
  413. return 0;
  414. }
  415. this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath);
  416. return this->Superclass::InitializeInternal();
  417. }
  418. bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command,
  419. const char* packageFile)
  420. {
  421. std::string tmpFile = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
  422. "/PackageMakerOutput.log");
  423. cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
  424. std::string output;
  425. int retVal = 1;
  426. bool res = cmSystemTools::RunSingleCommand(
  427. command, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
  428. cmDuration::zero());
  429. cmCPackLogger(cmCPackLog::LOG_VERBOSE,
  430. "Done running package maker" << std::endl);
  431. if (!res || retVal) {
  432. cmGeneratedFileStream ofs(tmpFile);
  433. ofs << "# Run command: " << command << std::endl
  434. << "# Output:" << std::endl
  435. << output << std::endl;
  436. cmCPackLogger(cmCPackLog::LOG_ERROR,
  437. "Problem running PackageMaker command: "
  438. << command << std::endl
  439. << "Please check " << tmpFile << " for errors"
  440. << std::endl);
  441. return false;
  442. }
  443. // sometimes the command finishes but the directory is not yet
  444. // created, so try 10 times to see if it shows up
  445. int tries = 10;
  446. while (tries > 0 && !cmSystemTools::FileExists(packageFile)) {
  447. cmSystemTools::Delay(500);
  448. tries--;
  449. }
  450. if (!cmSystemTools::FileExists(packageFile)) {
  451. cmCPackLogger(cmCPackLog::LOG_ERROR,
  452. "Problem running PackageMaker command: "
  453. << command << std::endl
  454. << "Package not created: " << packageFile << std::endl);
  455. return false;
  456. }
  457. return true;
  458. }
  459. bool cmCPackPackageMakerGenerator::GenerateComponentPackage(
  460. const char* packageFile, const char* packageDir,
  461. const cmCPackComponent& component)
  462. {
  463. cmCPackLogger(cmCPackLog::LOG_OUTPUT,
  464. "- Building component package: " << packageFile
  465. << std::endl);
  466. // The command that will be used to run PackageMaker
  467. std::ostringstream pkgCmd;
  468. if (this->PackageCompatibilityVersion < getVersion(10, 5) ||
  469. this->PackageMakerVersion < 3.0) {
  470. // Create Description.plist and Info.plist files for normal Mac OS
  471. // X packages, which work on Mac OS X 10.3 and newer.
  472. std::string descriptionFile =
  473. cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/',
  474. component.Name, "-Description.plist");
  475. cmsys::ofstream out(descriptionFile.c_str());
  476. cmXMLWriter xout(out);
  477. xout.StartDocument();
  478. xout.Doctype("plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
  479. "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
  480. xout.StartElement("plist");
  481. xout.Attribute("version", "1.4");
  482. xout.StartElement("dict");
  483. xout.Element("key", "IFPkgDescriptionTitle");
  484. xout.Element("string", component.DisplayName);
  485. xout.Element("key", "IFPkgDescriptionVersion");
  486. xout.Element("string", this->GetOption("CPACK_PACKAGE_VERSION"));
  487. xout.Element("key", "IFPkgDescriptionDescription");
  488. xout.Element("string", component.Description);
  489. xout.EndElement(); // dict
  490. xout.EndElement(); // plist
  491. xout.EndDocument();
  492. out.close();
  493. // Create the Info.plist file for this component
  494. std::string moduleVersionSuffix = cmStrCat('.', component.Name);
  495. this->SetOption("CPACK_MODULE_VERSION_SUFFIX", moduleVersionSuffix);
  496. std::string infoFileName = cmStrCat(component.Name, "-Info.plist");
  497. if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str())) {
  498. return false;
  499. }
  500. pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  501. << "\" -build -p \"" << packageFile << "\""
  502. << " -f \"" << packageDir << "\""
  503. << " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/"
  504. << infoFileName << "\""
  505. << " -d \"" << descriptionFile << "\"";
  506. } else {
  507. // Create a "flat" package on Mac OS X 10.5 and newer. Flat
  508. // packages are stored in a single file, rather than a directory
  509. // like normal packages, and can be downloaded by the installer
  510. // on-the-fly in Mac OS X 10.5 or newer. Thus, we need to create
  511. // flat packages when the packages will be downloaded on the fly.
  512. std::string pkgId =
  513. cmStrCat("com.", this->GetOption("CPACK_PACKAGE_VENDOR"), '.',
  514. this->GetOption("CPACK_PACKAGE_NAME"), '.', component.Name);
  515. pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
  516. << "\" --root \"" << packageDir << "\""
  517. << " --id " << pkgId << " --target "
  518. << this->GetOption("CPACK_OSX_PACKAGE_VERSION") << " --out \""
  519. << packageFile << "\"";
  520. }
  521. // Run PackageMaker
  522. return RunPackageMaker(pkgCmd.str().c_str(), packageFile);
  523. }