ENH: initial xcode stuff

This commit is contained in:
Bill Hoffman 2005-01-24 17:35:54 -05:00
parent a921ccaa2a
commit e57b17df7e
6 changed files with 344 additions and 26 deletions

View File

@ -0,0 +1,179 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmGlobalXCodeGenerator.h"
#include "cmLocalXCodeGenerator.h"
#include "cmMakefile.h"
#include "cmXCodeObject.h"
#include "cmake.h"
#include "cmGeneratedFileStream.h"
//----------------------------------------------------------------------------
cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
{
m_FindMakeProgramFile = "CMakeFindXCode.cmake";
m_RootObject = 0;
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const& lang,
cmMakefile *mf)
{
//this->cmGlobalGenerator::EnableLanguage(lang, mf);
}
//----------------------------------------------------------------------------
int cmGlobalXCodeGenerator::TryCompile(const char *,
const char *bindir,
const char *projectName,
const char *targetName,
std::string *output,
cmMakefile* mf)
{
// FIXME
return 1;
}
//----------------------------------------------------------------------------
///! Create a local generator appropriate to this Global Generator
cmLocalGenerator *cmGlobalXCodeGenerator::CreateLocalGenerator()
{
cmLocalGenerator *lg = new cmLocalXCodeGenerator;
lg->SetGlobalGenerator(this);
return lg;
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::Generate()
{
this->cmGlobalGenerator::Generate();
std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it)
{
this->OutputXCodeProject(it->second[0], it->second);
}
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::ClearXCodeObjects()
{
for(unsigned int i = 0; i < m_XCodeObjects.size(); ++i)
{
delete m_XCodeObjects[i];
}
m_XCodeObjects.clear();
}
//----------------------------------------------------------------------------
cmXCodeObject* cmGlobalXCodeGenerator::CreateObject(cmXCodeObject::PBXType ptype,
cmXCodeObject::Type type)
{
cmXCodeObject* obj = new cmXCodeObject(ptype, type);
m_XCodeObjects.push_back(obj);
return obj;
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>&
generators)
{
delete m_RootObject;
this->ClearXCodeObjects();
cmXCodeObject* group = this->CreateObject(cmXCodeObject::None, cmXCodeObject::ATTRIBUTE_GROUP);
group->AddAttribute("COPY_PHASE_STRIP", "NO");
cmXCodeObject* developBuildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle,
cmXCodeObject::OBJECT);
developBuildStyle->AddAttribute("name", "Development");
developBuildStyle->AddAttribute("buildSettings", group);
group = this->CreateObject(cmXCodeObject::None, cmXCodeObject::ATTRIBUTE_GROUP);
group->AddAttribute("COPY_PHASE_STRIP", "YES");
cmXCodeObject* deployBuildStyle = this->CreateObject(cmXCodeObject::PBXBuildStyle,
cmXCodeObject::OBJECT);
deployBuildStyle->AddAttribute("name", "Deployment");
deployBuildStyle->AddAttribute("buildSettings", group);
cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::None,
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->AddAttribute("buildSettings", group);
m_RootObject->AddAttribute("buildSyles", listObjs);
m_RootObject->AddAttribute("hasScannedForEncodings", "0");
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::OutputXCodeProject(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>&
generators)
{
if(generators.size() == 0)
{
return;
}
this->CreateXCodeObjects(root,
generators);
std::string xcodeDir = root->GetMakefile()->GetStartOutputDirectory();
xcodeDir += "/";
xcodeDir += root->GetMakefile()->GetProjectName();
xcodeDir += ".xcode";
cmSystemTools::MakeDirectory(xcodeDir.c_str());
xcodeDir += "/project.pbxproj";
cmGeneratedFileStream fout(xcodeDir.c_str());
fout.SetCopyIfDifferent(true);
if(!fout)
{
return;
}
this->WriteXCodePBXProj(fout, root, generators);
this->ClearXCodeObjects();
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
cmLocalGenerator* root,
std::vector<cmLocalGenerator*>&
generators)
{
fout << "// !$*UTF8*$!\n";
fout << "{\n";
cmXCodeObject::Indent(1, fout);
fout << "archiveVersion = 1;\n";
cmXCodeObject::Indent(1, fout);
fout << "classes = {\n";
cmXCodeObject::Indent(1, fout);
fout << "};\n";
cmXCodeObject::Indent(1, fout);
fout << "objectVersion = 39;\n";
cmXCodeObject::PrintList(m_XCodeObjects, fout);
cmXCodeObject::Indent(1, fout);
fout << "rootObject = " << m_RootObject->GetId() << ";\n";
fout << "}\n";
}
//----------------------------------------------------------------------------
void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry) const
{
entry.name = this->GetName();
entry.brief = "NOT YET WORKING, Will generates XCode project files.";
entry.full = "";
}

