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

Re-factor bundle content copying rules generation.

parent 3b2a01e8
......@@ -18,13 +18,11 @@
#include "cmSourceFile.h"
#include "cmTarget.h"
#include "cmake.h"
#include "cmOSXBundleGenerator.h"
//----------------------------------------------------------------------------
cmMakefileExecutableTargetGenerator
::cmMakefileExecutableTargetGenerator(cmTarget* target):
cmMakefileTargetGenerator(target),
OSXBundleGenerator(0)
cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnDepends;
this->Target->GetExecutableNames(
......@@ -34,6 +32,7 @@ cmMakefileExecutableTargetGenerator
this->OSXBundleGenerator = new cmOSXBundleGenerator(this->Target,
this->TargetNameOut,
this->ConfigName);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
this->MacContentDirectory =
this->OSXBundleGenerator->GetMacContentDirectory();
}
......
......@@ -14,8 +14,6 @@
#include "cmMakefileTargetGenerator.h"
class cmOSXBundleGenerator;
class cmMakefileExecutableTargetGenerator: public cmMakefileTargetGenerator
{
public:
......@@ -28,9 +26,6 @@ public:
protected:
virtual void WriteExecutableRule(bool relink);
private:
cmOSXBundleGenerator* OSXBundleGenerator;
};
#endif
......@@ -18,15 +18,13 @@
#include "cmSourceFile.h"
#include "cmTarget.h"
#include "cmake.h"
#include "cmOSXBundleGenerator.h"
#include <memory> // auto_ptr
//----------------------------------------------------------------------------
cmMakefileLibraryTargetGenerator
::cmMakefileLibraryTargetGenerator(cmTarget* target):
cmMakefileTargetGenerator(target),
OSXBundleGenerator(0)
cmMakefileTargetGenerator(target)
{
cmOSXBundleGenerator::PrepareTargetProperties(this->Target);
......
......@@ -14,8 +14,6 @@
#include "cmMakefileTargetGenerator.h"
class cmOSXBundleGenerator;
class cmMakefileLibraryTargetGenerator:
public cmMakefileTargetGenerator
{
......@@ -42,9 +40,6 @@ protected:
void AppendOSXVerFlag(std::string& flags, const char* lang,
const char* name, bool so);
private:
cmOSXBundleGenerator* OSXBundleGenerator;
};
#endif
......@@ -28,6 +28,8 @@
cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmTarget* target)
: OSXBundleGenerator(0)
, MacOSXContentGenerator(this)
{
this->BuildFileStream = 0;
this->InfoFileStream = 0;
......@@ -153,8 +155,12 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
}
}
}
this->WriteMacOSXContentRules(this->GeneratorTarget->HeaderSources);
this->WriteMacOSXContentRules(this->GeneratorTarget->ExtraSources);
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
this->GeneratorTarget->HeaderSources,
&this->MacOSXContentGenerator);
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
this->GeneratorTarget->ExtraSources,
&this->MacOSXContentGenerator);
for(std::vector<cmSourceFile*>::const_iterator
si = this->GeneratorTarget->ExternalObjects.begin();
si != this->GeneratorTarget->ExternalObjects.end(); ++si)
......@@ -173,7 +179,6 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
this->GeneratorTarget->UseObjectLibraries(this->ExternalObjects);
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::WriteCommonCodeRules()
{
......@@ -344,33 +349,26 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::WriteMacOSXContentRules(
std::vector<cmSourceFile*> const& sources)
cmMakefileTargetGenerator::MacOSXContentGeneratorType::
MacOSXContentGeneratorType(cmMakefileTargetGenerator* generator)
: cmOSXBundleGenerator::MacOSXContentGeneratorType()
, Generator(generator)
{
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)
{
this->WriteMacOSXContentRules(**si, tsFlags.MacFolder);
}
}
}
//----------------------------------------------------------------------------
void cmMakefileTargetGenerator::WriteMacOSXContentRules(cmSourceFile& source,
const char* pkgloc)
void
cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()
(cmSourceFile& source, const char* pkgloc)
{
// Skip OS X content when not building a Framework or Bundle.
if(this->MacContentDirectory.empty())
if(this->Generator->MacContentDirectory.empty())
{
return;
}
// Construct the full path to the content subdirectory.
std::string macdir = this->MacContentDirectory;
std::string macdir = this->Generator->MacContentDirectory;
macdir += pkgloc;
cmSystemTools::MakeDirectory(macdir.c_str());
......@@ -379,7 +377,7 @@ void cmMakefileTargetGenerator::WriteMacOSXContentRules(cmSourceFile& source,
{
std::string loc = pkgloc;
loc = loc.substr(0, loc.find('/'));
this->MacContentFolders.insert(loc);
this->Generator->MacContentFolders.insert(loc);
}
// Get the input file location.
......@@ -389,9 +387,11 @@ void cmMakefileTargetGenerator::WriteMacOSXContentRules(cmSourceFile& source,
std::string output = macdir;
output += "/";
output += cmSystemTools::GetFilenameName(input);
this->CleanFiles.push_back(this->Convert(output.c_str(),
cmLocalGenerator::START_OUTPUT));
output = this->Convert(output.c_str(), cmLocalGenerator::HOME_OUTPUT);
this->Generator->CleanFiles.push_back(
this->Generator->Convert(output.c_str(),
cmLocalGenerator::START_OUTPUT));
output = this->Generator->Convert(output.c_str(),
cmLocalGenerator::HOME_OUTPUT);
// Create a rule to copy the content into the bundle.
std::vector<std::string> depends;
......@@ -399,21 +399,23 @@ void cmMakefileTargetGenerator::WriteMacOSXContentRules(cmSourceFile& source,
depends.push_back(input);
std::string copyEcho = "Copying OS X content ";
copyEcho += output;
this->LocalGenerator->AppendEcho(commands, copyEcho.c_str(),
cmLocalUnixMakefileGenerator3::EchoBuild);
this->Generator->LocalGenerator->AppendEcho(
commands, copyEcho.c_str(),
cmLocalUnixMakefileGenerator3::EchoBuild);
std::string copyCommand = "$(CMAKE_COMMAND) -E copy ";
copyCommand += this->Convert(input.c_str(),
cmLocalGenerator::NONE,
cmLocalGenerator::SHELL);
copyCommand += this->Generator->Convert(input.c_str(),
cmLocalGenerator::NONE,
cmLocalGenerator::SHELL);
copyCommand += " ";
copyCommand += this->Convert(output.c_str(),
cmLocalGenerator::NONE,
cmLocalGenerator::SHELL);
copyCommand += this->Generator->Convert(output.c_str(),
cmLocalGenerator::NONE,
cmLocalGenerator::SHELL);
commands.push_back(copyCommand);
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
output.c_str(),
depends, commands, false);
this->ExtraFiles.insert(output);
this->Generator->LocalGenerator->WriteMakeRule(
*this->Generator->BuildFileStream, 0,
output.c_str(),
depends, commands, false);
this->Generator->ExtraFiles.insert(output);
}
//----------------------------------------------------------------------------
......
......@@ -13,6 +13,7 @@
#define cmMakefileTargetGenerator_h
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmOSXBundleGenerator.h"
class cmCustomCommand;
class cmDependInformation;
......@@ -73,8 +74,17 @@ protected:
void WriteTargetDependRules();
// write rules for Mac OS X Application Bundle content.
void WriteMacOSXContentRules(std::vector<cmSourceFile*> const& sources);
void WriteMacOSXContentRules(cmSourceFile& source, const char* pkgloc);
class MacOSXContentGeneratorType
: public cmOSXBundleGenerator::MacOSXContentGeneratorType
{
public:
MacOSXContentGeneratorType(cmMakefileTargetGenerator* Generator);
virtual void operator()(cmSourceFile& source, const char* pkgloc);
private:
cmMakefileTargetGenerator* Generator;
};
friend class MacOSXContentGeneratorType;
// write the rules for an object
void WriteObjectRuleFiles(cmSourceFile& source);
......@@ -223,6 +233,8 @@ protected:
// Mac OS X content info.
std::string MacContentDirectory;
std::set<cmStdString> MacContentFolders;
cmOSXBundleGenerator* OSXBundleGenerator;
MacOSXContentGeneratorType MacOSXContentGenerator;
typedef std::map<cmStdString, cmStdString> ByLanguageMap;
std::string GetFlags(const std::string &l);
......
......@@ -24,6 +24,12 @@ cmMakefileUtilityTargetGenerator
cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnUtility;
this->OSXBundleGenerator = new cmOSXBundleGenerator(this->Target,
this->TargetNameOut,
this->ConfigName);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
this->MacContentDirectory =
this->OSXBundleGenerator->GetMacContentDirectory();
}
//----------------------------------------------------------------------------
......
......@@ -22,7 +22,6 @@
#include "cmComputeLinkInformation.h"
#include "cmSourceFile.h"
#include "cmCustomCommandGenerator.h"
#include "cmOSXBundleGenerator.h"
#include <algorithm>
......@@ -58,6 +57,7 @@ cmNinjaTargetGenerator::New(cmTarget* target)
cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmTarget* target)
:
MacOSXContentGenerator(this),
OSXBundleGenerator(0),
MacContentFolders(),
Target(target),
......@@ -432,9 +432,12 @@ cmNinjaTargetGenerator
cmCustomCommand const* cc = (*si)->GetCustomCommand();
this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
}
this->WriteMacOSXContentBuildStatements(
this->GeneratorTarget->HeaderSources);
this->WriteMacOSXContentBuildStatements(this->GeneratorTarget->ExtraSources);
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
this->GeneratorTarget->HeaderSources,
&this->MacOSXContentGenerator);
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
this->GeneratorTarget->ExtraSources,
&this->MacOSXContentGenerator);
for(std::vector<cmSourceFile*>::const_iterator
si = this->GeneratorTarget->ExternalObjects.begin();
si != this->GeneratorTarget->ExternalObjects.end(); ++si)
......@@ -643,35 +646,27 @@ cmNinjaTargetGenerator
}
//----------------------------------------------------------------------------
// TODO: Re-factor with cmMakefileTargetGenerator::WriteMacOSXContentRules
void cmNinjaTargetGenerator::WriteMacOSXContentBuildStatements(
std::vector<cmSourceFile*> const& sources)
cmNinjaTargetGenerator::MacOSXContentGeneratorType::
MacOSXContentGeneratorType(cmNinjaTargetGenerator* generator)
: cmOSXBundleGenerator::MacOSXContentGeneratorType()
, Generator(generator)
{
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)
{
this->WriteMacOSXContentBuildStatement(**si, tsFlags.MacFolder);
}
}
}
//----------------------------------------------------------------------------
// TODO: Re-factor with cmMakefileTargetGenerator::WriteMacOSXContentRules
void cmNinjaTargetGenerator::WriteMacOSXContentBuildStatement(
void
cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
cmSourceFile& source, const char* pkgloc)
{
// Skip OS X content when not building a Framework or Bundle.
if(this->OSXBundleGenerator->GetMacContentDirectory().empty())
if(this->Generator->OSXBundleGenerator->GetMacContentDirectory().empty())
{
return;
}
// Construct the full path to the content subdirectory.
std::string macdir = this->OSXBundleGenerator->GetMacContentDirectory();
std::string macdir =
this->Generator->OSXBundleGenerator->GetMacContentDirectory();
macdir += pkgloc;
cmSystemTools::MakeDirectory(macdir.c_str());
......@@ -680,22 +675,25 @@ void cmNinjaTargetGenerator::WriteMacOSXContentBuildStatement(
{
std::string loc = pkgloc;
loc = loc.substr(0, loc.find('/'));
this->MacContentFolders.insert(loc);
this->Generator->MacContentFolders.insert(loc);
}
// Get the input file location.
std::string input = source.GetFullPath();
input = this->GetLocalGenerator()->ConvertToNinjaPath(input.c_str());
input =
this->Generator->GetLocalGenerator()->ConvertToNinjaPath(input.c_str());
// Get the output file location.
std::string output = macdir;
output += "/";
output += cmSystemTools::GetFilenameName(input);
output = this->GetLocalGenerator()->ConvertToNinjaPath(output.c_str());
output =
this->Generator->GetLocalGenerator()->ConvertToNinjaPath(output.c_str());
// Write a build statement to copy the content into the bundle.
this->GetGlobalGenerator()->WriteMacOSXContentBuild(input, output);
this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
output);
// Add as a dependency of all target so that it gets called.
this->GetGlobalGenerator()->AddDependencyToAll(output);
this->Generator->GetGlobalGenerator()->AddDependencyToAll(output);
}
......@@ -16,6 +16,7 @@
#include "cmStandardIncludes.h"
#include "cmNinjaTypes.h"
#include "cmLocalNinjaGenerator.h"
#include "cmOSXBundleGenerator.h"
class cmTarget;
class cmGlobalNinjaGenerator;
......@@ -24,7 +25,6 @@ class cmGeneratorTarget;
class cmMakefile;
class cmSourceFile;
class cmCustomCommand;
class cmOSXBundleGenerator;
class cmNinjaTargetGenerator
{
......@@ -115,12 +115,21 @@ protected:
void EnsureDirectoryExists(const std::string& dir);
void EnsureParentDirectoryExists(const std::string& path);
void WriteMacOSXContentBuildStatements(
std::vector<cmSourceFile*> const& sources);
void WriteMacOSXContentBuildStatement(cmSourceFile& source,
const char* pkgloc);
// write rules for Mac OS X Application Bundle content.
class MacOSXContentGeneratorType
: public cmOSXBundleGenerator::MacOSXContentGeneratorType
{
public:
MacOSXContentGeneratorType(cmNinjaTargetGenerator* Generator);
virtual void operator()(cmSourceFile& source, const char* pkgloc);
private:
cmNinjaTargetGenerator* Generator;
};
friend class MacOSXContentGeneratorType;
protected:
MacOSXContentGeneratorType MacOSXContentGenerator;
// Properly initialized by sub-classes.
cmOSXBundleGenerator* OSXBundleGenerator;
std::set<cmStdString> MacContentFolders;
......
......@@ -200,3 +200,21 @@ void cmOSXBundleGenerator::CreateCFBundle(std::string& targetName,
plist.c_str());
this->Makefile->AddCMakeOutputFile(plist.c_str());
}
//----------------------------------------------------------------------------
void
cmOSXBundleGenerator::
GenerateMacOSXContentStatements(std::vector<cmSourceFile*> const& sources,
MacOSXContentGeneratorType* generator)
{
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);
}
}
}
......@@ -13,6 +13,7 @@
#define cmOSXBundleGenerator_h
#include "cmStandardIncludes.h"
#include "cmSourceFile.h"
#include <string>
#include <set>
......@@ -34,6 +35,16 @@ public:
void CreateFramework(std::string const& targetName);
void CreateCFBundle(std::string& targetName, std::string& outpath);
class MacOSXContentGeneratorType
{
public:
virtual void operator()(cmSourceFile& source, const char* pkgloc) = 0;
};
void GenerateMacOSXContentStatements(
std::vector<cmSourceFile*> const& sources,
MacOSXContentGeneratorType* generator);
std::string GetMacContentDirectory() const
{ return this->MacContentDirectory; }
std::string GetFrameworkVersion() const
......
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