cmCPackPackageMakerGenerator.cxx 21.4 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4
#include "cmCPackPackageMakerGenerator.h"

5 6 7
#include <cassert>
#include <cstdio>
#include <cstdlib>
8 9 10 11
#include <map>
#include <sstream>
#include <string>

12 13 14
#include "cmsys/FStream.hxx"
#include "cmsys/RegularExpression.hxx"

15
#include "cmCPackComponentGroup.h"
16
#include "cmCPackLog.h"
17
#include "cmDuration.h"
18
#include "cmGeneratedFileStream.h"
19
#include "cmStringAlgorithms.h"
20
#include "cmSystemTools.h"
21
#include "cmXMLWriter.h"
22

23
static inline unsigned int getVersion(unsigned int major, unsigned int minor)
24 25 26 27 28
{
  assert(major < 256 && minor < 256);
  return ((major & 0xFF) << 16 | minor);
}

29 30
cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
{
31
  this->PackageMakerVersion = 0.0;
32
  this->PackageCompatibilityVersion = getVersion(10, 4);
33 34
}

wahikihiki's avatar
wahikihiki committed
35
cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator() = default;
36

37 38
bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
{
39
  return this->PackageCompatibilityVersion >= getVersion(10, 4);
40 41
}

42
int cmCPackPackageMakerGenerator::PackageFiles()
43
{
44 45
  // TODO: Use toplevel
  //       It is used! Is this an obsolete comment?
46 47

  std::string resDir; // Where this package's resources will go.
48 49 50
  std::string packageDirFileName =
    this->GetOption("CPACK_TEMPORARY_DIRECTORY");
  if (this->Components.empty()) {
51
    packageDirFileName += ".pkg";
52 53
    resDir =
      cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), "/Resources");
54
  } else {
55
    packageDirFileName += ".mpkg";
56
    if (!cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str())) {
57
      cmCPackLogger(cmCPackLog::LOG_ERROR,
58 59 60 61
                    "unable to create package directory " << packageDirFileName
                                                          << std::endl);
      return 0;
    }
62

63
    resDir = cmStrCat(packageDirFileName, "/Contents");
64
    if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) {
65
      cmCPackLogger(cmCPackLog::LOG_ERROR,
66
                    "unable to create package subdirectory " << resDir
67 68 69
                                                             << std::endl);
      return 0;
    }
70 71

    resDir += "/Resources";
72
    if (!cmsys::SystemTools::MakeDirectory(resDir.c_str())) {
73
      cmCPackLogger(cmCPackLog::LOG_ERROR,
74
                    "unable to create package subdirectory " << resDir
75 76 77
                                                             << std::endl);
      return 0;
    }
78 79

    resDir += "/en.lproj";
80
  }
81

82 83 84
  const char* preflight = this->GetOption("CPACK_PREFLIGHT_SCRIPT");
  const char* postflight = this->GetOption("CPACK_POSTFLIGHT_SCRIPT");
  const char* postupgrade = this->GetOption("CPACK_POSTUPGRADE_SCRIPT");
85

86
  if (this->Components.empty()) {
87 88 89 90 91
    // Create directory structure
    std::string preflightDirName = resDir + "/PreFlight";
    std::string postflightDirName = resDir + "/PostFlight";
    // if preflight or postflight scripts not there create directories
    // of the same name, I think this makes it work
92 93
    if (!preflight) {
      if (!cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())) {
94 95
        cmCPackLogger(cmCPackLog::LOG_ERROR,
                      "Problem creating installer directory: "
96
                        << preflightDirName << std::endl);
97 98
        return 0;
      }
99 100 101
    }
    if (!postflight) {
      if (!cmsys::SystemTools::MakeDirectory(postflightDirName.c_str())) {
102 103
        cmCPackLogger(cmCPackLog::LOG_ERROR,
                      "Problem creating installer directory: "
104
                        << postflightDirName << std::endl);
105 106
        return 0;
      }
107
    }
108 109 110
    // if preflight, postflight, or postupgrade are set
    // then copy them into the resource directory and make
    // them executable
111
    if (preflight) {
112
      this->CopyInstallScript(resDir, preflight, "preflight");
113
    }
114
    if (postflight) {
115
      this->CopyInstallScript(resDir, postflight, "postflight");
116 117
    }
    if (postupgrade) {
118
      this->CopyInstallScript(resDir, postupgrade, "postupgrade");
119 120
    }
  } else if (postflight) {
121 122 123 124 125 126 127 128
    // create a postflight component to house the script
    this->PostFlightComponent.Name = "PostFlight";
    this->PostFlightComponent.DisplayName = "PostFlight";
    this->PostFlightComponent.Description = "PostFlight";
    this->PostFlightComponent.IsHidden = true;

    // empty directory for pkg contents
    std::string packageDir = toplevel + "/" + PostFlightComponent.Name;
129
    if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str())) {
130
      cmCPackLogger(cmCPackLog::LOG_ERROR,
131
                    "Problem creating component packages directory: "
132
                      << packageDir << std::endl);
133
      return 0;
134
    }
135 136 137

    // create package
    std::string packageFileDir = packageDirFileName + "/Contents/Packages/";
138 139 140 141
    if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str())) {
      cmCPackLogger(
        cmCPackLog::LOG_ERROR,
        "Problem creating component PostFlight Packages directory: "
142
          << packageFileDir << std::endl);
143
      return 0;
144 145 146 147 148
    }
    std::string packageFile =
      packageFileDir + this->GetPackageName(PostFlightComponent);
    if (!this->GenerateComponentPackage(
          packageFile.c_str(), packageDir.c_str(), PostFlightComponent)) {
149
      return 0;
150
    }
151 152 153

    // copy postflight script into resource directory of .pkg
    std::string resourceDir = packageFile + "/Contents/Resources";
154
    this->CopyInstallScript(resourceDir, postflight, "postflight");
155
  }
156

157
  if (!this->Components.empty()) {
158
    // Create the directory where component packages will be built.
159 160
    std::string basePackageDir =
      cmStrCat(packageDirFileName, "/Contents/Packages");
161
    if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str())) {
162 163
      cmCPackLogger(cmCPackLog::LOG_ERROR,
                    "Problem creating component packages directory: "
164
                      << basePackageDir << std::endl);
165
      return 0;
166
    }
167

168 169
    // Create the directory where downloaded component packages will
    // be placed.
170 171
    const char* userUploadDirectory =
      this->GetOption("CPACK_UPLOAD_DIRECTORY");
172
    std::string uploadDirectory;
173
    if (userUploadDirectory && *userUploadDirectory) {
174
      uploadDirectory = userUploadDirectory;
175
    } else {
176 177
      uploadDirectory =
        cmStrCat(this->GetOption("CPACK_PACKAGE_DIRECTORY"), "/CPackUploads");
178
    }
179

180
    // Create packages for each component
181 182
    bool warnedAboutDownloadCompatibility = false;

183 184
    std::map<std::string, cmCPackComponent>::iterator compIt;
    for (compIt = this->Components.begin(); compIt != this->Components.end();
185
         ++compIt) {
186
      std::string packageFile;
187
      if (compIt->second.IsDownloaded) {
188
        if (this->PackageCompatibilityVersion >= getVersion(10, 5) &&
189
            this->PackageMakerVersion >= 3.0) {
190 191 192
          // Build this package within the upload directory.
          packageFile = uploadDirectory;

193 194
          if (!cmSystemTools::FileExists(uploadDirectory.c_str())) {
            if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) {
195
              cmCPackLogger(cmCPackLog::LOG_ERROR,
196
                            "Unable to create package upload directory "
197
                              << uploadDirectory << std::endl);
198 199 200
              return 0;
            }
          }
201 202
        } else if (!warnedAboutDownloadCompatibility) {
          if (this->PackageCompatibilityVersion < getVersion(10, 5)) {
203 204 205 206 207
            cmCPackLogger(
              cmCPackLog::LOG_WARNING,
              "CPack warning: please set CPACK_OSX_PACKAGE_VERSION to 10.5 "
              "or greater enable downloaded packages. CPack will build a "
              "non-downloaded package."
208 209
                << std::endl);
          }
210

211
          if (this->PackageMakerVersion < 3) {
212
            cmCPackLogger(cmCPackLog::LOG_WARNING,
213
                          "CPack warning: unable to build downloaded "
214 215
                          "packages with PackageMaker versions prior "
                          "to 3.0. CPack will build a non-downloaded package."
216 217
                            << std::endl);
          }
218 219 220

          warnedAboutDownloadCompatibility = true;
        }
221
      }
222

223
      if (packageFile.empty()) {
224 225 226 227 228 229 230
        // Build this package within the overall distribution
        // metapackage.
        packageFile = basePackageDir;

        // We're not downloading this component, even if the user
        // requested it.
        compIt->second.IsDownloaded = false;
231
      }
232

233 234 235
      packageFile += '/';
      packageFile += GetPackageName(compIt->second);

236
      std::string packageDir = cmStrCat(toplevel, '/', compIt->first);
237 238
      if (!this->GenerateComponentPackage(
            packageFile.c_str(), packageDir.c_str(), compIt->second)) {
239 240 241
        return 0;
      }
    }
242
  }
243 244 245
  this->SetOption("CPACK_MODULE_VERSION_SUFFIX", "");

  // Copy or create all of the resource files we need.
246 247 248
  if (!this->CopyCreateResourceFile("License", resDir) ||
      !this->CopyCreateResourceFile("ReadMe", resDir) ||
      !this->CopyCreateResourceFile("Welcome", resDir) ||
249 250
      !this->CopyResourcePlistFile("Info.plist") ||
      !this->CopyResourcePlistFile("Description.plist")) {
251 252
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "Problem copying the resource files" << std::endl);
253
    return 0;
254
  }
255

256
  if (this->Components.empty()) {
257
    // Use PackageMaker to build the package.
258
    std::ostringstream pkgCmd;
259 260
    pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
           << "\" -build -p \"" << packageDirFileName << "\"";
261
    if (this->Components.empty()) {
262
      pkgCmd << " -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY");
263
    } else {
264 265
      pkgCmd << " -mi \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
             << "/packages/";
266
    }
267 268
    pkgCmd << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
           << "/Resources\" -i \""
269
           << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
270
           << "/Info.plist\" -d \""
271
           << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
272
           << "/Description.plist\"";
273
    if (this->PackageMakerVersion > 2.0) {
274
      pkgCmd << " -v";
275
    }
276
    if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str())) {
277
      return 0;
278
    }
279
  } else {
280 281
    // We have built the package in place. Generate the
    // distribution.dist file to describe it for the installer.
282
    WriteDistributionFile(packageDirFileName.c_str(), "PACKAGEMAKER");
283
  }
284

285 286
  std::string tmpFile = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
                                 "/hdiutilOutput.log");
287
  std::ostringstream dmgCmd;
288
  dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
289 290
         << "\" create -ov -fs HFS+ -format UDZO -srcfolder \""
         << packageDirFileName << "\" \"" << packageFileNames[0] << "\"";
291 292
  std::string output;
  int retVal = 1;
293
  int numTries = 10;
294
  bool res = false;
295
  while (numTries > 0) {
296
    res = cmSystemTools::RunSingleCommand(
297 298
      dmgCmd.str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose,
      cmDuration::zero());
299
    if (res && !retVal) {
300
      numTries = -1;
301
      break;
302
    }
303
    cmSystemTools::Delay(500);
304
    numTries--;
305 306
  }
  if (!res || retVal) {
307
    cmGeneratedFileStream ofs(tmpFile);
308
    ofs << "# Run command: " << dmgCmd.str() << std::endl
309
        << "# Output:" << std::endl
310
        << output << std::endl;
311 312
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "Problem running hdiutil command: "
313 314
                    << dmgCmd.str() << std::endl
                    << "Please check " << tmpFile << " for errors"
315
                    << std::endl);
316
    return 0;
317
  }
318 319 320 321

  return 1;
}

322
int cmCPackPackageMakerGenerator::InitializeInternal()
323
{
324 325
  this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");

326 327 328 329 330 331 332 333 334 335 336 337 338 339
  // Starting with Xcode 4.3, PackageMaker is a separate app, and you
  // can put it anywhere you want. So... use a variable for its location.
  // People who put it in unexpected places can use the variable to tell
  // us where it is.
  //
  // Use the following locations, in "most recent installation" order,
  // to search for the PackageMaker app. Assume people who copy it into
  // the new Xcode 4.3 app in "/Applications" will copy it into the nested
  // Applications folder inside the Xcode bundle itself. Or directly in
  // the "/Applications" directory.
  //
  // If found, save result in the CPACK_INSTALLER_PROGRAM variable.

  std::vector<std::string> paths;
wahikihiki's avatar
wahikihiki committed
340 341 342 343 344 345 346 347 348 349
  paths.emplace_back("/Applications/Xcode.app/Contents/Applications"
                     "/PackageMaker.app/Contents/MacOS");
  paths.emplace_back("/Applications/Utilities"
                     "/PackageMaker.app/Contents/MacOS");
  paths.emplace_back("/Applications"
                     "/PackageMaker.app/Contents/MacOS");
  paths.emplace_back("/Developer/Applications/Utilities"
                     "/PackageMaker.app/Contents/MacOS");
  paths.emplace_back("/Developer/Applications"
                     "/PackageMaker.app/Contents/MacOS");
350 351

  std::string pkgPath;
352 353
  const char* inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM");
  if (inst_program && *inst_program) {
354
    pkgPath = inst_program;
355
  } else {
356
    pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false);
357
    if (pkgPath.empty()) {
358 359
      cmCPackLogger(cmCPackLog::LOG_ERROR,
                    "Cannot find PackageMaker compiler" << std::endl);
360
      return 0;
361
    }
362 363
    this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
  }
