ENH: add more xcode stuff

This commit is contained in:
Bill Hoffman 2005-01-27 16:11:44 -05:00
parent c22cc421e0
commit 97a51d2172
3 changed files with 150 additions and 21 deletions

View File

@ -20,6 +20,7 @@
#include "cmXCodeObject.h"
#include "cmake.h"
#include "cmGeneratedFileStream.h"
#include "cmSourceFile.h"
//----------------------------------------------------------------------------
cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
@ -78,55 +79,175 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects()
}
//----------------------------------------------------------------------------
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype,
cmXCodeObject::Type type)
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype)
{
cmXCodeObject* obj = new cmXCodeObject(ptype, type);
cmXCodeObject* obj = new cmXCodeObject(ptype, cmXCodeObject::OBJECT);
m_XCodeObjects.push_back(obj);
return obj;
}
//----------------------------------------------------------------------------
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::Type type)
{
cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, type);
m_XCodeObjects.push_back(obj);
return obj;
}
cmXCodeObject* cmGlobalXCodeGenerator::CreateString(const char* s)
{
cmXCodeObject* obj = new cmXCodeObject(cmXCodeObject::None, cmXCodeObject::STRING);
m_XCodeObjects.push_back(obj);
cmXCodeObject* obj = this->CreateObject(cmXCodeObject::STRING);
obj->SetString(s);
return obj;
}
cmXCodeObject*
cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
cmSourceFile* sf)
{
cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
cmXCodeObject* fileRefPtr = this->CreateObject(cmXCodeObject::OBJECT_REF);
fileRefPtr->SetObject(fileRef);
cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
buildFile->AddAttribute("fileRef", fileRefPtr);
cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
buildFile->AddAttribute("settings", settings);
fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
fileRef->AddAttribute("lastKnownFileType", this->CreateString("sourcecode.cpp.cpp;"));
fileRef->AddAttribute("path", this->CreateString(
lg->ConvertToRelativeOutputPath(sf->GetFullPath().c_str()).c_str()));
fileRef->AddAttribute("refType", this->CreateString("4"));
fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
return buildFile;
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* ,
std::vector<cmLocalGenerator*>&
void cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
std::vector<cmXCodeObject*>& targets)
{
cmTargets &tgts = gen->GetMakefile()->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
{
// create source build phase
cmXCodeObject* sourceBuildPhase = this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
sourceBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647"));
cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
sourceBuildPhase->AddAttribute("files", buildFiles);
sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", this->CreateString("0"));
std::vector<cmSourceFile*> &classes = l->second.GetSourceFiles();
// add all the sources
for(std::vector<cmSourceFile*>::iterator i = classes.begin();
i != classes.end(); ++i)
{
buildFiles->AddObject(this->CreateXCodeSourceFile(gen, *i));
}
// create header build phase
cmXCodeObject* headerBuildPhase = this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
headerBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647"));
buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
headerBuildPhase->AddAttribute("files", buildFiles);
headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", this->CreateString("0"));
// create framework build phase
cmXCodeObject* frameworkBuildPhase = this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
frameworkBuildPhase->AddAttribute("buildActionMask", this->CreateString("2147483647"));
buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
frameworkBuildPhase->AddAttribute("files", buildFiles);
frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", this->CreateString("0"));
cmXCodeObject* buildPhases = this->CreateObject(cmXCodeObject::OBJECT_LIST);
buildPhases->AddObject(sourceBuildPhase);
buildPhases->AddObject(headerBuildPhase);
buildPhases->AddObject(frameworkBuildPhase);
if((l->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(l->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(l->second.GetType() == cmTarget::MODULE_LIBRARY))
{
}
else if ( l->second.GetType() == cmTarget::EXECUTABLE )
{
cmXCodeObject* target = this->CreateObject(cmXCodeObject::PBXNativeTarget);
targets.push_back(target);
target->AddAttribute("buildPhases", buildPhases);
cmXCodeObject* buildRules = this->CreateObject(cmXCodeObject::OBJECT_LIST);
target->AddAttribute("buildRules", buildRules);
cmXCodeObject* buildSettings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
buildSettings->AddAttribute("INSTALL_PATH", this->CreateString("/usr/local/bin"));
buildSettings->AddAttribute("OPTIMIZATION_CFLAGS", this->CreateString(""));
buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(""));
buildSettings->AddAttribute("OTHER_LDFLAGS", this->CreateString(""));
buildSettings->AddAttribute("OTHER_REZFLAGS", this->CreateString(""));
buildSettings->AddAttribute("PRODUCT_NAME", this->CreateString(l->first.c_str()));
buildSettings->AddAttribute("SECTORDER_FLAGS", this->CreateString(""));
buildSettings->AddAttribute("WARNING_CFLAGS",
this->CreateString("-Wmost -Wno-four-char-constants -Wno-unknown-pragmas"));
target->AddAttribute("buildSettings", buildSettings);
cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
target->AddAttribute("dependencies", dependencies);
target->AddAttribute("name", this->CreateString(l->first.c_str()));
target->AddAttribute("productName",this->CreateString(l->first.c_str()));
cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
fileRef->AddAttribute("explicitFileType", this->CreateString("compiled.mach-o.executable"));
fileRef->AddAttribute("includedInIndex", this->CreateString("0"));
fileRef->AddAttribute("path", this->CreateString(l->first.c_str()));
fileRef->AddAttribute("refType", this->CreateString("3"));
fileRef->AddAttribute("sourceTree", this->CreateString("BUILT_PRODUCTS_DIR"));
cmXCodeObject* fileRefPtr = this->CreateObject(cmXCodeObject::OBJECT_REF);
fileRefPtr->AddObject(fileRef);
target->AddAttribute("productReference", fileRefPtr);
target->AddAttribute("productReference", this->CreateString("com.apple.product-type.tool"));
}
else if (l->second.GetType() == cmTarget::UTILITY)
{
}
}
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>&
generators
)
{
delete m_RootObject;
this->ClearXCodeObjects();
cmXCodeObject* group = this->CreateObject(cmXCodeObject::None, cmXCodeObject::ATTRIBUTE_GROUP);
cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
cmXCodeObject* developBuildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle,
cmXCodeObject::OBJECT);
cmXCodeObject* developBuildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle);
developBuildStyle->AddAttribute("name", this->CreateString("Development"));
developBuildStyle->AddAttribute("buildSettings", group);
group = this->CreateObject(cmXCodeObject::None, cmXCodeObject::ATTRIBUTE_GROUP);
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("YES"));
cmXCodeObject* deployBuildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle,
cmXCodeObject::OBJECT);
cmXCodeObject* deployBuildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle);
deployBuildStyle->AddAttribute("name", this->CreateString("Deployment"));
deployBuildStyle->AddAttribute("buildSettings", group);
cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::None,
cmXCodeObject::OBJECT_LIST);
cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
listObjs->AddObject(developBuildStyle);
listObjs->AddObject(deployBuildStyle);
m_RootObject = this->CreateObject(cmXCodeObject::PBXProject, cmXCodeObject::OBJECT);
group = this->CreateObject(cmXCodeObject::None, cmXCodeObject::ATTRIBUTE_GROUP);
m_RootObject = this->CreateObject(cmXCodeObject::PBXProject);
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
m_RootObject->AddAttribute("buildSettings", group);
m_RootObject->AddAttribute("buildSyles", listObjs);
m_RootObject->AddAttribute("hasScannedForEncodings", this->CreateString("0"));
std::vector<cmXCodeObject*> targets;
for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();
i != generators.end(); ++i)
{
this->CreateXCodeTargets(*i, targets);
}
cmXCodeObject* allTargets = this->CreateObject(cmXCodeObject::OBJECT_LIST);
for(std::vector<cmXCodeObject*>::iterator i = targets.begin();
i != targets.end(); ++i)
{
allTargets->AddObject(*i);
}
m_RootObject->AddAttribute("targets", allTargets);
}
//----------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@
#include "cmGlobalGenerator.h"
#include "cmXCodeObject.h"
class cmTarget;
class cmSourceFile;
/** \class cmGlobalXCodeGenerator
* \brief Write a Unix makefiles.
@ -66,7 +67,8 @@ public:
private:
// 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, cmXCodeObject::Type type);
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
cmXCodeObject* CreateObject(cmXCodeObject::Type type);
cmXCodeObject* CreateString(const char* s);
// delete all objects in the m_XCodeObjects vector.
@ -78,6 +80,8 @@ private:
void WriteXCodePBXProj(std::ostream& fout,
cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, cmSourceFile* sf);
void CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
std::vector<cmXCodeObject*> m_XCodeObjects;
cmXCodeObject* m_RootObject;

View File

@ -14,6 +14,8 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
m_IsA = ptype;
cmOStringStream str;
str << (void*)this;
str << (void*)this;
str << (void*)this;
m_Id = str.str();
m_Type = type;
if(m_Type == OBJECT)
@ -40,7 +42,6 @@ void cmXCodeObject::Print(std::ostream& out)
std::map<cmStdString, cmXCodeObject*>::iterator i;
for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
{
cmXCodeObject* object = i->second;
cmXCodeObject::Indent(3, out);
if(i->first == "isa")
@ -78,7 +79,10 @@ void cmXCodeObject::Print(std::ostream& out)
{
out << i->first << " = " << object->m_String << ";\n";
}
else
{
out << "what is this?? " << i->first << "\n";
}
}
cmXCodeObject::Indent(2, out);
out << "};\n";