cmCPackPackageMakerGenerator.cxx 22 KB

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