ENH: fixes for xcode21 and build styles and comments in the generated project

This commit is contained in:
Bill Hoffman 2005-11-16 13:13:39 -05:00
parent 7a1745b84b
commit 8b7091a0a6
4 changed files with 163 additions and 46 deletions

View File

@ -462,11 +462,20 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
lg->AppendFlags(flags, sf->GetProperty("COMPILE_FLAGS"));
cmXCodeObject* fileRef = this->CreateObject(cmXCodeObject::PBXFileReference);
cmXCodeObject* group = m_GroupMap[sf];
cmXCodeObject* children = group->GetObject("children");
children->AddObject(fileRef);
// m_SourcesGroupChildren->AddObject(fileRef);
cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
std::string fname = sf->GetSourceName();
fname += ".";
fname += sf->GetSourceExtension();
std::string comment = fname;
comment += " in ";
std::string gname = group->GetObject("name")->GetString();
comment += gname.substr(1, gname.size()-2);
buildFile->SetComment(comment.c_str());
fileRef->SetComment(fname.c_str());
buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef));
cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags.c_str()));
@ -518,7 +527,10 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
fileRef->AddAttribute("name", this->CreateString(file.c_str()));
fileRef->AddAttribute("path", this->CreateString(path.c_str()));
fileRef->AddAttribute("refType", this->CreateString("4"));
if(m_XcodeVersion == 15)
{
fileRef->AddAttribute("refType", this->CreateString("4"));
}
if(path.size() > 1 && path[0] == '.' && path[1] == '.')
{
fileRef->AddAttribute("sourceTree", this->CreateString("<group>"));
@ -590,6 +602,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
sourceBuildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647"));
sourceBuildPhase->SetComment("Sources");
cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
sourceBuildPhase->AddAttribute("files", buildFiles);
sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
@ -621,6 +634,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
// create header build phase
cmXCodeObject* headerBuildPhase =
this->CreateObject(cmXCodeObject::PBXHeadersBuildPhase);
headerBuildPhase->SetComment("Headers");
headerBuildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647"));
buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
@ -636,6 +650,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
// create framework build phase
cmXCodeObject* frameworkBuildPhase =
this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
frameworkBuildPhase->SetComment("Frameworks");
frameworkBuildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647"));
buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
@ -1235,6 +1250,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
"# shell script goes here\nexit 0"));
cmXCodeObject* target =
this->CreateObject(cmXCodeObject::PBXAggregateTarget);
target->SetComment(cmtarget.GetName());
cmXCodeObject* buildPhases =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
this->CreateCustomCommands(buildPhases, 0, 0, 0, cmtarget);
@ -1269,11 +1285,16 @@ void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
std::vector<std::string> configVector;
configVectorIn.push_back(configTypes);
cmSystemTools::ExpandList(configVectorIn, configVector);
configVector.push_back("Default");
cmXCodeObject* configlist = this->CreateObject(cmXCodeObject::XCConfigurationList);
cmXCodeObject* buildConfigurations =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
configlist->AddAttribute("buildConfigurations", buildConfigurations);
std::string comment = "Build configuration list for ";
comment += cmXCodeObject::PBXTypeNames[target->GetIsA()];
comment += " \"";
comment += cmtarget.GetName();
comment += "\"";
configlist->SetComment(comment.c_str());
target->AddAttribute("buildConfigurationList",
this->CreateObjectReference(configlist));
for(unsigned int i = 0; i < configVector.size(); ++i)
@ -1290,8 +1311,15 @@ void cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
buildSettings, fileTypeString,
productTypeString, productName, buildtype.c_str());
config->AddAttribute("name", this->CreateString(configVector[i].c_str()));
config->SetComment(configVector[i].c_str());
config->AddAttribute("buildSettings", buildSettings);
}
if(configVector.size())
{
configlist->AddAttribute("defaultConfigurationName",
this->CreateString(configVector[0].c_str()));
configlist->AddAttribute("defaultConfigurationIsVisible", this->CreateString("0"));
}
}
//----------------------------------------------------------------------------
@ -1329,7 +1357,7 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget,
fileRef->AddAttribute("refType", this->CreateString("0"));
fileRef->AddAttribute("sourceTree",
this->CreateString("BUILT_PRODUCTS_DIR"));
fileRef->SetComment(cmtarget.GetName());
target->AddAttribute("productReference",
this->CreateObjectReference(fileRef));
target->AddAttribute("productType",
@ -1383,6 +1411,7 @@ void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
{
cmXCodeObject* container =
this->CreateObject(cmXCodeObject::PBXContainerItemProxy);
container->SetComment("PBXContainerItemProxy");
container->AddAttribute("containerPortal",
this->CreateObjectReference(m_RootObject));
container->AddAttribute("proxyType", this->CreateString("1"));
@ -1393,6 +1422,7 @@ void cmGlobalXCodeGenerator::AddDependTarget(cmXCodeObject* target,
dependTarget->GetcmTarget()->GetName()));
targetdep =
this->CreateObject(cmXCodeObject::PBXTargetDependency);
targetdep->SetComment("PBXTargetDependency");
targetdep->AddAttribute("target",
this->CreateObjectReference(dependTarget));
targetdep->AddAttribute("targetProxy",
@ -1713,7 +1743,10 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(cmTarget& cmtarget,
this->CreateObject(cmXCodeObject::OBJECT_LIST);
tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
tgroup->AddAttribute("children", tgroupChildren);
tgroup->AddAttribute("refType", this->CreateString("4"));
if(m_XcodeVersion == 15)
{
tgroup->AddAttribute("refType", this->CreateString("4"));
}
tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
m_SourcesGroupChildren->AddObject(tgroup);
}
@ -1724,7 +1757,10 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(cmTarget& cmtarget,
this->CreateObject(cmXCodeObject::OBJECT_LIST);
group->AddAttribute("name", this->CreateString(sg->GetName()));
group->AddAttribute("children", groupChildren);
group->AddAttribute("refType", this->CreateString("4"));
if(m_XcodeVersion == 15)
{
group->AddAttribute("refType", this->CreateString("4"));
}
group->AddAttribute("sourceTree", this->CreateString("<group>"));
tgroupChildren->AddObject(group);
m_GroupNameMap[s] = group;
@ -1752,6 +1788,7 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
else
{
developBuildStyle->AddAttribute("name", this->CreateString("Debug"));
developBuildStyle->SetComment("Debug");
}
developBuildStyle->AddAttribute("buildSettings", group);
@ -1766,6 +1803,7 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
else
{
deployBuildStyle->AddAttribute("name", this->CreateString("Release"));
deployBuildStyle->SetComment("Release");
}
deployBuildStyle->AddAttribute("buildSettings", group);
@ -1773,12 +1811,14 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
listObjs->AddObject(developBuildStyle);
listObjs->AddObject(deployBuildStyle);
cmXCodeObject* mainGroup = this->CreateObject(cmXCodeObject::PBXGroup);
m_MainGroupChildren =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
mainGroup->AddAttribute("children", m_MainGroupChildren);
mainGroup->AddAttribute("refType", this->CreateString("4"));
if(m_XcodeVersion == 15)
{
mainGroup->AddAttribute("refType", this->CreateString("4"));
}
mainGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
cmXCodeObject* sourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
@ -1786,7 +1826,10 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
this->CreateObject(cmXCodeObject::OBJECT_LIST);
sourcesGroup->AddAttribute("name", this->CreateString("Sources"));
sourcesGroup->AddAttribute("children", m_SourcesGroupChildren);
sourcesGroup->AddAttribute("refType", this->CreateString("4"));
if(m_XcodeVersion == 15)
{
sourcesGroup->AddAttribute("refType", this->CreateString("4"));
}
sourcesGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
m_MainGroupChildren->AddObject(sourcesGroup);
// now create the cmake groups
@ -1794,7 +1837,10 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
cmXCodeObject* productGroup = this->CreateObject(cmXCodeObject::PBXGroup);
productGroup->AddAttribute("name", this->CreateString("Products"));
productGroup->AddAttribute("refType", this->CreateString("4"));
if(m_XcodeVersion == 15)
{
productGroup->AddAttribute("refType", this->CreateString("4"));
}
productGroup->AddAttribute("sourceTree", this->CreateString("<group>"));
cmXCodeObject* productGroupChildren =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
@ -1803,31 +1849,35 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
m_RootObject = this->CreateObject(cmXCodeObject::PBXProject);
m_RootObject->SetComment("Project object");
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
m_RootObject->AddAttribute("mainGroup",
this->CreateObjectReference(mainGroup));
m_RootObject->AddAttribute("buildSettings", group);
m_RootObject->AddAttribute("buildSyles", listObjs);
m_RootObject->AddAttribute("buildStyles", listObjs);
m_RootObject->AddAttribute("hasScannedForEncodings",
this->CreateString("0"));
cmXCodeObject* configlist = this->CreateObject(cmXCodeObject::XCConfigurationList);
cmXCodeObject* configDebug = this->CreateObject(cmXCodeObject::XCBuildConfiguration);
cmXCodeObject* configRelease = this->CreateObject(cmXCodeObject::XCBuildConfiguration);
cmXCodeObject* configDefault = this->CreateObject(cmXCodeObject::XCBuildConfiguration);
cmXCodeObject* buildConfigurations =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
buildConfigurations->AddObject(configDebug);
buildConfigurations->AddObject(configRelease);
buildConfigurations->AddObject(configDefault);
configlist->AddAttribute("buildConfigurations", buildConfigurations);
std::string comment = "Build configuration list for PBXProject ";
comment += " \"";
comment += m_CurrentProject;
comment += "\"";
configlist->SetComment(comment.c_str());
configlist->AddAttribute("defaultConfigurationIsVisible", this->CreateString("0"));
configlist->AddAttribute("defaultConfigurationName", this->CreateString("Debug"));
cmXCodeObject* buildSettings =
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
configDebug->AddAttribute("name", this->CreateString("Debug"));
configDebug->AddAttribute("buildSettings", buildSettings);
configRelease->AddAttribute("name", this->CreateString("Release"));
configRelease->AddAttribute("buildSettings", buildSettings);
configDefault->AddAttribute("name", this->CreateString("Default"));
configDefault->AddAttribute("buildSettings", buildSettings);
m_RootObject->AddAttribute("buildConfigurationList",
this->CreateObjectReference(configlist));
@ -1972,8 +2022,8 @@ cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
xcodeDir += "proj";
}
cmSystemTools::MakeDirectory(xcodeDir.c_str());
xcodeDir += "/project.pbxproj";
cmGeneratedFileStream fout(xcodeDir.c_str());
std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
cmGeneratedFileStream fout(xcodeProjFile.c_str());
fout.SetCopyIfDifferent(true);
if(!fout)
{

View File

@ -1,14 +1,27 @@
#include "cmXCode21Object.h"
#include "cmSystemTools.h"
cmXCode21Object::cmXCode21Object(PBXType ptype, Type type)
:cmXCodeObject(ptype, type)
{
m_Version = 21;
}
//----------------------------------------------------------------------------
void cmXCode21Object::PrintComment(std::ostream& out)
{
out << "/* */";
if(m_Comment.size() == 0)
{
cmXCodeObject* n = this->GetObject("name");
if(n)
{
m_Comment = n->GetString();
cmSystemTools::ReplaceString(m_Comment, "\"", "");
}
}
out << "/* ";
out << m_Comment;
out << " */";
}
@ -29,7 +42,7 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v, std::ostre
{
return;
}
out << "/* Begin " << PBXTypeNames[t] << " section */\n";
out << "\n/* Begin " << PBXTypeNames[t] << " section */\n";
for(std::vector<cmXCodeObject*>::const_iterator i = v.begin();
i != v.end(); ++i)
{
@ -56,9 +69,9 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v, std::ostre
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXHeadersBuildPhase);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXNativeTarget);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXProject);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXSourcesBuildPhase);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXShellScriptBuildPhase);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXResourcesBuildPhase);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXSourcesBuildPhase);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXApplicationReference);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXExecutableFileReference);
cmXCode21Object::PrintList(v, out, cmXCode21Object::PBXLibraryReference);