View File

@ -0,0 +1,81 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmGlobalXCodeGenerator_h
#define cmGlobalXCodeGenerator_h
#include "cmGlobalGenerator.h"
#include "cmXCodeObject.h"
class cmTarget;
/** \class cmGlobalXCodeGenerator
* \brief Write a Unix makefiles.
*
* cmGlobalXCodeGenerator manages UNIX build process for a tree
*/
class cmGlobalXCodeGenerator : public cmGlobalGenerator
{
public:
cmGlobalXCodeGenerator();
static cmGlobalGenerator* New() { return new cmGlobalXCodeGenerator; }
///! Get the name for the generator.
virtual const char* GetName() const {
return cmGlobalXCodeGenerator::GetActualName();}
static const char* GetActualName() {return "XCode";}
/** Get the documentation entry for this generator. */
virtual void GetDocumentation(cmDocumentationEntry& entry) const;
///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator();
/**
* Try to determine system infomation such as shared library
* extension, pthreads, byte order etc.
*/
virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
/**
* Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process.
*/
virtual int TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName,
std::string *output, cmMakefile* mf);
/**
* Generate the all required files for building this project/tree. This
* basically creates a series of LocalGenerators for each directory and
* requests that they Generate.
*/
virtual void Generate();
private:
cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype, cmXCodeObject::Type type);
void ClearXCodeObjects();
void CreateXCodeObjects(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
void OutputXCodeProject(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
void WriteXCodePBXProj(std::ostream& fout,
cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
std::vector<cmXCodeObject*> m_XCodeObjects;
cmXCodeObject* m_RootObject;
};
#endif

View File

@ -0,0 +1,10 @@
#include "cmLocalXCodeGenerator.h"
cmLocalXCodeGenerator::cmLocalXCodeGenerator()
{
}
cmLocalXCodeGenerator::~cmLocalXCodeGenerator()
{
}

View File

@ -0,0 +1,40 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmLocalXCodeGenerator_h
#define cmLocalXCodeGenerator_h
#include "cmLocalGenerator.h"
/** \class cmLocalXCodeGenerator
* \brief Write a local Xcode project
*
* cmLocalXCodeGenerator produces a LocalUnix makefile from its
* member m_Makefile.
*/
class cmLocalXCodeGenerator : public cmLocalGenerator
{
public:
///! Set cache only and recurse to false by default.
cmLocalXCodeGenerator();
virtual ~cmLocalXCodeGenerator();
private:
};
#endif

View File

@ -8,8 +8,7 @@ const char* cmXCodeObject::PBXTypeNames[] = {
"None"
};
std::vector<cmXCodeObject*> cmXCodeObject::s_AllObjects;
//----------------------------------------------------------------------------
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
m_IsA = ptype;
@ -17,10 +16,13 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
str << (void*)this;
m_Id = str.str();
m_Type = type;
cmXCodeObject::s_AllObjects.push_back(this);
if(m_Type == OBJECT)
{
this->AddAttribute("isa", PBXTypeNames[m_IsA]);
}
}
//----------------------------------------------------------------------------
void cmXCodeObject::Indent(int level, std::ostream& out)
{
while(level)
@ -30,9 +32,10 @@ void cmXCodeObject::Indent(int level, std::ostream& out)
}
}
//----------------------------------------------------------------------------
void cmXCodeObject::Print(std::ostream& out)
{
this->Indent(1, out);
cmXCodeObject::Indent(2, out);
out << m_Id << " = {\n";
std::map<cmStdString, cmXCodeObject*>::iterator i;
for(i = m_ObjectAttributes.begin(); i != m_ObjectAttributes.end(); ++i)
@ -40,58 +43,59 @@ void cmXCodeObject::Print(std::ostream& out)
cmXCodeObject* object = i->second;
if(object->m_Type == OBJECT_LIST)
{
this->Indent(2, out);
cmXCodeObject::Indent(3, out);
out << i->first << " = {\n";
for(unsigned int k = 0; k < i->second->m_List.size(); k++)
{
this->Indent(3, out);
cmXCodeObject::Indent(4, out);
out << i->second->m_List[k]->m_Id << ",\n";
}
this->Indent(2, out);
cmXCodeObject::Indent(3, out);
out << "};\n";
}
else if(object->m_Type == ATTRIBUTE_GROUP)
{
std::map<cmStdString, cmStdString>::iterator j;
this->Indent(2, out);
cmXCodeObject::Indent(3, out);
out << i->first << " = {\n";
for(j = object->m_StringAttributes.begin(); j != object->m_StringAttributes.end(); ++j)
{
this->Indent(3, out);
cmXCodeObject::Indent(4, out);
out << j->first << " = " << j->second << ";\n";
}
this->Indent(2, out);
out << " }\n";
cmXCodeObject::Indent(3, out);
out << "}\n";
}
else if(object->m_Type == OBJECT_REF)
{
this->Indent(2, out);
cmXCodeObject::Indent(3, out);
out << i->first << " = " << object->m_Object->m_Id << ";\n";
}
}
this->Indent(2, out);
out << "isa = " << PBXTypeNames[m_IsA] << ";\n";
std::map<cmStdString, cmStdString>::iterator j;
for(j = m_StringAttributes.begin(); j != m_StringAttributes.end(); ++j)
{
this->Indent(2, out);
cmXCodeObject::Indent(3, out);
out << j->first << " = " << j->second << ";\n";
}
this->Indent(1, out);
cmXCodeObject::Indent(2, out);
out << "};\n";
}
void cmXCodeObject::PrintAll(std::ostream& out)
{
//----------------------------------------------------------------------------
void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
std::ostream& out)
{
cmXCodeObject::Indent(1, out);
out << "objects = {\n";
for(unsigned int i = 0; i < s_AllObjects.size(); ++i)
for(unsigned int i = 0; i < objs.size(); ++i)
{
if(s_AllObjects[i]->m_Type == OBJECT)
if(objs[i]->m_Type == OBJECT)
{
s_AllObjects[i]->Print(out);
objs[i]->Print(out);
}
}
cmXCodeObject::Indent(1, out);
out << "};\n";
}

View File

@ -1,3 +1,6 @@
#ifndef cmXCodeObject_h
#define cmXCodeObject_h
#include "cmStandardIncludes.h"
class cmXCodeObject
@ -31,13 +34,14 @@ public:
{
m_List.push_back(value);
}
void Indent(int level, std::ostream& out);
static void Indent(int level, std::ostream& out);
void Print(std::ostream& out);
static void PrintAll(std::ostream& out);
static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);
const char* GetId()
{
return m_Id.c_str();
}
private:
Type m_Type;
cmStdString m_Id;
PBXType m_IsA;
@ -45,5 +49,5 @@ public:
std::vector<cmXCodeObject*> m_List;
std::map<cmStdString, cmXCodeObject*> m_ObjectAttributes;
std::map<cmStdString, cmStdString> m_StringAttributes;
static std::vector<cmXCodeObject*> s_AllObjects;
};
#endif