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
|
|
|
void cmOSXBundleGenerator::PrepareTargetProperties(cmTarget* target)
|
|
|
|
{
|
|
|
|
if(target->IsCFBundleOnApple())
|
|
|
|
{
|
|
|
|
target->SetProperty("PREFIX", "");
|
|
|
|
target->SetProperty("SUFFIX", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-07-07 21:54:16 +04:00
|
|
|
cmOSXBundleGenerator::
|
|
|
|
cmOSXBundleGenerator(cmTarget* target,
|
|
|
|
std::string targetNameOut,
|
|
|
|
const char* configName)
|
|
|
|
: Target(target)
|
|
|
|
, Makefile(target->GetMakefile())
|
|
|
|
, LocalGenerator(this->Makefile->GetLocalGenerator())
|
|
|
|
, TargetNameOut(targetNameOut)
|
|
|
|
, ConfigName(configName)
|
|
|
|
, MacContentDirectory()
|
|
|
|
, FrameworkVersion()
|
|
|
|
, MacContentFolders(0)
|
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
|
|
|
this->MacContentDirectory =
|
|
|
|
this->Target->GetMacContentDirectory(this->ConfigName,
|
|
|
|
/*implib*/ false,
|
|
|
|
/*includeMacOS*/ false);
|
|
|
|
if(this->Target->IsFrameworkOnApple())
|
2012-07-07 21:54:16 +04:00
|
|
|
this->FrameworkVersion = this->Target->GetFrameworkVersion();
|
2012-07-16 21:42:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmOSXBundleGenerator::MustSkip()
|
|
|
|
{
|
|
|
|
return !this->Target->HaveWellDefinedOutputFiles();
|
2012-07-07 21:54:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmOSXBundleGenerator::CreateAppBundle(std::string& targetName,
|
|
|
|
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.
|
|
|
|
outpath = this->MacContentDirectory;
|
|
|
|
outpath += "MacOS";
|
|
|
|
cmSystemTools::MakeDirectory(outpath.c_str());
|
|
|
|
outpath += "/";
|
2012-07-16 21:42:56 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(outpath.c_str());
|
2012-07-07 21:54:16 +04:00
|
|
|
|
|
|
|
// Configure the Info.plist file. Note that it needs the executable name
|
|
|
|
// to be set.
|
|
|
|
std::string plist = this->MacContentDirectory + "Info.plist";
|
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->Target,
|
|
|
|
targetName.c_str(),
|
|
|
|
plist.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(plist.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
|
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
2012-07-07 21:54:16 +04:00
|
|
|
assert(this->MacContentFolders);
|
|
|
|
|
|
|
|
// Configure the Info.plist file into the Resources directory.
|
|
|
|
this->MacContentFolders->insert("Resources");
|
|
|
|
std::string plist = this->MacContentDirectory + "Resources/Info.plist";
|
|
|
|
this->LocalGenerator->GenerateFrameworkInfoPList(this->Target,
|
|
|
|
targetName.c_str(),
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Compute the location of the top-level foo.framework directory.
|
|
|
|
std::string top = this->Target->GetDirectory(this->ConfigName);
|
|
|
|
top += "/";
|
|
|
|
top += this->TargetNameOut;
|
|
|
|
top += ".framework/";
|
|
|
|
|
|
|
|
// Make foo.framework/Versions
|
|
|
|
std::string versions = top;
|
|
|
|
versions += "Versions";
|
|
|
|
cmSystemTools::MakeDirectory(versions.c_str());
|
|
|
|
|
|
|
|
// Make foo.framework/Versions/version
|
|
|
|
std::string version = versions;
|
|
|
|
version += "/";
|
|
|
|
version += this->FrameworkVersion;
|
|
|
|
cmSystemTools::MakeDirectory(version.c_str());
|
|
|
|
|
|
|
|
// Current -> version
|
|
|
|
oldName = this->FrameworkVersion;
|
|
|
|
newName = versions;
|
|
|
|
newName += "/Current";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(newName.c_str());
|
|
|
|
|
|
|
|
// foo -> Versions/Current/foo
|
|
|
|
oldName = "Versions/Current/";
|
|
|
|
oldName += this->TargetNameOut;
|
|
|
|
newName = top;
|
|
|
|
newName += this->TargetNameOut;
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(newName.c_str());
|
|
|
|
|
|
|
|
// Resources -> Versions/Current/Resources
|
|
|
|
if(this->MacContentFolders->find("Resources") !=
|
|
|
|
this->MacContentFolders->end())
|
|
|
|
{
|
|
|
|
oldName = "Versions/Current/Resources";
|
|
|
|
newName = top;
|
|
|
|
newName += "Resources";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(newName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Headers -> Versions/Current/Headers
|
|
|
|
if(this->MacContentFolders->find("Headers") !=
|
|
|
|
this->MacContentFolders->end())
|
|
|
|
{
|
|
|
|
oldName = "Versions/Current/Headers";
|
|
|
|
newName = top;
|
|
|
|
newName += "Headers";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(newName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrivateHeaders -> Versions/Current/PrivateHeaders
|
|
|
|
if(this->MacContentFolders->find("PrivateHeaders") !=
|
|
|
|
this->MacContentFolders->end())
|
|
|
|
{
|
|
|
|
oldName = "Versions/Current/PrivateHeaders";
|
|
|
|
newName = top;
|
|
|
|
newName += "PrivateHeaders";
|
|
|
|
cmSystemTools::RemoveFile(newName.c_str());
|
|
|
|
cmSystemTools::CreateSymlink(oldName.c_str(), newName.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(newName.c_str());
|
|
|
|
}
|
|
|
|
}
|
2012-07-16 18:00:40 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmOSXBundleGenerator::CreateCFBundle(std::string& targetName,
|
|
|
|
std::string& outpath)
|
|
|
|
{
|
2012-07-16 21:42:56 +04:00
|
|
|
if (this->MustSkip())
|
|
|
|
return;
|
|
|
|
|
2012-07-16 18:00:40 +04:00
|
|
|
// Compute bundle directory names.
|
|
|
|
outpath = this->MacContentDirectory;
|
|
|
|
outpath += "MacOS";
|
|
|
|
cmSystemTools::MakeDirectory(outpath.c_str());
|
|
|
|
outpath += "/";
|
2012-07-16 21:42:56 +04:00
|
|
|
this->Makefile->AddCMakeOutputFile(outpath.c_str());
|
2012-07-16 18:00:40 +04:00
|
|
|
|
|
|
|
// Configure the Info.plist file. Note that it needs the executable name
|
|
|
|
// to be set.
|
|
|
|
std::string plist = this->MacContentDirectory;
|
|
|
|
plist += "Info.plist";
|
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->Target,
|
|
|
|
targetName.c_str(),
|
|
|
|
plist.c_str());
|
|
|
|
this->Makefile->AddCMakeOutputFile(plist.c_str());
|
|
|
|
}
|
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.
|
|
|
|
std::string macdir = this->MacContentDirectory;
|
|
|
|
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;
|
|
|
|
}
|