View File

@ -14,12 +14,14 @@ const char* cmXCodeObject::PBXTypeNames[] = {
cmXCodeObject::~cmXCodeObject()
{
m_Version = 15;
}
//----------------------------------------------------------------------------
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
m_Version = 15;
m_PBXTargetDependency = 0;
m_cmTarget = 0;
m_Object =0;
@ -67,56 +69,84 @@ void cmXCodeObject::Indent(int level, std::ostream& out)
//----------------------------------------------------------------------------
void cmXCodeObject::Print(std::ostream& out)
{
cmXCodeObject::Indent(2, out);
std::string separator = "\n";
int indentFactor = 1;
if(m_Version > 15 && (m_IsA == PBXFileReference || m_IsA == PBXBuildFile))
{
separator = " ";
indentFactor = 0;
}
cmXCodeObject::Indent(2*indentFactor, out);
out << m_Id << " ";
this->PrintComment(out);
out << " = {\n";
if(!(this->m_IsA == PBXGroup && this->m_Comment.size() == 0))
{
this->PrintComment(out);
}
out << " = {";
if(separator == "\n")
{
out << separator;
}
std::map<cmStdString, cmXCodeObject*>::iterator i;
cmXCodeObject::Indent(3*indentFactor, out);
out << "isa = " << PBXTypeNames[m_IsA] << ";" << separator;
for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
{
cmXCodeObject* object = i->second;
cmXCodeObject::Indent(3, out);
if(i->first == "isa")
if(i->first != "isa")
{
out << i->first << " = " << PBXTypeNames[m_IsA] << ";\n";
cmXCodeObject::Indent(3*indentFactor, out);
}
else if(object->m_Type == OBJECT_LIST)
else
{
out << i->first << " = (\n";
continue;
}
if(object->m_Type == OBJECT_LIST)
{
out << i->first << " = (" << separator;
for(unsigned int k = 0; k < i->second->m_List.size(); k++)
{
cmXCodeObject::Indent(4, out);
out << i->second->m_List[k]->m_Id << ",\n";
cmXCodeObject::Indent(4*indentFactor, out);
out << i->second->m_List[k]->m_Id << " ";
i->second->m_List[k]->PrintComment(out);
out << "," << separator;
}
cmXCodeObject::Indent(3, out);
out << ");\n";
cmXCodeObject::Indent(3*indentFactor, out);
out << ");" << separator;
}
else if(object->m_Type == ATTRIBUTE_GROUP)
{
std::map<cmStdString, cmXCodeObject*>::iterator j;
out << i->first << " = {\n";
out << i->first << " = {" << separator;
for(j = object->m_ObjectAttributes.begin(); j != object->m_ObjectAttributes.end(); ++j)
{
cmXCodeObject::Indent(4, out);
out << j->first << " = " << j->second->m_String << ";\n";
cmXCodeObject::Indent(4 *indentFactor, out);
out << j->first << " = " << j->second->m_String << ";";
out << separator;
}
cmXCodeObject::Indent(3, out);
out << "};\n";
cmXCodeObject::Indent(3 *indentFactor, out);
out << "};" << separator;
}
else if(object->m_Type == OBJECT_REF)
{
out << i->first << " = " << object->m_Object->m_Id << ";\n";
out << i->first << " = " << object->m_Object->m_Id;
if(object->m_Object->HasComment() && i->first != "remoteGlobalIDString")
{
out << " ";
object->m_Object->PrintComment(out);
}
out << ";" << separator;
}
else if(object->m_Type == STRING)
{
out << i->first << " = " << object->m_String << ";\n";
out << i->first << " = " << object->m_String << ";" << separator;
}
else
{
out << "what is this?? " << i->first << "\n";
}
}
cmXCodeObject::Indent(2, out);
cmXCodeObject::Indent(2*indentFactor, out);
out << "};\n";
}
@ -146,3 +176,27 @@ void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
this->m_Object = copy->m_Object;
}
void cmXCodeObject::SetString(const char* s)
{
std::string ss = s;
if(ss.size() == 0)
{
m_String = "\"\"";
return;
}
bool needQuote = false;
m_String = "";
if(ss.find_first_of(" <>.+") != ss.npos)
{
needQuote = true;
}
if(needQuote)
{
m_String = "\"";
}
m_String += s;
if(needQuote)
{
m_String += "\"";
}
}

View File

@ -24,12 +24,7 @@ public:
Type GetType() { return m_Type;}
PBXType GetIsA() { return m_IsA;}
void SetString(const char* s)
{
m_String = "\"";
m_String += s;
m_String += "\"";
}
void SetString(const char* s);
const char* GetString()
{
return m_String.c_str();
@ -80,6 +75,8 @@ public:
{
m_cmTarget = t;
}
const char* GetComment() {return m_Comment.c_str();}
bool HasComment() { return (m_Comment.size() != 0);}
cmXCodeObject* GetObject(const char* name)
{
if(m_ObjectAttributes.count(name))
@ -122,11 +119,14 @@ public:
return m_DependLibraries;
}
std::vector<cmXCodeObject*> const& GetObjectList() { return m_List;}
void SetComment(const char* c) { m_Comment = c;}
protected:
cmTarget* m_cmTarget;
Type m_Type;
cmStdString m_Id;
PBXType m_IsA;
int m_Version;
cmStdString m_Comment;
cmStdString m_String;
cmXCodeObject* m_Object;
cmXCodeObject* m_PBXTargetDependency;