summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-05-16 14:21:06 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-05-16 14:21:06 (GMT)
commit567ca4c79ecfa5665c475d9176d682908bade012 (patch)
tree5976ed5ffb85de79b10269d982925bb3f8e67438 /Source
parent57151fba6a66513237ab8de36a6b723007c5570a (diff)
parenta339ea652952666182d2e63ddce088d023e2a5f5 (diff)
downloadCMake-567ca4c79ecfa5665c475d9176d682908bade012.zip
CMake-567ca4c79ecfa5665c475d9176d682908bade012.tar.gz
CMake-567ca4c79ecfa5665c475d9176d682908bade012.tar.bz2
Merge topic 'xcode-file-type'
a339ea65 Xcode: Add source file property to control file type (#14854) ae80cb9f Xcode: Refactor internal source file type selection
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx77
-rw-r--r--Source/cmGlobalXCodeGenerator.h6
2 files changed, 50 insertions, 33 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index d44da37..e5fc436 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -647,13 +647,14 @@ cmXCodeObject*
cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
const std::string &fullpath,
cmTarget& cmtarget,
- const std::string &lang)
+ const std::string &lang,
+ cmSourceFile* sf)
{
// 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);
+ this->CreateXCodeFileReferenceFromPath(fullpath, cmtarget, lang, sf);
cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile);
buildFile->SetComment(fileRef->GetComment());
@@ -696,7 +697,7 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
cmXCodeObject* buildFile =
- this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang);
+ this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang, sf);
cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject();
cmXCodeObject* settings =
@@ -828,7 +829,8 @@ cmXCodeObject*
cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
const std::string &fullpath,
cmTarget& cmtarget,
- const std::string &lang)
+ const std::string &lang,
+ cmSourceFile* sf)
{
std::string fname = fullpath;
cmXCodeObject* fileRef = this->FileRefs[fname];
@@ -848,36 +850,49 @@ cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
}
fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
- // Compute the extension.
- std::string ext;
- std::string realExt =
- cmSystemTools::GetFilenameLastExtension(fullpath);
- if(!realExt.empty())
+ bool useLastKnownFileType = false;
+ std::string fileType;
+ if(sf)
{
- // Extension without the leading '.'.
- ext = realExt.substr(1);
- }
-
- // If fullpath references a directory, then we need to specify
- // lastKnownFileType as folder in order for Xcode to be able to open the
- // contents of the folder (Xcode 4.6 does not like explicitFileType=folder).
- if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
- {
- fileRef->AddAttribute("lastKnownFileType",
- this->CreateString("folder"));
+ if(const char* e = sf->GetProperty("XCODE_EXPLICIT_FILE_TYPE"))
+ {
+ fileType = e;
+ }
+ else if(const char* l = sf->GetProperty("XCODE_LAST_KNOWN_FILE_TYPE"))
+ {
+ useLastKnownFileType = true;
+ fileType = l;
+ }
}
- else
+ if(fileType.empty())
{
- bool keepLastKnownFileType = false;
- std::string sourcecode = GetSourcecodeValueFromFileExtension(ext,
- lang, keepLastKnownFileType);
- const char* attribute = keepLastKnownFileType ?
- "lastKnownFileType" :
- "explicitFileType";
- fileRef->AddAttribute(attribute,
- this->CreateString(sourcecode.c_str()));
+ // If fullpath references a directory, then we need to specify
+ // lastKnownFileType as folder in order for Xcode to be able to
+ // open the contents of the folder.
+ // (Xcode 4.6 does not like explicitFileType=folder).
+ if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
+ {
+ fileType = "folder";
+ useLastKnownFileType = true;
+ }
+ else
+ {
+ // Compute the extension without leading '.'.
+ std::string ext = cmSystemTools::GetFilenameLastExtension(fullpath);
+ if(!ext.empty())
+ {
+ ext = ext.substr(1);
+ }
+
+ fileType = GetSourcecodeValueFromFileExtension(
+ ext, lang, useLastKnownFileType);
+ }
}
+ fileRef->AddAttribute(useLastKnownFileType? "lastKnownFileType"
+ : "explicitFileType",
+ this->CreateString(fileType));
+
// Store the file path relative to the top of the source tree.
std::string path = this->RelativeToSource(fullpath.c_str());
std::string name = cmSystemTools::GetFilenameName(path.c_str());
@@ -902,7 +917,7 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf,
this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
return this->CreateXCodeFileReferenceFromPath(
- sf->GetFullPath(), cmtarget, lang);
+ sf->GetFullPath(), cmtarget, lang, sf);
}
//----------------------------------------------------------------------------
@@ -1052,7 +1067,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
{
std::string obj = *oi;
cmXCodeObject* xsf =
- this->CreateXCodeSourceFileFromPath(obj, cmtarget, "");
+ this->CreateXCodeSourceFileFromPath(obj, cmtarget, "", 0);
externalObjFiles.push_back(xsf);
}
}
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index 23616b4..c9937ed 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -163,10 +163,12 @@ private:
std::vector<cmLocalGenerator*>& generators);
cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string &fullpath,
cmTarget& cmtarget,
- const std::string &lang);
+ const std::string &lang,
+ cmSourceFile* sf);
cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string &fullpath,
cmTarget& cmtarget,
- const std::string &lang);
+ const std::string &lang,
+ cmSourceFile* sf);
cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf,
cmTarget& cmtarget);
cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen,