ENH: depends work between targets

This commit is contained in:
Bill Hoffman 2005-02-03 17:42:55 -05:00
parent cecf8bf26a
commit fd0f29e6f4
7 changed files with 254 additions and 28 deletions

View File

@ -798,3 +798,20 @@ void cmGlobalGenerator::FillProjectMap()
}
}
cmTarget* cmGlobalGenerator::FindTarget(const char* name)
{
for(unsigned int i = 0; i < m_LocalGenerators.size(); ++i)
{
cmTargets& tgts = m_LocalGenerators[i]->GetMakefile()->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
{
if(l->first == name)
{
return &l->second;
}
}
}
return 0;
}

View File

@ -23,6 +23,7 @@
class cmake;
class cmMakefile;
class cmLocalGenerator;
class cmTarget;
/** \class cmGlobalGenerator
* \brief Responable for overseeing the generation process for the entire tree
@ -132,6 +133,8 @@ protected:
///! used by Configure()
void RecursiveConfigure(cmLocalGenerator *lg, float start, float end);
///! Find a target by name by searching the local generators.
cmTarget* FindTarget(const char* name);
private:
// If you add a new map here, make sure it is copied
// in EnableLanguagesFromGenerator

View File

@ -22,6 +22,14 @@
#include "cmGeneratedFileStream.h"
#include "cmSourceFile.h"
//TODO
// per file flags
// depend info
// do I need an ALL_BUILD
// link libraries stuff
// exe/lib output paths
//----------------------------------------------------------------------------
cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
{
@ -201,8 +209,10 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
std::vector<cmXCodeObject*>& targets,
void
cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
std::vector<cmXCodeObject*>&
targets,
cmXCodeObject* mainGroupChildren)
{
m_CurrentLocalGenerator = gen;
@ -210,6 +220,15 @@ void cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
cmTargets &tgts = gen->GetMakefile()->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
{
cmTarget& cmtarget = l->second;
if(cmtarget.GetType() == cmTarget::UTILITY ||
cmtarget.GetType() == cmTarget::INSTALL_FILES ||
cmtarget.GetType() == cmTarget::INSTALL_PROGRAMS)
{
targets.push_back(this->CreateUtilityTarget(cmtarget));
continue;
}
// create source build phase
cmXCodeObject* sourceBuildPhase =
this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
@ -247,7 +266,8 @@ void cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
this->CreateString("0"));
cmXCodeObject* buildPhases = this->CreateObject(cmXCodeObject::OBJECT_LIST);
cmXCodeObject* buildPhases =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
buildPhases->AddObject(sourceBuildPhase);
buildPhases->AddObject(headerBuildPhase);
buildPhases->AddObject(frameworkBuildPhase);
@ -276,7 +296,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
m_CurrentLocalGenerator->AddSharedFlags(flags, lang, shared);
}
// Add include directory flags.
// this->AppendFlags(flags, this->GetIncludeFlags(lang));
m_CurrentLocalGenerator->
AppendFlags(flags, m_CurrentLocalGenerator->GetIncludeFlags(lang));
// Add include directory flags.
m_CurrentLocalGenerator->AppendFlags(flags,
@ -319,6 +340,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
productType = "com.apple.product-type.tool";
break;
case cmTarget::UTILITY:
break;
case cmTarget::INSTALL_FILES:
break;
@ -345,11 +367,57 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
this->CreateString(target.GetName()));
}
cmXCodeObject*
cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
{
cmXCodeObject* shellBuildPhase =
this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
shellBuildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647"));
cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
shellBuildPhase->AddAttribute("files", buildFiles);
cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
shellBuildPhase->AddAttribute("inputPaths", inputPaths);
cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
shellBuildPhase->AddAttribute("outputPaths", outputPaths);
shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
this->CreateString("0"));
shellBuildPhase->AddAttribute("shellPath",
this->CreateString("/bin/sh"));
shellBuildPhase->AddAttribute("shellScript",
this->CreateString(
"# shell script goes here\nexit 0"));
cmXCodeObject* target =
this->CreateObject(cmXCodeObject::PBXAggregateTarget);
cmXCodeObject* buildPhases =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
buildPhases->AddObject(shellBuildPhase);
target->AddAttribute("buildPhases", buildPhases);
cmXCodeObject* buildSettings =
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
std::string fileTypeString;
std::string productTypeString;
std::string productName;
this->CreateBuildSettings(cmtarget,
buildSettings, fileTypeString,
productTypeString, productName);
target->AddAttribute("buildSettings", buildSettings);
cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
target->AddAttribute("dependencies", dependencies);
target->AddAttribute("name", this->CreateString(cmtarget.GetName()));
target->AddAttribute("productName",this->CreateString(cmtarget.GetName()));
target->SetcmTarget(&cmtarget);
return target;
}
cmXCodeObject*
cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
cmXCodeObject* buildPhases)
{
cmXCodeObject* target = this->CreateObject(cmXCodeObject::PBXNativeTarget);
cmXCodeObject* target =
this->CreateObject(cmXCodeObject::PBXNativeTarget);
target->AddAttribute("buildPhases", buildPhases);
cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
target->AddAttribute("buildRules", buildRules);
@ -376,9 +444,113 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
target->AddAttribute("productReference", this->CreateObjectReference(fileRef));
target->AddAttribute("productType",
this->CreateString(productTypeString.c_str()));
target->SetcmTarget(&cmtarget);
return target;
}
cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(cmTarget* t)
{
if(!t)
{
return 0;
}
for(std::vector<cmXCodeObject*>::iterator i = m_XCodeObjects.begin();
i != m_XCodeObjects.end(); ++i)
{
cmXCodeObject* o = *i;
if(o->GetcmTarget() == t)
{
return o;
}
}
return 0;
}
void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget)
{
cmXCodeObject* container =
this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
container->AddAttribute("containerPortal",
this->CreateObjectReference(m_RootObject));
container->AddAttribute("proxyType", this->CreateString("1"));
container->AddAttribute("remoteGlobalIDString",
this->CreateObjectReference(dependTarget));
container->AddAttribute("remoteInfo",
this->CreateString(
dependTarget->GetcmTarget()->GetName()));
cmXCodeObject* targetdep =
this->CreateObject(cmXCodeObject::PBXTargetDependency);
targetdep->AddAttribute("target", this->CreateObjectReference(dependTarget));
targetdep->AddAttribute("targetProxy",
this->CreateObjectReference(container));
cmXCodeObject* depends = target->GetObject("dependencies");
if(!depends)
{
std::cerr << "target does not have dependencies attribute error...\n";
}
else
{
depends->AddObject(targetdep);
}
}
void cmGlobalXCodeGenerator::AddLinkTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget)
{
}
void cmGlobalXCodeGenerator::AddLinkFlag(cmXCodeObject* target,
const char*)
{
}
void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
{
cmTarget* cmtarget = target->GetcmTarget();
if(!cmtarget)
{
std::cerr << "Error no target on xobject\n";
return;
}
cmTarget::LinkLibraries::const_iterator j, jend;
j = cmtarget->GetLinkLibraries().begin();
jend = cmtarget->GetLinkLibraries().end();
std::cerr << "link targets for " << cmtarget->GetName() << "\n";
for(;j!= jend; ++j)
{
cmTarget* t = this->FindTarget(j->first.c_str());
cmXCodeObject* dptarget = this->FindXCodeTarget(t);
if(dptarget)
{
this->AddDependTarget(target, dptarget);
this->AddLinkTarget(target, dptarget);
}
else
{
this->AddLinkFlag(target, j->first.c_str());
}
}
std::set<cmStdString>::const_iterator i, end;
// write utility dependencies.
i = cmtarget->GetUtilities().begin();
end = cmtarget->GetUtilities().end();
for(;i!= end; ++i)
{
cmTarget* t = this->FindTarget(i->c_str());
cmXCodeObject* dptarget = this->FindXCodeTarget(t);
if(dptarget)
{
this->AddDependTarget(target, dptarget);
}
else
{
std::cerr << "External Util???: " << i->c_str() << "\n";
}
}
}
// to force the location of a target
//6FE4372B07AAF276004FB461 = {
@ -436,7 +608,9 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* ,
for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
i != targets.end(); ++i)
{
allTargets->AddObject(*i);
cmXCodeObject* t = *i;
this->AddDependAndLinkInformation(t);
allTargets->AddObject(t);
}
m_RootObject->AddAttribute("targets", allTargets);
}

View File

@ -66,6 +66,7 @@ public:
virtual void Generate();
private:
cmXCodeObject* FindXCodeTarget(cmTarget*);
// create cmXCodeObject from these functions so that memory can be managed
// correctly. All objects created are stored in m_XCodeObjects.
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
@ -74,19 +75,14 @@ private:
cmXCodeObject* CreateObjectReference(cmXCodeObject*);
cmXCodeObject* CreateXCodeTarget(cmTarget& target,
cmXCodeObject* buildPhases);
cmXCodeObject* CreateUtilityTarget(cmTarget& target);
void AddDependAndLinkInformation(cmXCodeObject* target);
void CreateBuildSettings(cmTarget& target,
cmXCodeObject* buildSettings,
std::string& fileType,
std::string& productType,
std::string& projectName);
// deprecated TODO FIXME
cmXCodeObject* CreateExecutable(cmTarget& cmtarget,
cmXCodeObject* buildPhases);
cmXCodeObject* CreateStaticLibrary(cmTarget& cmtarget,
cmXCodeObject* buildPhases);
cmXCodeObject* CreateSharedLibrary(cmTarget& cmtarget,
cmXCodeObject* buildPhases);
// delete all objects in the m_XCodeObjects vector.
void ClearXCodeObjects();
void CreateXCodeObjects(cmLocalGenerator* root,
@ -100,7 +96,13 @@ private:
cmXCodeObject* mainGroupChildren);
void CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&,
cmXCodeObject* mainGroupChildren);
void AddDependTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget);
void AddLinkTarget(cmXCodeObject* target,
cmXCodeObject* dependTarget);
void AddLinkFlag(cmXCodeObject* target,
const char*);
private:
std::vector<cmXCodeObject*> m_XCodeObjects;
cmXCodeObject* m_RootObject;
cmMakefile* m_CurrentMakefile;

View File

@ -97,6 +97,8 @@ public:
void AddSharedFlags(std::string& flags, const char* lang, bool shared);
void AddConfigVariableFlags(std::string& flags, const char* var);
void AppendFlags(std::string& flags, const char* newFlags);
///! Get the include flags for the current makefile and language
const char* GetIncludeFlags(const char* lang);
protected:
@ -109,8 +111,6 @@ protected:
///! put all the libraries for a target on into the given stream
virtual void OutputLinkLibraries(std::ostream&, const char* name, const cmTarget &);
///! Get the include flags for the current makefile and language
const char* GetIncludeFlags(const char* lang);
/** Get the include flags for the current makefile and language. */
void GetIncludeDirectories(std::vector<std::string>& dirs);

