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,
|
2012-07-07 21:54:16 +04:00
|
|
|
const char* configName)
|
2012-10-10 23:32:37 +04:00
|
|
|
: Target(target->Target)
|
|
|
|
, 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()
|
|
|
|
{
|
|
|
|
return !this->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 += "/";
|
|
|
|
out += this->Target->GetAppBundleDirectory(this->ConfigName, false);
|
|
|
|
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 += "/";
|
|
|
|
plist += this->Target->GetAppBundleDirectory(this->ConfigName, true);
|
|
|
|
plist += "/Info.plist";
|
2012-07-07 21:54:16 +04:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->Target,
|
|
|
|
targetName.c_str(),
|
|
|
|
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 + "/" +
|
|
|
|
this->Target->GetFrameworkDirectory(this->ConfigName, true);
|
|
|
|
contentdir += "/";
|
|
|
|
|
|
|
|
std::string newoutpath = outpath + "/" +
|
|
|
|
this->Target->GetFrameworkDirectory(this->ConfigName, false);
|
|
|
|
|
|
|
|
std::string frameworkVersion = this->Target->GetFrameworkVersion();
|
|
|
|
|
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);
|
2012-07-07 21:54:16 +04:00
|
|
|
this->LocalGenerator->GenerateFrameworkInfoPList(this->Target,
|
2013-05-06 06:19:05 +04:00
|
|
|
name.c_str(),
|
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";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
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;
|
2012-07-07 21:54:16 +04:00
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
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";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
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";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
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";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
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 += "/";
|
2013-06-02 08:47:18 +04:00
|
|
|
out += this->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 + "/" +
|
2013-06-02 08:47:18 +04:00
|
|
|
this->Target->GetCFBundleDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
plist += "/Info.plist";
|
2012-07-16 18:00:40 +04:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->Target,
|
|
|
|
targetName.c_str(),
|
|
|
|
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::
|
|
|
|
GenerateMacOSXContentStatements(std::vector<cmSourceFile*> const& sources,
|
|
|
|
MacOSXContentGeneratorType* generator)
|
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
2012-07-16 19:34:22 +04:00
|
|
|
for(std::vector<cmSourceFile*>::const_iterator
|
|
|
|
si = sources.begin(); si != sources.end(); ++si)
|
|
|
|
{
|
|
|
|
cmTarget::SourceFileFlags tsFlags =
|
|
|
|
this->Target->GetTargetSourceFileFlags(*si);
|
|
|
|
if(tsFlags.Type != cmTarget::SourceFileTypeNormal)
|
|
|
|
{
|
|
|
|
(*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 =
|
|
|
|
this->Target->GetMacContentDirectory(this->ConfigName,
|
|
|
|
/*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;
|
|
|
|
}
|