364

365
  // Get path to the real PackageMaker, not a symlink:
366
  pkgPath = cmSystemTools::GetRealPath(pkgPath);
367
  // Up from there to find the version.plist file in the "Contents" dir:
368 369 370 371 372 373
  std::string contents_dir;
  contents_dir = cmSystemTools::GetFilenamePath(pkgPath);
  contents_dir = cmSystemTools::GetFilenamePath(contents_dir);

  std::string versionFile = contents_dir + "/version.plist";

374
  if (!cmSystemTools::FileExists(versionFile.c_str())) {
375
    cmCPackLogger(cmCPackLog::LOG_ERROR,
376
                  "Cannot find PackageMaker compiler version file: "
377
                    << versionFile << std::endl);
378
    return 0;
379
  }
380

381
  cmsys::ifstream ifs(versionFile.c_str());
382
  if (!ifs) {
383
    cmCPackLogger(cmCPackLog::LOG_ERROR,
384 385
                  "Cannot open PackageMaker compiler version file"
                    << std::endl);
386
    return 0;
387
  }
388

389 390
  // Check the PackageMaker version
  cmsys::RegularExpression rexKey("<key>CFBundleShortVersionString</key>");
391
  cmsys::RegularExpression rexVersion("<string>([0-9]+.[0-9.]+)</string>");
392 393
  std::string line;
  bool foundKey = false;
394 395
  while (cmSystemTools::GetLineFromStream(ifs, line)) {
    if (rexKey.find(line)) {
396 397 398
      foundKey = true;
      break;
    }
399 400 401 402
  }
  if (!foundKey) {
    cmCPackLogger(
      cmCPackLog::LOG_ERROR,
403
      "Cannot find CFBundleShortVersionString in the PackageMaker compiler "
404 405
      "version file"
        << std::endl);
406
    return 0;
407 408
  }
  if (!cmSystemTools::GetLineFromStream(ifs, line) || !rexVersion.find(line)) {
409
    cmCPackLogger(cmCPackLog::LOG_ERROR,
410
                  "Problem reading the PackageMaker compiler version file: "
411
                    << versionFile << std::endl);
412
    return 0;
413
  }
414
  this->PackageMakerVersion = atof(rexVersion.match(1).c_str());
415
  if (this->PackageMakerVersion < 1.0) {
416 417
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "Require PackageMaker 1.0 or higher" << std::endl);
418
    return 0;
419
  }
420 421 422
  cmCPackLogger(cmCPackLog::LOG_DEBUG,
                "PackageMaker version is: " << this->PackageMakerVersion
                                            << std::endl);
423

424 425 426
  // Determine the package compatibility version. If it wasn't
  // specified by the user, we define it based on which features the
  // user requested.
427 428
  const char* packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION");
  if (packageCompat && *packageCompat) {
429 430 431
    unsigned int majorVersion = 10;
    unsigned int minorVersion = 5;
    int res = sscanf(packageCompat, "%u.%u", &majorVersion, &minorVersion);
432
    if (res == 2) {
433 434
      this->PackageCompatibilityVersion =
        getVersion(majorVersion, minorVersion);
435
    }
436
  } else if (this->GetOption("CPACK_DOWNLOAD_SITE")) {
437
    this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5");
438
    this->PackageCompatibilityVersion = getVersion(10, 5);
439
  } else if (this->GetOption("CPACK_COMPONENTS_ALL")) {
440
    this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4");
441
    this->PackageCompatibilityVersion = getVersion(10, 4);
442
  } else {
443
    this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3");
444
    this->PackageCompatibilityVersion = getVersion(10, 3);
445
  }
446

447 448
  std::vector<std::string> no_paths;
  pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false);
449
  if (pkgPath.empty()) {
450 451
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "Cannot find hdiutil compiler" << std::endl);
452
    return 0;
453
  }
454
  this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
Ken Martin's avatar
Ken Martin committed
455
                          pkgPath.c_str());
456

457
  return this->Superclass::InitializeInternal();
458 459
}

460 461
bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command,
                                                   const char* packageFile)
462
{
463 464
  std::string tmpFile = cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
                                 "/PackageMakerOutput.log");
465 466 467 468

  cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
  std::string output;
  int retVal = 1;