View File

@ -4,15 +4,23 @@
const char* cmXCodeObject::PBXTypeNames[] = {
"PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
"PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
"PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy", "PBXTargetDependency",
"PBXShellScriptBuildPhase", "PBXResourcesBuildPhase", "PBXApplicationReference",
"PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget", "PBXLibraryTarget",
"PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
"PBXTargetDependency", "PBXShellScriptBuildPhase",
"PBXResourcesBuildPhase", "PBXApplicationReference",
"PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
"PBXLibraryTarget", "PBXAggregateTarget",
"None"
};
cmXCodeObject::~cmXCodeObject()
{
}
//----------------------------------------------------------------------------
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
// m_cmTarget = 0;
m_IsA = ptype;
cmOStringStream str;
str << (void*)this;

View File

@ -2,20 +2,24 @@
#define cmXCodeObject_h
#include "cmStandardIncludes.h"
class cmTarget;
class cmXCodeObject
{
public:
enum Type { OBJECT_LIST, STRING, ATTRIBUTE_GROUP, OBJECT_REF, OBJECT };
enum PBXType { PBXGroup, PBXBuildStyle, PBXProject, PBXHeadersBuildPhase,
PBXSourcesBuildPhase, PBXFrameworksBuildPhase, PBXNativeTarget,
PBXFileReference, PBXBuildFile, PBXContainerItemProxy, PBXTargetDependency,
PBXShellScriptBuildPhase, PBXResourcesBuildPhase, PBXApplicationReference,
PBXExecutableFileReference, PBXLibraryReference, PBXToolTarget, PBXLibraryTarget,
PBXSourcesBuildPhase, PBXFrameworksBuildPhase,
PBXNativeTarget, PBXFileReference, PBXBuildFile,
PBXContainerItemProxy, PBXTargetDependency,
PBXShellScriptBuildPhase, PBXResourcesBuildPhase,
PBXApplicationReference, PBXExecutableFileReference,
PBXLibraryReference, PBXToolTarget, PBXLibraryTarget,
PBXAggregateTarget,
None
};
static const char* PBXTypeNames[];
~cmXCodeObject();
cmXCodeObject(PBXType ptype, Type type);
void SetString(const char* s)
{
@ -44,7 +48,25 @@ public:
{
return m_Id.c_str();
}
cmTarget* GetcmTarget()
{
return m_cmTarget;
}
void SetcmTarget(cmTarget* t)
{
m_cmTarget = t;
}
cmXCodeObject* GetObject(const char* name)
{
if(m_ObjectAttributes.count(name))
{
return m_ObjectAttributes[name];
}
return 0;
}
private:
cmTarget* m_cmTarget;
Type m_Type;
cmStdString m_Id;
PBXType m_IsA;