Ninja: Add support for CFBundle.

This patch fixes test CFBundleTest on Darwin.
This commit is contained in:
Nicolas Despres 2012-07-11 11:19:25 +02:00 committed by Peter Kümmel
parent 10686a17f4
commit 54d9713adb
3 changed files with 51 additions and 0 deletions

View File

@ -36,6 +36,13 @@ cmNinjaNormalTargetGenerator(cmTarget* target)
, TargetNamePDB() , TargetNamePDB()
, TargetLinkLanguage(0) , TargetLinkLanguage(0)
{ {
// TODO: Re-factor with cmMakefileLibraryTargetGenerator's constructor.
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)
target->GetExecutableNames(this->TargetNameOut, target->GetExecutableNames(this->TargetNameOut,
@ -376,6 +383,14 @@ 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())
{
std::string outpath;
outpath = this->GetTarget()->GetDirectory(this->GetConfigName());
outpath += "/";
this->CreateCFBundle(this->TargetNameOut, outpath);
}
// Write comments. // Write comments.
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream()); cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
@ -602,3 +617,25 @@ 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,6 +38,7 @@ 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

@ -3169,6 +3169,7 @@ std::string cmTarget::GetFullPath(const char* config, bool implib,
std::string cmTarget::NormalGetFullPath(const char* config, bool implib, std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
bool realname) bool realname)
{ {
// TODO: Re-factor with cmOSXBundleGenerator's constructor.
// Start with the output directory for the target. // Start with the output directory for the target.
std::string fpath = this->GetDirectory(config, implib); std::string fpath = this->GetDirectory(config, implib);
fpath += "/"; fpath += "/";
@ -3185,6 +3186,18 @@ std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
fpath += this->GetFrameworkVersion(); fpath += this->GetFrameworkVersion();
fpath += "/"; fpath += "/";
} }
if(this->IsCFBundleOnApple())
{
fpath += this->GetFullName(config, false);
fpath += ".";
const char *ext = this->GetProperty("BUNDLE_EXTENSION");
if (!ext)
{
ext = "bundle";
}
fpath += ext;
fpath += "/Contents/MacOS/";
}
// Add the full name of the target. // Add the full name of the target.
if(implib) if(implib)