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"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmTarget.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2012-07-16 18:00:40 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2012-07-07 21:54:16 +04:00
|
|
|
cmOSXBundleGenerator::
|
2012-10-10 23:32:37 +04:00
|
|
|
cmOSXBundleGenerator(cmGeneratorTarget* target,
|
2014-02-10 07:48:34 +04:00
|
|
|
const std::string& configName)
|
2014-02-06 14:24:37 +04:00
|
|
|
: GT(target)
|
2012-10-10 23:32:37 +04:00
|
|
|
, Makefile(target->Target->GetMakefile())
|
2012-07-18 15:11:27 +04:00
|
|
|
, LocalGenerator(Makefile->GetLocalGenerator())
|
2012-07-07 21:54:16 +04:00
|
|
|
, ConfigName(configName)
|
|
|
|
, MacContentFolders(0)
|
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmOSXBundleGenerator::MustSkip()
|
|
|
|
{
|
2014-02-06 14:24:37 +04:00
|
|
|
return !this->GT->Target->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)
|
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
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 += "/";
|
2014-02-06 14:24:37 +04:00
|
|
|
out += this->GT->Target->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 += "/";
|
2014-02-06 14:24:37 +04:00
|
|
|
plist += this->GT->Target->GetAppBundleDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
plist += "/Info.plist";
|
2014-02-06 14:24:37 +04:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->GT->Target,
|
2014-03-11 03:04:11 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2013-05-06 06:19:05 +04:00
|
|
|
void cmOSXBundleGenerator::CreateFramework(
|
|
|
|
const std::string& targetName, const std::string& outpath)
|
2012-07-07 21:54:16 +04:00
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
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.
|
|
|
|
std::string contentdir = outpath + "/" +
|
2014-02-06 14:24:37 +04:00
|
|
|
this->GT->Target->GetFrameworkDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
contentdir += "/";
|
|
|
|
|
|
|
|
std::string newoutpath = outpath + "/" +
|
2014-02-06 14:24:37 +04:00
|
|
|
this->GT->Target->GetFrameworkDirectory(this->ConfigName, false);
|
2013-05-06 06:19:05 +04:00
|
|
|
|
2014-02-06 14:24:37 +04:00
|
|
|
std::string frameworkVersion = this->GT->Target->GetFrameworkVersion();
|
2013-05-06 06:19:05 +04:00
|
|
|
|
2012-07-07 21:54:16 +04:00
|
|
|
// Configure the Info.plist file into the Resources directory.
|
|
|
|
this->MacContentFolders->insert("Resources");
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string plist = newoutpath;
|
|
|
|
plist += "/Resources/Info.plist";
|
|
|
|
std::string name = cmSystemTools::GetFilenameName(targetName);
|
2014-02-06 14:24:37 +04:00
|
|
|
this->LocalGenerator->GenerateFrameworkInfoPList(this->GT->Target,
|
2014-03-11 03:04:11 +04:00
|
|
|
name,
|
2012-07-07 21:54:16 +04:00
|
|
|
plist.c_str());
|
|
|
|
|
|
|
|
// 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);
|
2012-07-07 21:54:16 +04:00
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
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);
|
2012-07-07 21:54:16 +04:00
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// Resources -> Versions/Current/Resources
|
|
|
|
if(this->MacContentFolders->find("Resources") !=
|
|
|
|
this->MacContentFolders->end())
|
|
|
|
{
|
|
|
|
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);
|
2012-07-07 21:54:16 +04:00
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2012-07-07 21:54:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Headers -> Versions/Current/Headers
|
|
|
|
if(this->MacContentFolders->find("Headers") !=
|
|
|
|
this->MacContentFolders->end())
|
|
|
|
{
|
|
|
|
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);
|
2012-07-07 21:54:16 +04:00
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
2012-07-07 21:54:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// PrivateHeaders -> Versions/Current/PrivateHeaders
|
|
|
|
if(this->MacContentFolders->find("PrivateHeaders") !=
|
|
|
|
this->MacContentFolders->end())
|
|
|
|
{
|
|
|
|
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);
|
2012-07-07 21:54:16 +04:00
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
2013-06-18 21:41:50 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(newName);
|
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
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
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 += "/";
|
2014-02-06 14:24:37 +04:00
|
|
|
out += this->GT->Target->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.
|
2014-03-25 19:16:51 +04:00
|
|
|
std::string plist = root + "/" +
|
2014-02-06 14:24:37 +04:00
|
|
|
this->GT->Target->GetCFBundleDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
plist += "/Info.plist";
|
2014-02-06 14:24:37 +04:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->GT->Target,
|
2014-03-11 03:04:11 +04:00
|
|
|
targetName,
|
2012-07-16 18:00:40 +04:00
|
|
|
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
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmOSXBundleGenerator::
|
2014-03-13 02:06:05 +04:00
|
|
|
GenerateMacOSXContentStatements(
|
|
|
|
std::vector<cmSourceFile const*> const& sources,
|
|
|
|
MacOSXContentGeneratorType* generator)
|
2012-07-16 19:34:22 +04:00
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
2014-03-13 02:06:05 +04:00
|
|
|
for(std::vector<cmSourceFile const*>::const_iterator
|
2012-07-16 19:34:22 +04:00
|
|
|
si = sources.begin(); si != sources.end(); ++si)
|
|
|
|
{
|
2014-02-06 14:24:37 +04:00
|
|
|
cmGeneratorTarget::SourceFileFlags tsFlags =
|
|
|
|
this->GT->GetTargetSourceFileFlags(*si);
|
|
|
|
if(tsFlags.Type != cmGeneratorTarget::SourceFileTypeNormal)
|
2012-07-16 19:34:22 +04:00
|
|
|
{
|
|
|
|
(*generator)(**si, tsFlags.MacFolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-17 01:03:40 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string
|
|
|
|
cmOSXBundleGenerator::InitMacOSXContentDirectory(const char* pkgloc)
|
|
|
|
{
|
|
|
|
// Construct the full path to the content subdirectory.
|
2013-05-06 06:19:05 +04:00
|
|
|
|
|
|
|
std::string macdir =
|
2014-02-06 14:24:37 +04:00
|
|
|
this->GT->Target->GetMacContentDirectory(this->ConfigName,
|
2013-05-06 06:19:05 +04:00
|
|
|
/*implib*/ false);
|
|
|
|
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.
|
|
|
|
{
|
|
|
|
std::string loc = pkgloc;
|
|
|
|
loc = loc.substr(0, loc.find('/'));
|
|
|
|
this->MacContentFolders->insert(loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return macdir;
|
|
|
|
}
|