469
  bool res = cmSystemTools::RunSingleCommand(
470 471
    command, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
    cmDuration::zero());
472 473
  cmCPackLogger(cmCPackLog::LOG_VERBOSE,
                "Done running package maker" << std::endl);
474
  if (!res || retVal) {
475
    cmGeneratedFileStream ofs(tmpFile);
476
    ofs << "# Run command: " << command << std::endl
477
        << "# Output:" << std::endl
478
        << output << std::endl;
479 480 481 482 483
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "Problem running PackageMaker command: "
                    << command << std::endl
                    << "Please check " << tmpFile << " for errors"
                    << std::endl);
484
    return false;
485
  }
486 487 488
  // sometimes the command finishes but the directory is not yet
  // created, so try 10 times to see if it shows up
  int tries = 10;
489
  while (tries > 0 && !cmSystemTools::FileExists(packageFile)) {
490 491
    cmSystemTools::Delay(500);
    tries--;
492 493 494 495 496 497
  }
  if (!cmSystemTools::FileExists(packageFile)) {
    cmCPackLogger(cmCPackLog::LOG_ERROR,
                  "Problem running PackageMaker command: "
                    << command << std::endl
                    << "Package not created: " << packageFile << std::endl);
498
    return false;
499
  }
500 501 502 503

  return true;
}

504 505 506
bool cmCPackPackageMakerGenerator::GenerateComponentPackage(
  const char* packageFile, const char* packageDir,
  const cmCPackComponent& component)
507
{
508 509 510
  cmCPackLogger(cmCPackLog::LOG_OUTPUT,
                "-   Building component package: " << packageFile
                                                   << std::endl);
511

512
  // The command that will be used to run PackageMaker
513
  std::ostringstream pkgCmd;
514

515
  if (this->PackageCompatibilityVersion < getVersion(10, 5) ||
516
      this->PackageMakerVersion < 3.0) {
517 518
    // Create Description.plist and Info.plist files for normal Mac OS
    // X packages, which work on Mac OS X 10.3 and newer.
519 520 521
    std::string descriptionFile =
      cmStrCat(this->GetOption("CPACK_TOPLEVEL_DIRECTORY"), '/',
               component.Name, "-Description.plist");
522
    cmsys::ofstream out(descriptionFile.c_str());
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
    cmXMLWriter xout(out);
    xout.StartDocument();
    xout.Doctype("plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
                 "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
    xout.StartElement("plist");
    xout.Attribute("version", "1.4");
    xout.StartElement("dict");
    xout.Element("key", "IFPkgDescriptionTitle");
    xout.Element("string", component.DisplayName);
    xout.Element("key", "IFPkgDescriptionVersion");
    xout.Element("string", this->GetOption("CPACK_PACKAGE_VERSION"));
    xout.Element("key", "IFPkgDescriptionDescription");
    xout.Element("string", component.Description);
    xout.EndElement(); // dict
    xout.EndElement(); // plist
    xout.EndDocument();
539 540 541
    out.close();

    // Create the Info.plist file for this component
542
    std::string moduleVersionSuffix = cmStrCat('.', component.Name);
543
    this->SetOption("CPACK_MODULE_VERSION_SUFFIX",
544
                    moduleVersionSuffix.c_str());
545
    std::string infoFileName = cmStrCat(component.Name, "-Info.plist");
546
    if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str())) {
547
      return false;
548
    }
549 550 551 552

    pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
           << "\" -build -p \"" << packageFile << "\""
           << " -f \"" << packageDir << "\""
553 554
           << " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/"
           << infoFileName << "\""
555
           << " -d \"" << descriptionFile << "\"";
556
  } else {
557 558 559 560 561
    // Create a "flat" package on Mac OS X 10.5 and newer. Flat
    // packages are stored in a single file, rather than a directory
    // like normal packages, and can be downloaded by the installer
    // on-the-fly in Mac OS X 10.5 or newer. Thus, we need to create
    // flat packages when the packages will be downloaded on the fly.
562 563 564
    std::string pkgId =
      cmStrCat("com.", this->GetOption("CPACK_PACKAGE_VENDOR"), '.',
               this->GetOption("CPACK_PACKAGE_NAME"), '.', component.Name);
565 566 567

    pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
           << "\" --root \"" << packageDir << "\""
568 569 570 571
           << " --id " << pkgId << " --target "
           << this->GetOption("CPACK_OSX_PACKAGE_VERSION") << " --out \""
           << packageFile << "\"";
  }
572

573
  // Run PackageMaker
574 575
  return RunPackageMaker(pkgCmd.str().c_str(), packageFile);
}