Commit f36c7b0b authored by Nicolas Despres's avatar Nicolas Despres Committed by Peter Kümmel

Re-factor Mac OS X content directory computation.

parent 5d885db4
......@@ -39,49 +39,36 @@ cmOSXBundleGenerator(cmTarget* target,
, FrameworkVersion()
, MacContentFolders(0)
{
if(this->Target->IsAppBundleOnApple())
{
this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
this->MacContentDirectory += "/";
this->MacContentDirectory += this->TargetNameOut;
this->MacContentDirectory += ".app/Contents/";
}
else if(this->Target->IsFrameworkOnApple())
{
if (this->MustSkip())
return;
this->MacContentDirectory =
this->Target->GetMacContentDirectory(this->ConfigName,
/*implib*/ false,
/*includeMacOS*/ false);
if(this->Target->IsFrameworkOnApple())
this->FrameworkVersion = this->Target->GetFrameworkVersion();
this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
this->MacContentDirectory += "/";
this->MacContentDirectory += this->TargetNameOut;
this->MacContentDirectory += ".framework/Versions/";
this->MacContentDirectory += this->FrameworkVersion;
this->MacContentDirectory += "/";
}
else if(this->Target->IsCFBundleOnApple())
{
this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
this->MacContentDirectory += "/";
this->MacContentDirectory += this->TargetNameOut;
this->MacContentDirectory += ".";
const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
if (!ext)
{
ext = "bundle";
}
this->MacContentDirectory += ext;
this->MacContentDirectory += "/Contents/";
}
}
//----------------------------------------------------------------------------
bool cmOSXBundleGenerator::MustSkip()
{
return !this->Target->HaveWellDefinedOutputFiles();
}
//----------------------------------------------------------------------------
void cmOSXBundleGenerator::CreateAppBundle(std::string& targetName,
std::string& outpath)
{
if (this->MustSkip())
return;
// Compute bundle directory names.
outpath = this->MacContentDirectory;
outpath += "MacOS";
cmSystemTools::MakeDirectory(outpath.c_str());
this->Makefile->AddCMakeOutputFile(outpath.c_str());
outpath += "/";
this->Makefile->AddCMakeOutputFile(outpath.c_str());
// Configure the Info.plist file. Note that it needs the executable name
// to be set.
......@@ -95,6 +82,9 @@ void cmOSXBundleGenerator::CreateAppBundle(std::string& targetName,
//----------------------------------------------------------------------------
void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
{
if (this->MustSkip())
return;
assert(this->MacContentFolders);
// Configure the Info.plist file into the Resources directory.
......@@ -184,12 +174,15 @@ void cmOSXBundleGenerator::CreateFramework(std::string const& targetName)
void cmOSXBundleGenerator::CreateCFBundle(std::string& targetName,
std::string& outpath)
{
if (this->MustSkip())
return;
// Compute bundle directory names.
outpath = this->MacContentDirectory;
outpath += "MacOS";
cmSystemTools::MakeDirectory(outpath.c_str());
this->Makefile->AddCMakeOutputFile(outpath.c_str());
outpath += "/";
this->Makefile->AddCMakeOutputFile(outpath.c_str());
// Configure the Info.plist file. Note that it needs the executable name
// to be set.
......@@ -207,6 +200,9 @@ cmOSXBundleGenerator::
GenerateMacOSXContentStatements(std::vector<cmSourceFile*> const& sources,
MacOSXContentGeneratorType* generator)
{
if (this->MustSkip())
return;
for(std::vector<cmSourceFile*>::const_iterator
si = sources.begin(); si != sources.end(); ++si)
{
......
......@@ -52,6 +52,9 @@ public:
void SetMacContentFolders(std::set<cmStdString>* macContentFolders)
{ this->MacContentFolders = macContentFolders; }
private:
bool MustSkip();
private:
cmTarget* Target;
cmMakefile* Makefile;
......
......@@ -2482,6 +2482,16 @@ void cmTarget::MarkAsImported()
this->IsImportedTarget = true;
}
//----------------------------------------------------------------------------
bool cmTarget::HaveWellDefinedOutputFiles()
{
return
this->GetType() == cmTarget::STATIC_LIBRARY ||
this->GetType() == cmTarget::SHARED_LIBRARY ||
this->GetType() == cmTarget::MODULE_LIBRARY ||
this->GetType() == cmTarget::EXECUTABLE;
}
//----------------------------------------------------------------------------
cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
{
......@@ -2492,10 +2502,7 @@ cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
}
// Only libraries and executables have well-defined output files.
if(this->GetType() != cmTarget::STATIC_LIBRARY &&
this->GetType() != cmTarget::SHARED_LIBRARY &&
this->GetType() != cmTarget::MODULE_LIBRARY &&
this->GetType() != cmTarget::EXECUTABLE)
if(!this->HaveWellDefinedOutputFiles())
{
std::string msg = "cmTarget::GetOutputInfo called for ";
msg += this->GetName();
......@@ -2586,18 +2593,7 @@ const char* cmTarget::NormalGetLocation(const char* config)
this->Location += cfgid;
this->Location += "/";
}
if(this->IsAppBundleOnApple())
{
this->Location += this->GetFullName(config, false);
this->Location += ".app/Contents/MacOS/";
}
if(this->IsFrameworkOnApple())
{
this->Location += this->GetFullName(config, false);
this->Location += ".framework/Versions/";
this->Location += this->GetFrameworkVersion();
this->Location += "/";
}
this->Location = this->BuildMacContentDirectory(this->Location, config);
this->Location += this->GetFullName(config, false);
return this->Location.c_str();
}
......@@ -3169,35 +3165,7 @@ std::string cmTarget::GetFullPath(const char* config, bool implib,
std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
bool realname)
{
// TODO: Re-factor with cmOSXBundleGenerator's constructor.
// Start with the output directory for the target.
std::string fpath = this->GetDirectory(config, implib);
fpath += "/";
if(this->IsAppBundleOnApple())
{
fpath += this->GetFullName(config, false);
fpath += ".app/Contents/MacOS/";
}
if(this->IsFrameworkOnApple())
{
fpath += this->GetFullName(config, false);
fpath += ".framework/Versions/";
fpath += this->GetFrameworkVersion();
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/";
}
std::string fpath = this->GetMacContentDirectory(config, implib);
// Add the full name of the target.
if(implib)
......@@ -4746,6 +4714,55 @@ std::vector<std::string> cmTarget::GetIncludeDirectories()
return orderedAndUniqueIncludes;
}
//----------------------------------------------------------------------------
std::string cmTarget::BuildMacContentDirectory(const std::string& base,
const char* config,
bool includeMacOS)
{
std::string fpath = base;
if(this->IsAppBundleOnApple())
{
fpath += this->GetFullName(config, false);
fpath += ".app/Contents/";
if(includeMacOS)
fpath += "MacOS/";
}
if(this->IsFrameworkOnApple())
{
fpath += this->GetFullName(config, false);
fpath += ".framework/Versions/";
fpath += this->GetFrameworkVersion();
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/";
if(includeMacOS)
fpath += "MacOS/";
}
return fpath;
}
//----------------------------------------------------------------------------
std::string cmTarget::GetMacContentDirectory(const char* config,
bool implib,
bool includeMacOS)
{
// Start with the output directory for the target.
std::string fpath = this->GetDirectory(config, implib);
fpath += "/";
fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
return fpath;
}
//----------------------------------------------------------------------------
cmTargetLinkInformationMap
::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
......
......@@ -465,6 +465,19 @@ public:
/** Get the include directories for this target. */
std::vector<std::string> GetIncludeDirectories();
/** Append to @a base the mac content directory and return it. */
std::string BuildMacContentDirectory(const std::string& base,
const char* config = 0,
bool includeMacOS = true);
/** @return the mac content directory for this target. */
std::string GetMacContentDirectory(const char* config = 0,
bool implib = false,
bool includeMacOS = true);
/** @return whether this target have a well defined output file name. */
bool HaveWellDefinedOutputFiles();
private:
/**
* A list of direct dependencies. Use in conjunction with DependencyMap.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment