2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2006-01-02 07:21:05 +03:00
|
|
|
#include "cmCPackPackageMakerGenerator.h"
|
|
|
|
|
|
|
|
#include "cmake.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2008-06-17 19:39:26 +04:00
|
|
|
#include "cmCPackComponentGroup.h"
|
2006-01-03 00:14:21 +03:00
|
|
|
#include "cmCPackLog.h"
|
2006-01-02 07:21:05 +03:00
|
|
|
|
|
|
|
#include <cmsys/SystemTools.hxx>
|
|
|
|
#include <cmsys/Glob.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2014-12-26 20:48:53 +03:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
static inline
|
|
|
|
unsigned int getVersion(unsigned int major, unsigned int minor)
|
|
|
|
{
|
|
|
|
assert(major < 256 && minor < 256);
|
|
|
|
return ((major & 0xFF) << 16 | minor);
|
|
|
|
}
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
|
|
|
|
{
|
2007-11-05 22:34:36 +03:00
|
|
|
this->PackageMakerVersion = 0.0;
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 4);
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
|
|
|
|
{
|
2014-12-26 20:48:53 +03:00
|
|
|
return this->PackageCompatibilityVersion >= getVersion(10, 4);
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2014-02-22 04:05:55 +04:00
|
|
|
int cmCPackPackageMakerGenerator::CopyInstallScript(const std::string& resdir,
|
|
|
|
const std::string& script,
|
|
|
|
const std::string& name)
|
2008-02-19 22:26:20 +03:00
|
|
|
{
|
|
|
|
std::string dst = resdir;
|
|
|
|
dst += "/";
|
|
|
|
dst += name;
|
2014-02-22 04:05:55 +04:00
|
|
|
cmSystemTools::CopyFileAlways(script.c_str(), dst.c_str());
|
2008-02-19 22:26:20 +03:00
|
|
|
cmSystemTools::SetPermissions(dst.c_str(),0777);
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
2012-08-13 21:42:58 +04:00
|
|
|
"copy script : " << script << "\ninto " << dst.c_str() <<
|
2008-02-19 22:26:20 +03:00
|
|
|
std::endl);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
//----------------------------------------------------------------------
|
2010-08-11 21:48:39 +04:00
|
|
|
int cmCPackPackageMakerGenerator::PackageFiles()
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2010-08-11 21:48:39 +04:00
|
|
|
// TODO: Use toplevel
|
|
|
|
// It is used! Is this an obsolete comment?
|
2008-06-18 15:08:33 +04:00
|
|
|
|
|
|
|
std::string resDir; // Where this package's resources will go.
|
|
|
|
std::string packageDirFileName
|
|
|
|
= this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
if (this->Components.empty())
|
|
|
|
{
|
|
|
|
packageDirFileName += ".pkg";
|
|
|
|
resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
resDir += "/Resources";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
packageDirFileName += ".mpkg";
|
|
|
|
if ( !cmsys::SystemTools::MakeDirectory(packageDirFileName.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"unable to create package directory "
|
2008-06-18 15:08:33 +04:00
|
|
|
<< packageDirFileName << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
resDir = packageDirFileName;
|
|
|
|
resDir += "/Contents";
|
|
|
|
if ( !cmsys::SystemTools::MakeDirectory(resDir.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"unable to create package subdirectory " << resDir
|
2008-06-18 15:08:33 +04:00
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
resDir += "/Resources";
|
|
|
|
if ( !cmsys::SystemTools::MakeDirectory(resDir.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"unable to create package subdirectory " << resDir
|
2008-06-18 15:08:33 +04:00
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
resDir += "/en.lproj";
|
|
|
|
}
|
|
|
|
|
2008-02-19 22:26:20 +03:00
|
|
|
const char* preflight = this->GetOption("CPACK_PREFLIGHT_SCRIPT");
|
|
|
|
const char* postflight = this->GetOption("CPACK_POSTFLIGHT_SCRIPT");
|
|
|
|
const char* postupgrade = this->GetOption("CPACK_POSTUPGRADE_SCRIPT");
|
2012-10-27 21:07:31 +04:00
|
|
|
|
|
|
|
if(this->Components.empty())
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2012-10-27 21:07:31 +04:00
|
|
|
// 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
|
|
|
|
if(!preflight)
|
2008-02-19 22:26:20 +03:00
|
|
|
{
|
2012-10-27 21:07:31 +04:00
|
|
|
if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating installer directory: "
|
|
|
|
<< preflightDirName.c_str() << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!postflight)
|
|
|
|
{
|
|
|
|
if ( !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating installer directory: "
|
|
|
|
<< postflightDirName.c_str() << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if preflight, postflight, or postupgrade are set
|
|
|
|
// then copy them into the resource directory and make
|
|
|
|
// them executable
|
|
|
|
if(preflight)
|
|
|
|
{
|
|
|
|
this->CopyInstallScript(resDir.c_str(),
|
|
|
|
preflight,
|
|
|
|
"preflight");
|
|
|
|
}
|
|
|
|
if(postflight)
|
|
|
|
{
|
|
|
|
this->CopyInstallScript(resDir.c_str(),
|
|
|
|
postflight,
|
|
|
|
"postflight");
|
|
|
|
}
|
|
|
|
if(postupgrade)
|
|
|
|
{
|
|
|
|
this->CopyInstallScript(resDir.c_str(),
|
|
|
|
postupgrade,
|
|
|
|
"postupgrade");
|
2008-02-19 22:26:20 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
else if(postflight)
|
2008-02-19 22:26:20 +03:00
|
|
|
{
|
2012-10-27 21:07:31 +04:00
|
|
|
// 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;
|
|
|
|
if (!cmsys::SystemTools::MakeDirectory(packageDir.c_str()))
|
2008-02-19 22:26:20 +03:00
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-10-27 21:07:31 +04:00
|
|
|
"Problem creating component packages directory: "
|
|
|
|
<< packageDir.c_str() << std::endl);
|
2008-02-19 22:26:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
|
|
|
|
// create package
|
|
|
|
std::string packageFileDir = packageDirFileName + "/Contents/Packages/";
|
|
|
|
if (!cmsys::SystemTools::MakeDirectory(packageFileDir.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating component PostFlight Packages directory: "
|
|
|
|
<< packageFileDir.c_str() << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
std::string packageFile = packageFileDir +
|
|
|
|
this->GetPackageName(PostFlightComponent);
|
|
|
|
if (!this->GenerateComponentPackage(packageFile.c_str(),
|
|
|
|
packageDir.c_str(),
|
|
|
|
PostFlightComponent))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy postflight script into resource directory of .pkg
|
|
|
|
std::string resourceDir = packageFile + "/Contents/Resources";
|
|
|
|
this->CopyInstallScript(resourceDir.c_str(),
|
2008-06-17 19:39:26 +04:00
|
|
|
postflight,
|
|
|
|
"postflight");
|
2008-02-19 22:26:20 +03:00
|
|
|
}
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
if (!this->Components.empty())
|
|
|
|
{
|
2008-07-09 21:38:56 +04:00
|
|
|
// Create the directory where component packages will be built.
|
2008-06-18 15:08:33 +04:00
|
|
|
std::string basePackageDir = packageDirFileName;
|
|
|
|
basePackageDir += "/Contents/Packages";
|
2008-06-17 19:39:26 +04:00
|
|
|
if (!cmsys::SystemTools::MakeDirectory(basePackageDir.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem creating component packages directory: "
|
|
|
|
<< basePackageDir.c_str() << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-09 21:38:56 +04:00
|
|
|
// Create the directory where downloaded component packages will
|
|
|
|
// be placed.
|
2008-10-01 17:04:27 +04:00
|
|
|
const char* userUploadDirectory =
|
|
|
|
this->GetOption("CPACK_UPLOAD_DIRECTORY");
|
2008-07-09 21:38:56 +04:00
|
|
|
std::string uploadDirectory;
|
|
|
|
if (userUploadDirectory && *userUploadDirectory)
|
|
|
|
{
|
|
|
|
uploadDirectory = userUploadDirectory;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uploadDirectory= this->GetOption("CPACK_PACKAGE_DIRECTORY");
|
|
|
|
uploadDirectory += "/CPackUploads";
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
// Create packages for each component
|
2008-07-09 21:38:56 +04:00
|
|
|
bool warnedAboutDownloadCompatibility = false;
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
|
|
|
++compIt)
|
|
|
|
{
|
2008-07-09 21:38:56 +04:00
|
|
|
std::string packageFile;
|
|
|
|
if (compIt->second.IsDownloaded)
|
|
|
|
{
|
2014-12-26 20:48:53 +03:00
|
|
|
if (this->PackageCompatibilityVersion >= getVersion(10, 5) &&
|
2008-07-09 21:38:56 +04:00
|
|
|
this->PackageMakerVersion >= 3.0)
|
|
|
|
{
|
|
|
|
// Build this package within the upload directory.
|
|
|
|
packageFile = uploadDirectory;
|
|
|
|
|
|
|
|
if(!cmSystemTools::FileExists(uploadDirectory.c_str()))
|
|
|
|
{
|
|
|
|
if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
2012-08-13 21:42:58 +04:00
|
|
|
"Unable to create package upload directory "
|
2008-07-09 21:38:56 +04:00
|
|
|
<< uploadDirectory << std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!warnedAboutDownloadCompatibility)
|
|
|
|
{
|
2014-12-26 20:48:53 +03:00
|
|
|
if (this->PackageCompatibilityVersion < getVersion(10, 5))
|
2008-07-09 21:38:56 +04:00
|
|
|
{
|
2008-10-01 17:04:27 +04:00
|
|
|
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."
|
|
|
|
<< std::endl);
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this->PackageMakerVersion < 3)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_WARNING,
|
2008-10-01 17:04:27 +04:00
|
|
|
"CPack warning: unable to build downloaded "
|
|
|
|
"packages with PackageMaker versions prior "
|
|
|
|
"to 3.0. CPack will build a non-downloaded package."
|
2008-07-09 21:38:56 +04:00
|
|
|
<< std::endl);
|
|
|
|
}
|
|
|
|
|
|
|
|
warnedAboutDownloadCompatibility = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packageFile.empty())
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
packageFile += '/';
|
|
|
|
packageFile += GetPackageName(compIt->second);
|
|
|
|
|
|
|
|
std::string packageDir = toplevel;
|
|
|
|
packageDir += '/';
|
|
|
|
packageDir += compIt->first;
|
2012-08-13 21:42:58 +04:00
|
|
|
if (!this->GenerateComponentPackage(packageFile.c_str(),
|
2008-06-17 19:39:26 +04:00
|
|
|
packageDir.c_str(),
|
|
|
|
compIt->second))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->SetOption("CPACK_MODULE_VERSION_SUFFIX", "");
|
|
|
|
|
|
|
|
// Copy or create all of the resource files we need.
|
2008-06-18 15:08:33 +04:00
|
|
|
if ( !this->CopyCreateResourceFile("License", resDir.c_str())
|
|
|
|
|| !this->CopyCreateResourceFile("ReadMe", resDir.c_str())
|
|
|
|
|| !this->CopyCreateResourceFile("Welcome", resDir.c_str())
|
|
|
|
|| !this->CopyResourcePlistFile("Info.plist")
|
|
|
|
|| !this->CopyResourcePlistFile("Description.plist") )
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
|
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
if (this->Components.empty())
|
|
|
|
{
|
2008-06-18 15:08:33 +04:00
|
|
|
// Use PackageMaker to build the package.
|
|
|
|
cmOStringStream pkgCmd;
|
|
|
|
pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
|
|
|
|
<< "\" -build -p \"" << packageDirFileName << "\"";
|
|
|
|
if (this->Components.empty())
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
2008-06-18 15:08:33 +04:00
|
|
|
pkgCmd << " -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
2008-06-18 15:08:33 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pkgCmd << " -mi \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
|
|
|
|
<< "/packages/";
|
|
|
|
}
|
|
|
|
pkgCmd << "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
|
|
|
<< "/Resources\" -i \""
|
2012-08-13 21:42:58 +04:00
|
|
|
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
2008-06-18 15:08:33 +04:00
|
|
|
<< "/Info.plist\" -d \""
|
2008-07-09 21:38:56 +04:00
|
|
|
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
2008-06-18 15:08:33 +04:00
|
|
|
<< "/Description.plist\"";
|
|
|
|
if ( this->PackageMakerVersion > 2.0 )
|
|
|
|
{
|
|
|
|
pkgCmd << " -v";
|
|
|
|
}
|
|
|
|
if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str()))
|
|
|
|
return 0;
|
2006-03-03 23:04:28 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
else
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2008-06-18 15:08:33 +04:00
|
|
|
// We have built the package in place. Generate the
|
|
|
|
// distribution.dist file to describe it for the installer.
|
2008-06-17 19:39:26 +04:00
|
|
|
WriteDistributionFile(packageDirFileName.c_str());
|
2007-12-17 23:27:30 +03:00
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
2006-01-02 07:21:05 +03:00
|
|
|
tmpFile += "/hdiutilOutput.log";
|
|
|
|
cmOStringStream dmgCmd;
|
2006-03-09 00:33:39 +03:00
|
|
|
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
|
|
|
|
<< "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
|
2010-08-11 21:48:39 +04:00
|
|
|
<< "\" \"" << packageFileNames[0] << "\"";
|
2008-06-17 19:39:26 +04:00
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
2012-03-09 20:39:01 +04:00
|
|
|
int numTries = 10;
|
2011-02-03 18:21:32 +03:00
|
|
|
bool res = false;
|
2009-10-04 17:54:55 +04:00
|
|
|
while(numTries > 0)
|
|
|
|
{
|
|
|
|
res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output,
|
2012-08-13 21:42:58 +04:00
|
|
|
&retVal, 0, this->GeneratorVerbose,
|
2009-10-04 17:54:55 +04:00
|
|
|
0);
|
2012-03-09 20:39:01 +04:00
|
|
|
if ( res && !retVal )
|
2009-10-04 17:54:55 +04:00
|
|
|
{
|
|
|
|
numTries = -1;
|
2012-03-09 20:39:01 +04:00
|
|
|
break;
|
2009-10-04 17:54:55 +04:00
|
|
|
}
|
2012-03-09 20:39:01 +04:00
|
|
|
cmSystemTools::Delay(500);
|
2009-10-04 17:54:55 +04:00
|
|
|
numTries--;
|
|
|
|
}
|
2006-01-02 07:21:05 +03:00
|
|
|
if ( !res || retVal )
|
|
|
|
{
|
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
|
|
|
ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
|
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output.c_str() << std::endl;
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
|
|
|
|
<< dmgCmd.str().c_str() << std::endl
|
2006-01-03 00:14:21 +03:00
|
|
|
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-04-15 21:02:18 +04:00
|
|
|
int cmCPackPackageMakerGenerator::InitializeInternal()
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
|
|
|
"cmCPackPackageMakerGenerator::Initialize()" << std::endl);
|
2007-10-31 15:50:17 +03:00
|
|
|
this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
|
2012-03-04 00:03:50 +04:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
paths.push_back(
|
|
|
|
"/Applications/Xcode.app/Contents/Applications"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back(
|
|
|
|
"/Applications/Utilities"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back(
|
|
|
|
"/Applications"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back(
|
|
|
|
"/Developer/Applications/Utilities"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
paths.push_back(
|
|
|
|
"/Developer/Applications"
|
|
|
|
"/PackageMaker.app/Contents/MacOS");
|
|
|
|
|
|
|
|
std::string pkgPath;
|
|
|
|
const char *inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM");
|
|
|
|
if (inst_program && *inst_program)
|
|
|
|
{
|
|
|
|
pkgPath = inst_program;
|
|
|
|
}
|
|
|
|
else
|
2006-03-03 23:04:28 +03:00
|
|
|
{
|
2012-03-04 00:03:50 +04:00
|
|
|
pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false);
|
|
|
|
if ( pkgPath.empty() )
|
2006-03-21 00:24:43 +03:00
|
|
|
{
|
2012-03-04 00:03:50 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler"
|
2006-03-21 00:24:43 +03:00
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-04 00:03:50 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
|
|
|
|
}
|
|
|
|
|
2012-03-13 22:01:19 +04:00
|
|
|
// Get path to the real PackageMaker, not a symlink:
|
|
|
|
pkgPath = cmSystemTools::GetRealPath(pkgPath.c_str());
|
|
|
|
// Up from there to find the version.plist file in the "Contents" dir:
|
2012-03-04 00:03:50 +04:00
|
|
|
std::string contents_dir;
|
|
|
|
contents_dir = cmSystemTools::GetFilenamePath(pkgPath);
|
|
|
|
contents_dir = cmSystemTools::GetFilenamePath(contents_dir);
|
|
|
|
|
|
|
|
std::string versionFile = contents_dir + "/version.plist";
|
|
|
|
|
|
|
|
if ( !cmSystemTools::FileExists(versionFile.c_str()) )
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Cannot find PackageMaker compiler version file: "
|
|
|
|
<< versionFile.c_str()
|
|
|
|
<< std::endl);
|
|
|
|
return 0;
|
2006-03-03 23:04:28 +03:00
|
|
|
}
|
2012-03-04 00:03:50 +04:00
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream ifs(versionFile.c_str());
|
2006-03-03 23:04:28 +03:00
|
|
|
if ( !ifs )
|
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Cannot open PackageMaker compiler version file" << std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2012-03-04 00:03:50 +04:00
|
|
|
|
2006-03-03 23:04:28 +03:00
|
|
|
// Check the PackageMaker version
|
|
|
|
cmsys::RegularExpression rexKey("<key>CFBundleShortVersionString</key>");
|
2006-03-08 21:59:33 +03:00
|
|
|
cmsys::RegularExpression rexVersion("<string>([0-9]+.[0-9.]+)</string>");
|
2006-03-03 23:04:28 +03:00
|
|
|
std::string line;
|
|
|
|
bool foundKey = false;
|
|
|
|
while ( cmSystemTools::GetLineFromStream(ifs, line) )
|
|
|
|
{
|
|
|
|
if ( rexKey.find(line) )
|
|
|
|
{
|
|
|
|
foundKey = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !foundKey )
|
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Cannot find CFBundleShortVersionString in the PackageMaker compiler "
|
|
|
|
"version file" << std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2006-03-09 16:32:08 +03:00
|
|
|
if ( !cmSystemTools::GetLineFromStream(ifs, line) ||
|
|
|
|
!rexVersion.find(line) )
|
2006-03-03 23:04:28 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem reading the PackageMaker compiler version file: "
|
|
|
|
<< versionFile.c_str() << std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
this->PackageMakerVersion = atof(rexVersion.match(1).c_str());
|
2007-11-05 22:34:36 +03:00
|
|
|
if ( this->PackageMakerVersion < 1.0 )
|
2006-03-03 23:04:28 +03:00
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Require PackageMaker 1.0 or higher"
|
|
|
|
<< std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "PackageMaker version is: "
|
|
|
|
<< this->PackageMakerVersion << std::endl);
|
2006-03-03 23:04:28 +03:00
|
|
|
|
2008-07-09 21:38:56 +04:00
|
|
|
// Determine the package compatibility version. If it wasn't
|
|
|
|
// specified by the user, we define it based on which features the
|
|
|
|
// user requested.
|
|
|
|
const char *packageCompat = this->GetOption("CPACK_OSX_PACKAGE_VERSION");
|
|
|
|
if (packageCompat && *packageCompat)
|
|
|
|
{
|
2014-12-26 20:48:53 +03:00
|
|
|
unsigned int majorVersion = 10;
|
|
|
|
unsigned int minorVersion = 5;
|
|
|
|
int res = sscanf(packageCompat, "%u.%u", &majorVersion, &minorVersion);
|
|
|
|
if (res == 2)
|
|
|
|
{
|
|
|
|
this->PackageCompatibilityVersion =
|
|
|
|
getVersion(majorVersion, minorVersion);
|
|
|
|
}
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
|
|
|
else if (this->GetOption("CPACK_DOWNLOAD_SITE"))
|
|
|
|
{
|
|
|
|
this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.5");
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 5);
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
|
|
|
else if (this->GetOption("CPACK_COMPONENTS_ALL"))
|
|
|
|
{
|
|
|
|
this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.4");
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 4);
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->SetOption("CPACK_OSX_PACKAGE_VERSION", "10.3");
|
2014-12-26 20:48:53 +03:00
|
|
|
this->PackageCompatibilityVersion = getVersion(10, 3);
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
|
|
|
|
2012-03-04 00:03:50 +04:00
|
|
|
std::vector<std::string> no_paths;
|
|
|
|
pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false);
|
2006-01-02 07:21:05 +03:00
|
|
|
if ( pkgPath.empty() )
|
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler"
|
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
|
2006-05-12 22:44:24 +04:00
|
|
|
pkgPath.c_str());
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2006-04-15 21:02:18 +04:00
|
|
|
return this->Superclass::InitializeInternal();
|
2006-01-02 07:21:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2014-02-08 00:02:41 +04:00
|
|
|
bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& dirName)
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
|
|
|
std::string uname = cmSystemTools::UpperCase(name);
|
|
|
|
std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
|
|
|
|
const char* inFileName = this->GetOption(cpackVar.c_str());
|
|
|
|
if ( !inFileName )
|
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str()
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " not specified. It should point to "
|
2014-02-08 00:02:41 +04:00
|
|
|
<< (!name.empty() ? name : "<empty>")
|
2006-10-30 19:22:48 +03:00
|
|
|
<< ".rtf, " << name
|
|
|
|
<< ".html, or " << name << ".txt file" << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( !cmSystemTools::FileExists(inFileName) )
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find "
|
2014-02-08 00:02:41 +04:00
|
|
|
<< (!name.empty() ? name : "<empty>")
|
2006-10-30 19:22:48 +03:00
|
|
|
<< " resource file: " << inFileName << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
|
|
|
|
if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
|
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: "
|
|
|
|
<< ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed."
|
|
|
|
<< std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-18 15:08:33 +04:00
|
|
|
std::string destFileName = dirName;
|
|
|
|
destFileName += '/';
|
2006-01-02 07:21:05 +03:00
|
|
|
destFileName += name + ext;
|
|
|
|
|
2008-06-18 15:08:33 +04:00
|
|
|
// Set this so that distribution.dist gets the right name (without
|
|
|
|
// the path).
|
|
|
|
this->SetOption(("CPACK_RESOURCE_FILE_" + uname + "_NOPATH").c_str(),
|
|
|
|
(name + ext).c_str());
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
|
2006-10-30 19:22:48 +03:00
|
|
|
<< (inFileName ? inFileName : "(NULL)")
|
|
|
|
<< " to " << destFileName.c_str() << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
this->ConfigureFile(inFileName, destFileName.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-22 04:05:55 +04:00
|
|
|
bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(
|
|
|
|
const std::string& name,
|
|
|
|
const char* outName)
|
2006-01-02 07:21:05 +03:00
|
|
|
{
|
2008-06-17 19:39:26 +04:00
|
|
|
if (!outName)
|
|
|
|
{
|
2014-02-22 04:05:55 +04:00
|
|
|
outName = name.c_str();
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
2006-01-02 07:21:05 +03:00
|
|
|
std::string inFName = "CPack.";
|
|
|
|
inFName += name;
|
|
|
|
inFName += ".in";
|
|
|
|
std::string inFileName = this->FindTemplate(inFName.c_str());
|
|
|
|
if ( inFileName.empty() )
|
|
|
|
{
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: "
|
|
|
|
<< inFName << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
destFileName += "/";
|
2008-06-17 19:39:26 +04:00
|
|
|
destFileName += outName;
|
2006-01-02 07:21:05 +03:00
|
|
|
|
2006-03-09 00:33:39 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
|
|
|
|
<< inFileName.c_str() << " to " << destFileName.c_str() << std::endl);
|
2006-01-02 07:21:05 +03:00
|
|
|
this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool cmCPackPackageMakerGenerator::RunPackageMaker(const char *command,
|
|
|
|
const char *packageFile)
|
|
|
|
{
|
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
tmpFile += "/PackageMakerOutput.log";
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
|
|
|
|
std::string output;
|
|
|
|
int retVal = 1;
|
2012-08-13 21:42:58 +04:00
|
|
|
bool res = cmSystemTools::RunSingleCommand(command, &output, &retVal, 0,
|
2008-06-17 19:39:26 +04:00
|
|
|
this->GeneratorVerbose, 0);
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker"
|
|
|
|
<< std::endl);
|
|
|
|
if ( !res || retVal )
|
|
|
|
{
|
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
|
|
|
ofs << "# Run command: " << command << std::endl
|
|
|
|
<< "# Output:" << std::endl
|
|
|
|
<< output.c_str() << std::endl;
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem running PackageMaker command: " << command
|
|
|
|
<< std::endl << "Please check " << tmpFile.c_str() << " for errors"
|
|
|
|
<< std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// sometimes the command finishes but the directory is not yet
|
|
|
|
// created, so try 10 times to see if it shows up
|
|
|
|
int tries = 10;
|
2012-08-13 21:42:58 +04:00
|
|
|
while(tries > 0 &&
|
2008-06-17 19:39:26 +04:00
|
|
|
!cmSystemTools::FileExists(packageFile))
|
|
|
|
{
|
|
|
|
cmSystemTools::Delay(500);
|
|
|
|
tries--;
|
|
|
|
}
|
|
|
|
if(!cmSystemTools::FileExists(packageFile))
|
|
|
|
{
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem running PackageMaker command: " << command
|
|
|
|
<< std::endl << "Package not created: " << packageFile
|
|
|
|
<< std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-08-13 21:42:58 +04:00
|
|
|
std::string
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackPackageMakerGenerator::GetPackageName(const cmCPackComponent& component)
|
|
|
|
{
|
2008-07-09 21:38:56 +04:00
|
|
|
if (component.ArchiveFile.empty())
|
|
|
|
{
|
|
|
|
std::string packagesDir = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
packagesDir += ".dummy";
|
|
|
|
cmOStringStream out;
|
|
|
|
out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir)
|
|
|
|
<< "-" << component.Name << ".pkg";
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return component.ArchiveFile + ".pkg";
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
cmCPackPackageMakerGenerator::
|
|
|
|
GenerateComponentPackage(const char *packageFile,
|
|
|
|
const char *packageDir,
|
|
|
|
const cmCPackComponent& component)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
2008-10-01 17:04:27 +04:00
|
|
|
"- Building component package: " <<
|
|
|
|
packageFile << std::endl);
|
2008-06-17 19:39:26 +04:00
|
|
|
|
2008-07-09 21:38:56 +04:00
|
|
|
// The command that will be used to run PackageMaker
|
|
|
|
cmOStringStream pkgCmd;
|
|
|
|
|
2014-12-26 20:48:53 +03:00
|
|
|
if (this->PackageCompatibilityVersion < getVersion(10, 5) ||
|
2008-07-09 21:38:56 +04:00
|
|
|
this->PackageMakerVersion < 3.0)
|
|
|
|
{
|
|
|
|
// Create Description.plist and Info.plist files for normal Mac OS
|
|
|
|
// X packages, which work on Mac OS X 10.3 and newer.
|
|
|
|
std::string descriptionFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
descriptionFile += '/' + component.Name + "-Description.plist";
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream out(descriptionFile.c_str());
|
2008-07-09 21:38:56 +04:00
|
|
|
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl
|
|
|
|
<< "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
|
|
|
|
<< "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" << std::endl
|
|
|
|
<< "<plist version=\"1.4\">" << std::endl
|
|
|
|
<< "<dict>" << std::endl
|
|
|
|
<< " <key>IFPkgDescriptionTitle</key>" << std::endl
|
|
|
|
<< " <string>" << component.DisplayName << "</string>" << std::endl
|
|
|
|
<< " <key>IFPkgDescriptionVersion</key>" << std::endl
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " <string>" << this->GetOption("CPACK_PACKAGE_VERSION")
|
2008-07-09 21:38:56 +04:00
|
|
|
<< "</string>" << std::endl
|
|
|
|
<< " <key>IFPkgDescriptionDescription</key>" << std::endl
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " <string>" + this->EscapeForXML(component.Description)
|
2008-07-09 21:38:56 +04:00
|
|
|
<< "</string>" << std::endl
|
|
|
|
<< "</dict>" << std::endl
|
|
|
|
<< "</plist>" << std::endl;
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
// Create the Info.plist file for this component
|
|
|
|
std::string moduleVersionSuffix = ".";
|
|
|
|
moduleVersionSuffix += component.Name;
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOption("CPACK_MODULE_VERSION_SUFFIX",
|
2008-10-01 17:04:27 +04:00
|
|
|
moduleVersionSuffix.c_str());
|
2008-07-09 21:38:56 +04:00
|
|
|
std::string infoFileName = component.Name;
|
|
|
|
infoFileName += "-Info.plist";
|
|
|
|
if (!this->CopyResourcePlistFile("Info.plist", infoFileName.c_str()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
|
|
|
|
<< "\" -build -p \"" << packageFile << "\""
|
|
|
|
<< " -f \"" << packageDir << "\""
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " -i \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY")
|
2008-07-09 21:38:56 +04:00
|
|
|
<< "/" << infoFileName << "\""
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " -d \"" << descriptionFile << "\"";
|
2008-07-09 21:38:56 +04:00
|
|
|
}
|
|
|
|
else
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
2008-07-09 21:38:56 +04:00
|
|
|
// 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.
|
|
|
|
std::string pkgId = "com.";
|
|
|
|
pkgId += this->GetOption("CPACK_PACKAGE_VENDOR");
|
|
|
|
pkgId += '.';
|
|
|
|
pkgId += this->GetOption("CPACK_PACKAGE_NAME");
|
|
|
|
pkgId += '.';
|
|
|
|
pkgId += component.Name;
|
|
|
|
|
|
|
|
pkgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
|
|
|
|
<< "\" --root \"" << packageDir << "\""
|
|
|
|
<< " --id " << pkgId
|
|
|
|
<< " --target " << this->GetOption("CPACK_OSX_PACKAGE_VERSION")
|
|
|
|
<< " --out \"" << packageFile << "\"";
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
// Run PackageMaker
|
2008-06-17 19:39:26 +04:00
|
|
|
return RunPackageMaker(pkgCmd.str().c_str(), packageFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-08-13 21:42:58 +04:00
|
|
|
void
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackPackageMakerGenerator::
|
|
|
|
WriteDistributionFile(const char* metapackageFile)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
std::string distributionTemplate
|
2008-06-17 19:39:26 +04:00
|
|
|
= this->FindTemplate("CPack.distribution.dist.in");
|
|
|
|
if ( distributionTemplate.empty() )
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: "
|
|
|
|
<< distributionTemplate << std::endl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string distributionFile = metapackageFile;
|
|
|
|
distributionFile += "/Contents/distribution.dist";
|
|
|
|
|
|
|
|
// Create the choice outline, which provides a tree-based view of
|
|
|
|
// the components in their groups.
|
|
|
|
cmOStringStream choiceOut;
|
|
|
|
choiceOut << "<choices-outline>" << std::endl;
|
|
|
|
|
|
|
|
// Emit the outline for the groups
|
|
|
|
std::map<std::string, cmCPackComponentGroup>::iterator groupIt;
|
2012-08-13 21:42:58 +04:00
|
|
|
for (groupIt = this->ComponentGroups.begin();
|
|
|
|
groupIt != this->ComponentGroups.end();
|
2008-06-17 19:39:26 +04:00
|
|
|
++groupIt)
|
|
|
|
{
|
2008-07-08 19:52:25 +04:00
|
|
|
if (groupIt->second.ParentGroup == 0)
|
|
|
|
{
|
|
|
|
CreateChoiceOutline(groupIt->second, choiceOut);
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the outline for the non-grouped components
|
|
|
|
std::map<std::string, cmCPackComponent>::iterator compIt;
|
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
|
|
|
++compIt)
|
|
|
|
{
|
|
|
|
if (!compIt->second.Group)
|
|
|
|
{
|
|
|
|
choiceOut << "<line choice=\"" << compIt->first << "Choice\"></line>"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
if(!this->PostFlightComponent.Name.empty())
|
|
|
|
{
|
|
|
|
choiceOut << "<line choice=\"" << PostFlightComponent.Name
|
|
|
|
<< "Choice\"></line>" << std::endl;
|
|
|
|
}
|
2008-06-17 19:39:26 +04:00
|
|
|
choiceOut << "</choices-outline>" << std::endl;
|
|
|
|
|
|
|
|
// Create the actual choices
|
2012-08-13 21:42:58 +04:00
|
|
|
for (groupIt = this->ComponentGroups.begin();
|
|
|
|
groupIt != this->ComponentGroups.end();
|
2008-06-17 19:39:26 +04:00
|
|
|
++groupIt)
|
|
|
|
{
|
|
|
|
CreateChoice(groupIt->second, choiceOut);
|
|
|
|
}
|
|
|
|
for (compIt = this->Components.begin(); compIt != this->Components.end();
|
|
|
|
++compIt)
|
|
|
|
{
|
|
|
|
CreateChoice(compIt->second, choiceOut);
|
|
|
|
}
|
2012-10-27 21:07:31 +04:00
|
|
|
|
|
|
|
if(!this->PostFlightComponent.Name.empty())
|
|
|
|
{
|
|
|
|
CreateChoice(PostFlightComponent, choiceOut);
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
this->SetOption("CPACK_PACKAGEMAKER_CHOICES", choiceOut.str().c_str());
|
|
|
|
|
|
|
|
// Create the distribution.dist file in the metapackage to turn it
|
|
|
|
// into a distribution package.
|
2012-08-13 21:42:58 +04:00
|
|
|
this->ConfigureFile(distributionTemplate.c_str(),
|
2008-06-17 19:39:26 +04:00
|
|
|
distributionFile.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmCPackPackageMakerGenerator::
|
|
|
|
CreateChoiceOutline(const cmCPackComponentGroup& group, cmOStringStream& out)
|
|
|
|
{
|
|
|
|
out << "<line choice=\"" << group.Name << "Choice\">" << std::endl;
|
2008-07-08 19:52:25 +04:00
|
|
|
std::vector<cmCPackComponentGroup*>::const_iterator groupIt;
|
|
|
|
for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end();
|
|
|
|
++groupIt)
|
|
|
|
{
|
|
|
|
CreateChoiceOutline(**groupIt, out);
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::vector<cmCPackComponent*>::const_iterator compIt;
|
|
|
|
for (compIt = group.Components.begin(); compIt != group.Components.end();
|
|
|
|
++compIt)
|
|
|
|
{
|
|
|
|
out << " <line choice=\"" << (*compIt)->Name << "Choice\"></line>"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
out << "</line>" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-08-13 21:42:58 +04:00
|
|
|
void
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackPackageMakerGenerator::CreateChoice(const cmCPackComponentGroup& group,
|
|
|
|
cmOStringStream& out)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
out << "<choice id=\"" << group.Name << "Choice\" "
|
2008-06-17 19:39:26 +04:00
|
|
|
<< "title=\"" << group.DisplayName << "\" "
|
2012-08-13 21:42:58 +04:00
|
|
|
<< "start_selected=\"true\" "
|
2008-06-17 19:39:26 +04:00
|
|
|
<< "start_enabled=\"true\" "
|
|
|
|
<< "start_visible=\"true\" ";
|
|
|
|
if (!group.Description.empty())
|
|
|
|
{
|
|
|
|
out << "description=\"" << EscapeForXML(group.Description)
|
|
|
|
<< "\"";
|
|
|
|
}
|
|
|
|
out << "></choice>" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-08-13 21:42:58 +04:00
|
|
|
void
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackPackageMakerGenerator::CreateChoice(const cmCPackComponent& component,
|
|
|
|
cmOStringStream& out)
|
|
|
|
{
|
|
|
|
std::string packageId = "com.";
|
|
|
|
packageId += this->GetOption("CPACK_PACKAGE_VENDOR");
|
2012-08-13 21:42:58 +04:00
|
|
|
packageId += '.';
|
2008-06-17 19:39:26 +04:00
|
|
|
packageId += this->GetOption("CPACK_PACKAGE_NAME");
|
|
|
|
packageId += '.';
|
|
|
|
packageId += component.Name;
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
out << "<choice id=\"" << component.Name << "Choice\" "
|
2008-06-17 19:39:26 +04:00
|
|
|
<< "title=\"" << component.DisplayName << "\" "
|
2012-08-13 21:42:58 +04:00
|
|
|
<< "start_selected=\""
|
|
|
|
<< (component.IsDisabledByDefault &&
|
2008-10-01 17:04:27 +04:00
|
|
|
!component.IsRequired? "false" : "true")
|
2008-06-17 19:39:26 +04:00
|
|
|
<< "\" "
|
|
|
|
<< "start_enabled=\""
|
|
|
|
<< (component.IsRequired? "false" : "true")
|
|
|
|
<< "\" "
|
|
|
|
<< "start_visible=\"" << (component.IsHidden? "false" : "true") << "\" ";
|
|
|
|
if (!component.Description.empty())
|
|
|
|
{
|
|
|
|
out << "description=\"" << EscapeForXML(component.Description)
|
|
|
|
<< "\" ";
|
|
|
|
}
|
2008-10-01 17:04:27 +04:00
|
|
|
if (!component.Dependencies.empty() ||
|
|
|
|
!component.ReverseDependencies.empty())
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
|
|
|
// The "selected" expression is evaluated each time any choice is
|
|
|
|
// selected, for all choices *except* the one that the user
|
|
|
|
// selected. A component is marked selected if it has been
|
|
|
|
// selected (my.choice.selected in Javascript) and all of the
|
|
|
|
// components it depends on have been selected (transitively) or
|
|
|
|
// if any of the components that depend on it have been selected
|
|
|
|
// (transitively). Assume that we have components A, B, C, D, and
|
|
|
|
// E, where each component depends on the previous component (B
|
|
|
|
// depends on A, C depends on B, D depends on C, and E depends on
|
|
|
|
// D). The expression we build for the component C will be
|
|
|
|
// my.choice.selected && B && A || D || E
|
|
|
|
// This way, selecting C will automatically select everything it depends
|
|
|
|
// on (B and A), while selecting something that depends on C--either D
|
|
|
|
// or E--will automatically cause C to get selected.
|
|
|
|
out << "selected=\"my.choice.selected";
|
2008-07-30 21:28:17 +04:00
|
|
|
std::set<const cmCPackComponent *> visited;
|
|
|
|
AddDependencyAttributes(component, visited, out);
|
|
|
|
visited.clear();
|
|
|
|
AddReverseDependencyAttributes(component, visited, out);
|
2008-06-17 19:39:26 +04:00
|
|
|
out << "\"";
|
|
|
|
}
|
|
|
|
out << ">" << std::endl;
|
|
|
|
out << " <pkg-ref id=\"" << packageId << "\"></pkg-ref>" << std::endl;
|
|
|
|
out << "</choice>" << std::endl;
|
|
|
|
|
|
|
|
// Create a description of the package associated with this
|
|
|
|
// component.
|
|
|
|
std::string relativePackageLocation = "Contents/Packages/";
|
2008-07-09 21:38:56 +04:00
|
|
|
relativePackageLocation += this->GetPackageName(component);
|
|
|
|
|
|
|
|
// Determine the installed size of the package.
|
|
|
|
std::string dirName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
|
|
|
dirName += '/';
|
|
|
|
dirName += component.Name;
|
2012-08-13 21:42:58 +04:00
|
|
|
unsigned long installedSize
|
2008-07-09 21:38:56 +04:00
|
|
|
= component.GetInstalledSizeInKbytes(dirName.c_str());
|
2008-06-17 19:39:26 +04:00
|
|
|
|
|
|
|
out << "<pkg-ref id=\"" << packageId << "\" "
|
|
|
|
<< "version=\"" << this->GetOption("CPACK_PACKAGE_VERSION") << "\" "
|
|
|
|
<< "installKBytes=\"" << installedSize << "\" "
|
2008-07-09 21:38:56 +04:00
|
|
|
<< "auth=\"Admin\" onConclusion=\"None\">";
|
|
|
|
if (component.IsDownloaded)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
out << this->GetOption("CPACK_DOWNLOAD_SITE")
|
2008-07-09 21:38:56 +04:00
|
|
|
<< this->GetPackageName(component);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out << "file:./" << relativePackageLocation;
|
|
|
|
}
|
|
|
|
out << "</pkg-ref>" << std::endl;
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-08-13 21:42:58 +04:00
|
|
|
void
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackPackageMakerGenerator::
|
2012-08-13 21:42:58 +04:00
|
|
|
AddDependencyAttributes(const cmCPackComponent& component,
|
2008-07-30 21:28:17 +04:00
|
|
|
std::set<const cmCPackComponent *>& visited,
|
|
|
|
cmOStringStream& out)
|
2008-06-17 19:39:26 +04:00
|
|
|
{
|
2008-07-30 21:28:17 +04:00
|
|
|
if (visited.find(&component) != visited.end())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
visited.insert(&component);
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::vector<cmCPackComponent *>::const_iterator dependIt;
|
|
|
|
for (dependIt = component.Dependencies.begin();
|
|
|
|
dependIt != component.Dependencies.end();
|
|
|
|
++dependIt)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
out << " && choices['" <<
|
2008-10-01 17:04:27 +04:00
|
|
|
(*dependIt)->Name << "Choice'].selected";
|
2008-07-30 21:28:17 +04:00
|
|
|
AddDependencyAttributes(**dependIt, visited, out);
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-08-13 21:42:58 +04:00
|
|
|
void
|
2008-06-17 19:39:26 +04:00
|
|
|
cmCPackPackageMakerGenerator::
|
2012-08-13 21:42:58 +04:00
|
|
|
AddReverseDependencyAttributes(const cmCPackComponent& component,
|
2008-07-30 21:28:17 +04:00
|
|
|
std::set<const cmCPackComponent *>& visited,
|
2008-06-17 19:39:26 +04:00
|
|
|
cmOStringStream& out)
|
|
|
|
{
|
2008-07-30 21:28:17 +04:00
|
|
|
if (visited.find(&component) != visited.end())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
visited.insert(&component);
|
|
|
|
|
2008-06-17 19:39:26 +04:00
|
|
|
std::vector<cmCPackComponent *>::const_iterator dependIt;
|
|
|
|
for (dependIt = component.ReverseDependencies.begin();
|
|
|
|
dependIt != component.ReverseDependencies.end();
|
|
|
|
++dependIt)
|
|
|
|
{
|
|
|
|
out << " || choices['" << (*dependIt)->Name << "Choice'].selected";
|
2008-07-30 21:28:17 +04:00
|
|
|
AddReverseDependencyAttributes(**dependIt, visited, out);
|
2008-06-17 19:39:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
std::string cmCPackPackageMakerGenerator::EscapeForXML(std::string str)
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(str, "&", "&");
|
|
|
|
cmSystemTools::ReplaceString(str, "<", "<");
|
|
|
|
cmSystemTools::ReplaceString(str, ">", ">");
|
|
|
|
cmSystemTools::ReplaceString(str, "\"", """);
|
|
|
|
return str;
|
|
|
|
}
|