cmCPackPackageMakerGenerator.cxx 21 KB

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