Re-factor CFBundle generation.

This commit is contained in:
Nicolas Despres 2012-07-16 16:00:40 +02:00 committed by Peter Kümmel
parent 03bdaf5453
commit 7bb56c511e
6 changed files with 39 additions and 61 deletions

View File

@ -28,11 +28,7 @@ cmMakefileLibraryTargetGenerator
cmMakefileTargetGenerator(target), cmMakefileTargetGenerator(target),
OSXBundleGenerator(0) OSXBundleGenerator(0)
{ {
if(this->Target->IsCFBundleOnApple()) cmOSXBundleGenerator::PrepareTargetProperties(this->Target);
{
target->SetProperty("PREFIX", "");
target->SetProperty("SUFFIX", "");
}
this->CustomCommandDriver = OnDepends; this->CustomCommandDriver = OnDepends;
this->Target->GetLibraryNames( this->Target->GetLibraryNames(
@ -249,27 +245,6 @@ void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink); this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink);
} }
//----------------------------------------------------------------------------
void
cmMakefileLibraryTargetGenerator::CreateCFBundle(std::string& targetName,
std::string& outpath)
{
// Compute bundle directory names.
outpath = this->MacContentDirectory;
outpath += "MacOS";
cmSystemTools::MakeDirectory(outpath.c_str());
this->Makefile->AddCMakeOutputFile(outpath.c_str());
outpath += "/";
// 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 cmMakefileLibraryTargetGenerator::WriteLibraryRules void cmMakefileLibraryTargetGenerator::WriteLibraryRules
(const char* linkRuleVar, const char* extraFlags, bool relink) (const char* linkRuleVar, const char* extraFlags, bool relink)
@ -328,7 +303,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
{ {
outpath = this->Target->GetDirectory(this->ConfigName); outpath = this->Target->GetDirectory(this->ConfigName);
outpath += "/"; outpath += "/";
this->CreateCFBundle(targetName, outpath); this->OSXBundleGenerator->CreateCFBundle(targetName, outpath);
} }
else if(relink) else if(relink)
{ {

View File

@ -36,7 +36,6 @@ protected:
bool relink); bool relink);
// MacOSX Framework support methods // MacOSX Framework support methods
void WriteFrameworkRules(bool relink); void WriteFrameworkRules(bool relink);
void CreateCFBundle(std::string& targetName, std::string& outpath);
// Store the computd framework version for OS X Frameworks. // Store the computd framework version for OS X Frameworks.
std::string FrameworkVersion; std::string FrameworkVersion;

View File

@ -36,12 +36,7 @@ cmNinjaNormalTargetGenerator(cmTarget* target)
, TargetNamePDB() , TargetNamePDB()
, TargetLinkLanguage(0) , TargetLinkLanguage(0)
{ {
// TODO: Re-factor with cmMakefileLibraryTargetGenerator's constructor. cmOSXBundleGenerator::PrepareTargetProperties(target);
if(target->IsCFBundleOnApple())
{
target->SetProperty("PREFIX", "");
target->SetProperty("SUFFIX", "");
}
this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName()); this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
if (target->GetType() == cmTarget::EXECUTABLE) if (target->GetType() == cmTarget::EXECUTABLE)
@ -383,13 +378,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Create the library framework. // Create the library framework.
this->OSXBundleGenerator->CreateFramework(this->TargetNameOut); this->OSXBundleGenerator->CreateFramework(this->TargetNameOut);
} }
// TODO: Re-factor with cmMakefileLibraryTargetGenerator::WriteLibraryRules.
else if(this->GetTarget()->IsCFBundleOnApple()) else if(this->GetTarget()->IsCFBundleOnApple())
{ {
// Create the core foundation bundle.
std::string outpath; std::string outpath;
outpath = this->GetTarget()->GetDirectory(this->GetConfigName()); this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut, outpath);
outpath += "/";
this->CreateCFBundle(this->TargetNameOut, outpath);
} }
// Write comments. // Write comments.
@ -617,25 +610,3 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
this->GetTarget()); this->GetTarget());
} }
//----------------------------------------------------------------------------
// TODO: Re-factor with cmMakefileLibraryTargetGenerator::CreateCFBundle.
void cmNinjaNormalTargetGenerator::CreateCFBundle(std::string& targetName,
std::string& outpath)
{
// Compute bundle directory names.
outpath = this->OSXBundleGenerator->GetMacContentDirectory();
outpath += "MacOS";
cmSystemTools::MakeDirectory(outpath.c_str());
this->GetMakefile()->AddCMakeOutputFile(outpath.c_str());
outpath += "/";
// Configure the Info.plist file. Note that it needs the executable name
// to be set.
std::string plist = this->OSXBundleGenerator->GetMacContentDirectory();
plist += "Info.plist";
this->GetLocalGenerator()->GenerateAppleInfoPList(this->GetTarget(),
targetName.c_str(),
plist.c_str());
this->GetMakefile()->AddCMakeOutputFile(plist.c_str());
}

View File

@ -38,7 +38,6 @@ private:
void WriteLinkStatement(); void WriteLinkStatement();
void WriteObjectLibStatement(); void WriteObjectLibStatement();
std::vector<std::string> ComputeLinkCmd(); std::vector<std::string> ComputeLinkCmd();
void CreateCFBundle(std::string& targetName, std::string& outpath);
private: private:
// Target name info. // Target name info.

View File

@ -16,6 +16,16 @@
#include <cassert> #include <cassert>
void cmOSXBundleGenerator::PrepareTargetProperties(cmTarget* target)
{
if(target->IsCFBundleOnApple())
{
target->SetProperty("PREFIX", "");
target->SetProperty("SUFFIX", "");
}
}
//----------------------------------------------------------------------------
cmOSXBundleGenerator:: cmOSXBundleGenerator::
cmOSXBundleGenerator(cmTarget* target, cmOSXBundleGenerator(cmTarget* target,
std::string targetNameOut, std::string targetNameOut,
@ -169,3 +179,24 @@ void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
this->Makefile->AddCMakeOutputFile(newName.c_str()); this->Makefile->AddCMakeOutputFile(newName.c_str());
} }
} }
//----------------------------------------------------------------------------
void cmOSXBundleGenerator::CreateCFBundle(std::string& targetName,
std::string& outpath)
{
// Compute bundle directory names.
outpath = this->MacContentDirectory;
outpath += "MacOS";
cmSystemTools::MakeDirectory(outpath.c_str());
this->Makefile->AddCMakeOutputFile(outpath.c_str());
outpath += "/";
// 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());
}

View File

@ -24,12 +24,15 @@ class cmLocalGenerator;
class cmOSXBundleGenerator class cmOSXBundleGenerator
{ {
public: public:
static void PrepareTargetProperties(cmTarget* target);
cmOSXBundleGenerator(cmTarget* target, cmOSXBundleGenerator(cmTarget* target,
std::string targetNameOut, std::string targetNameOut,
const char* configName); const char* configName);
void CreateAppBundle(std::string& targetName, std::string& outpath); void CreateAppBundle(std::string& targetName, std::string& outpath);
void CreateFramework(std::string const& targetName); void CreateFramework(std::string const& targetName);
void CreateCFBundle(std::string& targetName, std::string& outpath);
std::string GetMacContentDirectory() const std::string GetMacContentDirectory() const
{ return this->MacContentDirectory; } { return this->MacContentDirectory; }