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-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2012-07-07 21:54:16 +04:00
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmTarget.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())
|
2015-06-06 15:59:06 +03:00
|
|
|
, LocalGenerator(target->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()
|
|
|
|
{
|
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)
|
|
|
|
{
|
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 += "/";
|
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";
|
2015-10-09 23:31:05 +03:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->GT,
|
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 + "/" +
|
2015-08-04 20:19:48 +03:00
|
|
|
this->GT->GetFrameworkDirectory(this->ConfigName, true);
|
2013-05-06 06:19:05 +04:00
|
|
|
contentdir += "/";
|
|
|
|
|
|
|
|
std::string newoutpath = outpath + "/" +
|
2015-08-04 20:19:48 +03:00
|
|
|
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;
|
2015-11-12 10:44:07 +03:00
|
|
|
if (!this->Makefile->PlatformIsAppleIos())
|
|
|
|
{
|
|
|
|
// Put the Info.plist file into the Resources directory.
|
|
|
|
this->MacContentFolders->insert("Resources");
|
|
|
|
plist += "/Resources";
|
|
|
|
}
|
|
|
|
plist += "/Info.plist";
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string name = cmSystemTools::GetFilenameName(targetName);
|
2015-10-09 23:31:05 +03:00
|
|
|
this->LocalGenerator->GenerateFrameworkInfoPList(this->GT,
|
2014-03-11 03:04:11 +04:00
|
|
|
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
|
|
|
|
if (this->Makefile->PlatformIsAppleIos())
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
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
|
|
|
}
|
|
|
|
}
|
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 += "/";
|
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.
|
2014-03-25 19:16:51 +04:00
|
|
|
std::string plist = root + "/" +
|
2015-08-04 20:19:48 +03:00
|
|
|
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);
|
2015-10-09 23:31:05 +03:00
|
|
|
this->LocalGenerator->GenerateAppleInfoPList(this->GT,
|
2015-02-22 21:00:10 +03:00
|
|
|
name,
|
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 =
|
2015-08-04 20:19:47 +03:00
|
|
|
this->GT->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;
|
|
|
|
}
|