2012-07-07 21:54:16 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2012 Nicolas Despres <nicolas.despres@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmOSXBundleGenerator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <cmConfigure.h>
|
|
|
|
|
|
|
|
#include "cmGeneratorTarget.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2012-07-07 21:54:16 +04:00
|
|
|
#include "cmMakefile.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmSystemTools.h"
|
2012-07-07 21:54:16 +04:00
|
|
|
#include "cmTarget.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
class cmSourceFile;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmOSXBundleGenerator::cmOSXBundleGenerator(cmGeneratorTarget* target,
|
|
|
|
const std::string& configName)
|
|
|
|
: GT(target)
|
|
|
|
, Makefile(target->Target->GetMakefile())
|
|
|
|
, LocalGenerator(target->GetLocalGenerator())
|
|
|
|
, ConfigName(configName)
|
2016-06-27 23:44:16 +03:00
|
|
|
, MacContentFolders(CM_NULLPTR)
|
2012-07-07 21:54:16 +04:00
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->MustSkip()) {
|
2012-07-16 21:42:56 +04:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-07-16 21:42:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmOSXBundleGenerator::MustSkip()
|
|
|
|
{
|
2015-10-20 01:42:01 +03:00
|
|
|
return !this->GT->HaveWellDefinedOutputFiles();
|
2012-07-07 21:54:16 +04:00
|
|
|
}
|
|
|
|
|
2013-05-06 06:19:05 +04:00
|
|
|
void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName,
|
2012-07-07 21:54:16 +04:00
|
|
|
std::string& outpath)
|
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->MustSkip()) {
|
2012-07-16 21:42:56 +04:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-07-16 21:42:56 +04:00
|
|
|
|
2012-07-07 21:54:16 +04:00
|
|
|
// Compute bundle directory names.
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string out = outpath;
|
|
|
|
out += "/";
|
2015-08-04 20:19:48 +03:00
|
|
|
out += this->GT->GetAppBundleDirectory(this->ConfigName, false);
|
2013-05-06 06:19:05 +04:00
|
|
|
cmSystemTools::MakeDirectory(out.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(out);
|
2013-05-06 06:19:05 +04:00
|
|
|
|
|
|
|
std::string newoutpath = out;
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// Configure the Info.plist file. Note that it needs the executable name
|
|
|
|
// to be set.
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string plist = outpath;
|
|
|
|
plist += "/";
|
2015-08-04 20:19:48 +03:00
|
|
|
plist += this->GT->GetAppBundleDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
plist += "/Info.plist";
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->GT, targetName,
|
2012-07-07 21:54:16 +04:00
|
|
|
plist.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(plist);
|
2013-05-06 06:19:05 +04:00
|
|
|
outpath = newoutpath;
|
2012-07-07 21:54:16 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmOSXBundleGenerator::CreateFramework(const std::string& targetName,
|
|
|
|
const std::string& outpath)
|
2012-07-07 21:54:16 +04:00
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->MustSkip()) {
|
2012-07-16 21:42:56 +04:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-07-16 21:42:56 +04:00
|
|
|
|
2012-07-07 21:54:16 +04:00
|
|
|
assert(this->MacContentFolders);
|
|
|
|
|
2013-05-06 06:19:05 +04:00
|
|
|
// Compute the location of the top-level foo.framework directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string contentdir =
|
|
|
|
outpath + "/" + this->GT->GetFrameworkDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
contentdir += "/";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string newoutpath =
|
|
|
|
outpath + "/" + this->GT->GetFrameworkDirectory(this->ConfigName, false);
|
2013-05-06 06:19:05 +04:00
|
|
|
|
2015-10-23 01:47:31 +03:00
|
|
|
std::string frameworkVersion = this->GT->GetFrameworkVersion();
|
2013-05-06 06:19:05 +04:00
|
|
|
|
2015-11-12 10:44:07 +03:00
|
|
|
// Configure the Info.plist file
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string plist = newoutpath;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->PlatformIsAppleIos()) {
|
2015-11-12 10:44:07 +03:00
|
|
|
// Put the Info.plist file into the Resources directory.
|
|
|
|
this->MacContentFolders->insert("Resources");
|
|
|
|
plist += "/Resources";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-11-12 10:44:07 +03:00
|
|
|
plist += "/Info.plist";
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string name = cmSystemTools::GetFilenameName(targetName);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->GenerateFrameworkInfoPList(this->GT, name,
|
2012-07-07 21:54:16 +04:00
|
|
|
plist.c_str());
|
|
|
|
|
2015-11-12 10:44:07 +03:00
|
|
|
// Generate Versions directory only for MacOSX frameworks
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->Makefile->PlatformIsAppleIos()) {
|
2015-11-12 10:44:07 +03:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2015-11-12 10:44:07 +03:00
|
|
|
|
2012-07-07 21:54:16 +04:00
|
|
|
// TODO: Use the cmMakefileTargetGenerator::ExtraFiles vector to
|
|
|
|
// drive rules to create these files at build time.
|
|
|
|
std::string oldName;
|
|
|
|
std::string newName;
|
|
|
|
|
|
|
|
// Make foo.framework/Versions
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string versions = contentdir;
|
2012-07-07 21:54:16 +04:00
|
|
|
versions += "Versions";
|
|
|
|
cmSystemTools::MakeDirectory(versions.c_str());
|
|
|
|
|
|
|
|
// Make foo.framework/Versions/version
|
2013-05-06 06:19:05 +04:00
|
|
|
cmSystemTools::MakeDirectory(newoutpath.c_str());
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// Current -> version
|
2013-05-06 06:19:05 +04:00
|
|
|
oldName = frameworkVersion;
|
2012-07-07 21:54:16 +04:00
|
|
|
newName = versions;
|
|
|
|
newName += "/Current";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(newName);
|
2014-11-23 13:05:50 +03:00
|
|
|
cmSystemTools::CreateSymlink(oldName, newName);
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// foo -> Versions/Current/foo
|
|
|
|
oldName = "Versions/Current/";
|
2013-05-06 06:19:05 +04:00
|
|
|
oldName += name;
|
|
|
|
newName = contentdir;
|
|
|
|
newName += name;
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(newName);
|
2014-11-23 13:05:50 +03:00
|
|
|
cmSystemTools::CreateSymlink(oldName, newName);
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// Resources -> Versions/Current/Resources
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MacContentFolders->find("Resources") !=
|
|
|
|
this->MacContentFolders->end()) {
|
2012-07-07 21:54:16 +04:00
|
|
|
oldName = "Versions/Current/Resources";
|
2013-05-06 06:19:05 +04:00
|
|
|
newName = contentdir;
|
2012-07-07 21:54:16 +04:00
|
|
|
newName += "Resources";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(newName);
|
2014-11-23 13:05:50 +03:00
|
|
|
cmSystemTools::CreateSymlink(oldName, newName);
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// Headers -> Versions/Current/Headers
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MacContentFolders->find("Headers") !=
|
|
|
|
this->MacContentFolders->end()) {
|
2012-07-07 21:54:16 +04:00
|
|
|
oldName = "Versions/Current/Headers";
|
2013-05-06 06:19:05 +04:00
|
|
|
newName = contentdir;
|
2012-07-07 21:54:16 +04:00
|
|
|
newName += "Headers";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(newName);
|
2014-11-23 13:05:50 +03:00
|
|
|
cmSystemTools::CreateSymlink(oldName, newName);
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// PrivateHeaders -> Versions/Current/PrivateHeaders
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MacContentFolders->find("PrivateHeaders") !=
|
|
|
|
this->MacContentFolders->end()) {
|
2012-07-07 21:54:16 +04:00
|
|
|
oldName = "Versions/Current/PrivateHeaders";
|
2013-05-06 06:19:05 +04:00
|
|
|
newName = contentdir;
|
2012-07-07 21:54:16 +04:00
|
|
|
newName += "PrivateHeaders";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(newName);
|
2014-11-23 13:05:50 +03:00
|
|
|
cmSystemTools::CreateSymlink(oldName, newName);
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-07 21:54:16 +04:00
|
|
|
}
|
2012-07-16 18:00:40 +04:00
|
|
|
|
2013-05-06 06:19:05 +04:00
|
|
|
void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
|
2013-06-02 08:47:18 +04:00
|
|
|
const std::string& root)
|
2012-07-16 18:00:40 +04:00
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->MustSkip()) {
|
2012-07-16 21:42:56 +04:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-07-16 21:42:56 +04:00
|
|
|
|
2012-07-16 18:00:40 +04:00
|
|
|
// Compute bundle directory names.
|
2013-06-02 08:47:18 +04:00
|
|
|
std::string out = root;
|
2013-05-06 06:19:05 +04:00
|
|
|
out += "/";
|
2015-08-04 20:19:48 +03:00
|
|
|
out += this->GT->GetCFBundleDirectory(this->ConfigName, false);
|
2013-05-06 06:19:05 +04:00
|
|
|
cmSystemTools::MakeDirectory(out.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(out);
|
2013-05-06 06:19:05 +04:00
|
|
|
|
2012-07-16 18:00:40 +04:00
|
|
|
// Configure the Info.plist file. Note that it needs the executable name
|
|
|
|
// to be set.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string plist =
|
|
|
|
root + "/" + this->GT->GetCFBundleDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
plist += "/Info.plist";
|
2015-02-22 21:00:10 +03:00
|
|
|
std::string name = cmSystemTools::GetFilenameName(targetName);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->GT, name, plist.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(plist);
|
2012-07-16 18:00:40 +04:00
|
|
|
}
|
2012-07-16 19:34:22 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmOSXBundleGenerator::GenerateMacOSXContentStatements(
|
|
|
|
std::vector<cmSourceFile const*> const& sources,
|
|
|
|
MacOSXContentGeneratorType* generator)
|
2012-07-16 19:34:22 +04:00
|
|
|
{
|
2016-06-10 19:36:24 +03:00
|
|
|
if (this->MustSkip()) {
|
2012-07-16 21:42:56 +04:00
|
|
|
return;
|
2016-06-10 19:36:24 +03:00
|
|
|
}
|
2012-07-16 21:42:56 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile const*>::const_iterator si = sources.begin();
|
|
|
|
si != sources.end(); ++si) {
|
2014-02-06 14:24:37 +04:00
|
|
|
cmGeneratorTarget::SourceFileFlags tsFlags =
|
|
|
|
this->GT->GetTargetSourceFileFlags(*si);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tsFlags.Type != cmGeneratorTarget::SourceFileTypeNormal) {
|
2012-07-16 19:34:22 +04:00
|
|
|
(*generator)(**si, tsFlags.MacFolder);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-16 19:34:22 +04:00
|
|
|
}
|
2012-07-17 01:03:40 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmOSXBundleGenerator::InitMacOSXContentDirectory(
|
|
|
|
const char* pkgloc)
|
2012-07-17 01:03:40 +04:00
|
|
|
{
|
|
|
|
// Construct the full path to the content subdirectory.
|
2013-05-06 06:19:05 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string macdir = this->GT->GetMacContentDirectory(this->ConfigName,
|
|
|
|
/*implib*/ false);
|
2013-05-06 06:19:05 +04:00
|
|
|
macdir += "/";
|
2012-07-17 01:03:40 +04:00
|
|
|
macdir += pkgloc;
|
|
|
|
cmSystemTools::MakeDirectory(macdir.c_str());
|
|
|
|
|
|
|
|
// Record use of this content location. Only the first level
|
|
|
|
// directory is needed.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string loc = pkgloc;
|
|
|
|
loc = loc.substr(0, loc.find('/'));
|
|
|
|
this->MacContentFolders->insert(loc);
|
2012-07-17 01:03:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return macdir;
|
|
|
|
}
|