diff options
author | David Cole <david.cole@kitware.com> | 2012-03-15 16:05:31 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2012-03-16 18:23:13 (GMT) |
commit | be01f3b098a69570cc382501a3895f424c4a608f (patch) | |
tree | 4e4e7430e5b523d939363c8ca32eae45ae70bef5 /Source | |
parent | 34e4985eed3589a4f7ad7dfc14a7a8aa10c8ff97 (diff) | |
download | CMake-be01f3b098a69570cc382501a3895f424c4a608f.zip CMake-be01f3b098a69570cc382501a3895f424c4a608f.tar.gz CMake-be01f3b098a69570cc382501a3895f424c4a608f.tar.bz2 |
Xcode: Re-factor some existing methods into "FromPath" variants
...to avoid depending on cmSourceFile instances. Prep work for supporting
OBJECT_LIBRARY in the Xcode generator.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 158 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.h | 6 |
2 files changed, 116 insertions, 48 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 7660ffa..4ba0350 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -561,15 +561,43 @@ cmXCodeObject* cmGlobalXCodeGenerator } //---------------------------------------------------------------------------- -cmStdString GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf) +cmStdString +GetGroupMapKeyFromPath(cmTarget& cmtarget, const std::string& fullpath) { cmStdString key(cmtarget.GetName()); key += "-"; - key += sf->GetFullPath(); + key += fullpath; return key; } //---------------------------------------------------------------------------- +cmStdString +GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf) +{ + return GetGroupMapKeyFromPath(cmtarget, sf->GetFullPath()); +} + +//---------------------------------------------------------------------------- +cmXCodeObject* +cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath( + const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang) +{ + // Using a map and the full path guarantees that we will always get the same + // fileRef object for any given full path. + // + cmXCodeObject* fileRef = + this->CreateXCodeFileReferenceFromPath(fullpath, cmtarget, lang); + + cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile); + buildFile->SetComment(fileRef->GetComment()); + buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef)); + + return buildFile; +} + +//---------------------------------------------------------------------------- cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, cmSourceFile* sf, @@ -603,14 +631,16 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, flags += flagsBuild.GetString(); } - // Using a map and the full path guarantees that we will always get the same - // fileRef object for any given full path. - // - cmXCodeObject* fileRef = this->CreateXCodeFileReference(sf, cmtarget); + const char* lang = + this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); + if (!lang) + { + lang = ""; + } - cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile); - buildFile->SetComment(fileRef->GetComment()); - buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef)); + cmXCodeObject* buildFile = + this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang); + cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject(); cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); @@ -662,36 +692,12 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, } //---------------------------------------------------------------------------- -cmXCodeObject* -cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, - cmTarget& cmtarget) +std::string +GetSourcecodeValueFromFileExtension(const std::string& _ext, + const std::string& lang) { - std::string fname = sf->GetFullPath(); - cmXCodeObject* fileRef = this->FileRefs[fname]; - if(!fileRef) - { - fileRef = this->CreateObject(cmXCodeObject::PBXFileReference); - std::string comment = fname; - //comment += " in "; - //std::string gname = group->GetObject("name")->GetString(); - //comment += gname.substr(1, gname.size()-2); - fileRef->SetComment(fname.c_str()); - this->FileRefs[fname] = fileRef; - } - cmStdString key = GetGroupMapKey(cmtarget, sf); - cmXCodeObject* group = this->GroupMap[key]; - cmXCodeObject* children = group->GetObject("children"); - if (!children->HasObject(fileRef)) - { - children->AddObject(fileRef); - } - fileRef->AddAttribute("fileEncoding", this->CreateString("4")); - - const char* lang = - this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); + std::string ext = cmSystemTools::LowerCase(_ext); std::string sourcecode = "sourcecode"; - std::string ext = sf->GetExtension(); - ext = cmSystemTools::LowerCase(ext); if(ext == "o") { @@ -726,25 +732,25 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, { sourcecode += ".cpp.h"; } - else if(lang && strcmp(lang, "CXX") == 0) + else if(ext == "png" || ext == "gif" || ext == "jpg") { - sourcecode += ".cpp.cpp"; + sourcecode = "image"; } - else if(lang && strcmp(lang, "C") == 0) + else if(ext == "txt") { - sourcecode += ".c.c"; + sourcecode += ".text"; } - else if(lang && strcmp(lang, "Fortran") == 0) + else if(lang == "CXX") { - sourcecode += ".fortran.f90"; + sourcecode += ".cpp.cpp"; } - else if(ext == "png" || ext == "gif" || ext == "jpg") + else if(lang == "C") { - sourcecode = "image"; + sourcecode += ".c.c"; } - else if(ext == "txt") + else if(lang == "Fortran") { - sourcecode += ".text"; + sourcecode += ".fortran.f90"; } //else // { @@ -754,11 +760,51 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, // // valid lastKnownFileType value. // } + return sourcecode; +} + +//---------------------------------------------------------------------------- +cmXCodeObject* +cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath( + const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang) +{ + std::string fname = fullpath; + cmXCodeObject* fileRef = this->FileRefs[fname]; + if(!fileRef) + { + fileRef = this->CreateObject(cmXCodeObject::PBXFileReference); + std::string comment = fname; + fileRef->SetComment(fname.c_str()); + this->FileRefs[fname] = fileRef; + } + cmStdString key = GetGroupMapKeyFromPath(cmtarget, fullpath); + cmXCodeObject* group = this->GroupMap[key]; + cmXCodeObject* children = group->GetObject("children"); + if (!children->HasObject(fileRef)) + { + children->AddObject(fileRef); + } + fileRef->AddAttribute("fileEncoding", this->CreateString("4")); + + // Compute the extension. + std::string ext; + std::string realExt = + cmSystemTools::GetFilenameLastExtension(fullpath); + if(!realExt.empty()) + { + // Extension without the leading '.'. + ext = realExt.substr(1); + } + + std::string sourcecode = GetSourcecodeValueFromFileExtension(ext, lang); + fileRef->AddAttribute("lastKnownFileType", this->CreateString(sourcecode.c_str())); // Store the file path relative to the top of the source tree. - std::string path = this->RelativeToSource(sf->GetFullPath().c_str()); + std::string path = this->RelativeToSource(fullpath.c_str()); std::string name = cmSystemTools::GetFilenameName(path.c_str()); const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())? "<absolute>" : "SOURCE_ROOT"); @@ -773,6 +819,22 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, } //---------------------------------------------------------------------------- +cmXCodeObject* +cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, + cmTarget& cmtarget) +{ + const char* lang = + this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); + if (!lang) + { + lang = ""; + } + + return this->CreateXCodeFileReferenceFromPath( + sf->GetFullPath(), cmtarget, lang); +} + +//---------------------------------------------------------------------------- bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname) { if(tname == "ALL_BUILD" || tname == "XCODE_DEPEND_HELPER" || diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 393cd47..2004514 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -153,6 +153,12 @@ private: std::vector<cmLocalGenerator*>& generators); void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators); + cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang); + cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang); cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf, cmTarget& cmtarget); cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, |