2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2007-01-10 23:30:26 +03:00
|
|
|
#include "cmCPackOSXX11Generator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCPackLog.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2007-01-10 23:30:26 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmake.h"
|
2007-01-10 23:30:26 +03:00
|
|
|
|
|
|
|
#include <cmsys/Glob.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/SystemTools.hxx>
|
2011-05-17 02:15:32 +04:00
|
|
|
#include <sys/stat.h>
|
2007-01-10 23:30:26 +03:00
|
|
|
|
|
|
|
cmCPackOSXX11Generator::cmCPackOSXX11Generator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCPackOSXX11Generator::~cmCPackOSXX11Generator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:48:39 +04:00
|
|
|
int cmCPackOSXX11Generator::PackageFiles()
|
2007-01-10 23:30:26 +03:00
|
|
|
{
|
2010-08-11 21:48:39 +04:00
|
|
|
// TODO: Use toplevel ?
|
|
|
|
// It is used! Is this an obsolete comment?
|
2007-01-10 23:30:26 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cpackPackageExecutables =
|
|
|
|
this->GetOption("CPACK_PACKAGE_EXECUTABLES");
|
|
|
|
if (cpackPackageExecutables) {
|
2007-01-10 23:30:26 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< cpackPackageExecutables << "." << std::endl);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream str;
|
|
|
|
std::ostringstream deleteStr;
|
2007-01-10 23:30:26 +03:00
|
|
|
std::vector<std::string> cpackPackageExecutablesVector;
|
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageExecutables,
|
2016-05-16 17:34:04 +03:00
|
|
|
cpackPackageExecutablesVector);
|
|
|
|
if (cpackPackageExecutablesVector.size() % 2 != 0) {
|
|
|
|
cmCPackLogger(
|
|
|
|
cmCPackLog::LOG_ERROR,
|
2007-01-10 23:30:26 +03:00
|
|
|
"CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
|
2016-05-16 17:34:04 +03:00
|
|
|
"<icon name>."
|
|
|
|
<< std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-01-10 23:30:26 +03:00
|
|
|
std::vector<std::string>::iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = cpackPackageExecutablesVector.begin();
|
|
|
|
it != cpackPackageExecutablesVector.end(); ++it) {
|
2007-01-10 23:30:26 +03:00
|
|
|
std::string cpackExecutableName = *it;
|
2016-05-16 17:34:04 +03:00
|
|
|
++it;
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_EXECUTABLE_NAME",
|
2016-05-16 17:34:04 +03:00
|
|
|
cpackExecutableName.c_str());
|
2007-01-10 23:30:26 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-01-10 23:30:26 +03:00
|
|
|
|
2007-02-13 22:13:51 +03:00
|
|
|
// Disk image directories
|
|
|
|
std::string diskImageDirectory = toplevel;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string diskImageBackgroundImageDir =
|
|
|
|
diskImageDirectory + "/.background";
|
2007-02-13 22:13:51 +03:00
|
|
|
|
|
|
|
// App bundle directories
|
2007-01-10 23:30:26 +03:00
|
|
|
std::string packageDirFileName = toplevel;
|
2007-02-13 22:13:51 +03:00
|
|
|
packageDirFileName += "/";
|
|
|
|
packageDirFileName += this->GetOption("CPACK_PACKAGE_FILE_NAME");
|
2007-01-10 23:30:26 +03:00
|
|
|
packageDirFileName += ".app";
|
|
|
|
std::string contentsDirectory = packageDirFileName + "/Contents";
|
|
|
|
std::string resourcesDirectory = contentsDirectory + "/Resources";
|
|
|
|
std::string appDirectory = contentsDirectory + "/MacOS";
|
2009-01-21 19:54:30 +03:00
|
|
|
std::string scriptDirectory = resourcesDirectory + "/Scripts";
|
|
|
|
std::string resourceFileName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
|
|
|
|
resourceFileName += ".rsrc";
|
2007-01-10 23:30:26 +03:00
|
|
|
|
|
|
|
const char* dir = resourcesDirectory.c_str();
|
|
|
|
const char* appdir = appDirectory.c_str();
|
2009-01-21 19:54:30 +03:00
|
|
|
const char* scrDir = scriptDirectory.c_str();
|
2007-01-10 23:30:26 +03:00
|
|
|
const char* contDir = contentsDirectory.c_str();
|
2009-01-21 19:54:30 +03:00
|
|
|
const char* rsrcFile = resourceFileName.c_str();
|
2007-02-13 22:13:51 +03:00
|
|
|
const char* iconFile = this->GetOption("CPACK_PACKAGE_ICON");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (iconFile) {
|
|
|
|
std::string iconFileName = cmsys::SystemTools::GetFilenameName(iconFile);
|
|
|
|
if (!cmSystemTools::FileExists(iconFile)) {
|
2007-02-13 22:13:51 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find icon file: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< iconFile
|
|
|
|
<< ". Please check CPACK_PACKAGE_ICON setting."
|
|
|
|
<< std::endl);
|
2007-02-13 22:13:51 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-02-13 22:13:51 +03:00
|
|
|
std::string destFileName = resourcesDirectory + "/" + iconFileName;
|
|
|
|
this->ConfigureFile(iconFile, destFileName.c_str(), true);
|
|
|
|
this->SetOptionIfNotSet("CPACK_APPLE_GUI_ICON", iconFileName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-02-13 22:13:51 +03:00
|
|
|
|
|
|
|
std::string applicationsLinkName = diskImageDirectory + "/Applications";
|
2016-09-04 17:55:05 +03:00
|
|
|
cmSystemTools::CreateSymlink("/Applications", applicationsLinkName);
|
2007-02-13 22:13:51 +03:00
|
|
|
|
2016-09-04 17:55:05 +03:00
|
|
|
if (!this->CopyResourcePlistFile("VolumeIcon.icns", diskImageDirectory,
|
2016-05-16 17:34:04 +03:00
|
|
|
".VolumeIcon.icns", true) ||
|
2016-09-04 17:55:05 +03:00
|
|
|
!this->CopyResourcePlistFile("DS_Store", diskImageDirectory, ".DS_Store",
|
|
|
|
true) ||
|
2016-05-16 17:34:04 +03:00
|
|
|
!this->CopyResourcePlistFile("background.png",
|
2016-09-04 17:55:05 +03:00
|
|
|
diskImageBackgroundImageDir,
|
2016-05-16 17:34:04 +03:00
|
|
|
"background.png", true) ||
|
|
|
|
!this->CopyResourcePlistFile("RuntimeScript", dir) ||
|
|
|
|
!this->CopyResourcePlistFile("OSXX11.Info.plist", contDir,
|
|
|
|
"Info.plist") ||
|
|
|
|
!this->CopyResourcePlistFile("OSXX11.main.scpt", scrDir, "main.scpt",
|
|
|
|
true) ||
|
|
|
|
!this->CopyResourcePlistFile("OSXScriptLauncher.rsrc", dir, rsrcFile,
|
|
|
|
true) ||
|
|
|
|
!this->CopyResourcePlistFile("OSXScriptLauncher", appdir,
|
|
|
|
this->GetOption("CPACK_PACKAGE_FILE_NAME"),
|
|
|
|
true)) {
|
2007-01-10 23:30:26 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-01-10 23:30:26 +03:00
|
|
|
|
2011-05-17 02:15:32 +04:00
|
|
|
// Two of the files need to have execute permission, so ensure they do:
|
|
|
|
std::string runTimeScript = dir;
|
|
|
|
runTimeScript += "/";
|
|
|
|
runTimeScript += "RuntimeScript";
|
|
|
|
|
|
|
|
std::string appScriptName = appdir;
|
|
|
|
appScriptName += "/";
|
|
|
|
appScriptName += this->GetOption("CPACK_PACKAGE_FILE_NAME");
|
|
|
|
|
|
|
|
mode_t mode;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmsys::SystemTools::GetPermissions(runTimeScript.c_str(), mode)) {
|
2011-05-17 02:15:32 +04:00
|
|
|
mode |= (S_IXUSR | S_IXGRP | S_IXOTH);
|
|
|
|
cmsys::SystemTools::SetPermissions(runTimeScript.c_str(), mode);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
|
|
|
"Setting: " << runTimeScript << " to permission: " << mode
|
|
|
|
<< std::endl);
|
|
|
|
}
|
2011-05-17 02:15:32 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmsys::SystemTools::GetPermissions(appScriptName.c_str(), mode)) {
|
2011-05-17 02:15:32 +04:00
|
|
|
mode |= (S_IXUSR | S_IXGRP | S_IXOTH);
|
|
|
|
cmsys::SystemTools::SetPermissions(appScriptName.c_str(), mode);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
|
|
|
|
"Setting: " << appScriptName << " to permission: " << mode
|
|
|
|
<< std::endl);
|
|
|
|
}
|
2011-05-17 02:15:32 +04:00
|
|
|
|
2007-01-10 23:30:26 +03:00
|
|
|
std::string output;
|
|
|
|
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
tmpFile += "/hdiutilOutput.log";
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream dmgCmd;
|
2007-01-10 23:30:26 +03:00
|
|
|
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
|
2016-06-07 00:53:32 +03:00
|
|
|
<< "\" create -ov -format UDZO -srcfolder \"" << diskImageDirectory
|
|
|
|
<< "\" \"" << packageFileNames[0] << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress disk image using command: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< dmgCmd.str() << std::endl);
|
2009-10-04 17:32:48 +04:00
|
|
|
// since we get random dashboard failures with this one
|
|
|
|
// try running it more than once
|
2012-03-09 20:39:01 +04:00
|
|
|
int retVal = 1;
|
|
|
|
int numTries = 10;
|
2011-02-03 18:21:32 +03:00
|
|
|
bool res = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (numTries > 0) {
|
|
|
|
res =
|
|
|
|
cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &output,
|
|
|
|
&retVal, 0, this->GeneratorVerbose, 0);
|
|
|
|
if (res && !retVal) {
|
2009-10-04 17:32:48 +04:00
|
|
|
numTries = -1;
|
2012-03-09 20:39:01 +04:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-09 20:39:01 +04:00
|
|
|
cmSystemTools::Delay(500);
|
2009-10-04 17:32:48 +04:00
|
|
|
numTries--;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!res || retVal) {
|
2007-01-10 23:30:26 +03:00
|
|
|
cmGeneratedFileStream ofs(tmpFile.c_str());
|
2016-06-07 00:53:32 +03:00
|
|
|
ofs << "# Run command: " << dmgCmd.str() << std::endl
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "# Output:" << std::endl
|
2016-06-07 00:53:32 +03:00
|
|
|
<< output << std::endl;
|
2007-01-10 23:30:26 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
|
2016-06-07 00:53:32 +03:00
|
|
|
<< dmgCmd.str() << std::endl
|
|
|
|
<< "Please check " << tmpFile << " for errors"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-01-10 23:30:26 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCPackOSXX11Generator::InitializeInternal()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackOSXX11Generator::Initialize()"
|
|
|
|
<< std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
std::vector<std::string> path;
|
|
|
|
std::string pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pkgPath.empty()) {
|
2007-01-10 23:30:26 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
|
2007-01-10 23:30:26 +03:00
|
|
|
pkgPath.c_str());
|
|
|
|
|
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-08 00:02:41 +04:00
|
|
|
bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name)
|
2007-01-10 23:30:26 +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 )
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str()
|
2012-08-13 21:42:58 +04:00
|
|
|
<< " not specified. It should point to "
|
2007-01-10 23:30:26 +03:00
|
|
|
<< (name ? name : "(NULL)")
|
|
|
|
<< ".rtf, " << name
|
|
|
|
<< ".html, or " << name << ".txt file" << std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( !cmSystemTools::FileExists(inFileName) )
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find "
|
2007-01-10 23:30:26 +03:00
|
|
|
<< (name ? name : "(NULL)")
|
|
|
|
<< " resource file: " << inFileName << std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
|
|
|
|
if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: "
|
|
|
|
<< ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed."
|
|
|
|
<< std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
|
|
|
|
destFileName += "/Resources/";
|
|
|
|
destFileName += name + ext;
|
|
|
|
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
|
2007-01-10 23:30:26 +03:00
|
|
|
<< (inFileName ? inFileName : "(NULL)")
|
2016-06-07 00:53:32 +03:00
|
|
|
<< " to " << destFileName << std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
this->ConfigureFile(inFileName, destFileName.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCPackOSXX11Generator::CopyResourcePlistFile(
|
|
|
|
const std::string& name, const std::string& dir,
|
|
|
|
const char* outputFileName /* = 0 */, bool copyOnly /* = false */)
|
2007-01-10 23:30:26 +03:00
|
|
|
{
|
|
|
|
std::string inFName = "CPack.";
|
|
|
|
inFName += name;
|
|
|
|
inFName += ".in";
|
|
|
|
std::string inFileName = this->FindTemplate(inFName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (inFileName.empty()) {
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Cannot find input file: " << inFName << std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-01-10 23:30:26 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!outputFileName) {
|
2014-02-08 00:02:41 +04:00
|
|
|
outputFileName = name.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-01-10 23:30:26 +03:00
|
|
|
|
|
|
|
std::string destFileName = dir;
|
|
|
|
destFileName += "/";
|
|
|
|
destFileName += outputFileName;
|
|
|
|
|
2016-06-07 00:53:32 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
|
|
|
|
<< inFileName << " to " << destFileName << std::endl);
|
2007-01-10 23:30:26 +03:00
|
|
|
this->ConfigureFile(inFileName.c_str(), destFileName.c_str(), copyOnly);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-31 15:50:17 +03:00
|
|
|
const char* cmCPackOSXX11Generator::GetPackagingInstallPrefix()
|
2007-02-13 22:13:51 +03:00
|
|
|
{
|
|
|
|
this->InstallPrefix = "/";
|
|
|
|
this->InstallPrefix += this->GetOption("CPACK_PACKAGE_FILE_NAME");
|
|
|
|
this->InstallPrefix += ".app/Contents/Resources";
|
|
|
|
return this->InstallPrefix.c_str();
|
|
|
|
}
|