| 1348 | } |
| 1349 | |
| 1350 | cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath( |
| 1351 | std::string const& fullpath, cmGeneratorTarget* target, |
| 1352 | std::string const& lang, cmSourceFile* sf) |
| 1353 | { |
| 1354 | bool useLastKnownFileType = false; |
| 1355 | std::string fileType; |
| 1356 | if (sf) { |
| 1357 | if (cmValue e = sf->GetProperty("XCODE_EXPLICIT_FILE_TYPE")) { |
| 1358 | fileType = *e; |
| 1359 | } else if (cmValue l = sf->GetProperty("XCODE_LAST_KNOWN_FILE_TYPE")) { |
| 1360 | useLastKnownFileType = true; |
| 1361 | fileType = *l; |
| 1362 | } |
| 1363 | } |
| 1364 | // Make a copy so that we can override it later |
| 1365 | std::string path = cmSystemTools::CollapseFullPath(fullpath); |
| 1366 | if (fileType.empty()) { |
| 1367 | path = this->GetLibraryOrFrameworkPath(path); |
| 1368 | // Compute the extension without leading '.'. |
| 1369 | std::string ext = cmSystemTools::GetFilenameLastExtension(path); |
| 1370 | if (!ext.empty()) { |
| 1371 | ext = ext.substr(1); |
| 1372 | } |
| 1373 | // If fullpath references a directory, then we need to specify |
| 1374 | // lastKnownFileType as folder in order for Xcode to be able to |
| 1375 | // open the contents of the folder. |
| 1376 | // (Xcode 4.6 does not like explicitFileType=folder). |
| 1377 | if (cmSystemTools::FileIsDirectory(path)) { |
| 1378 | fileType = GetDirectoryValueFromFileExtension(ext); |
| 1379 | useLastKnownFileType = true; |
| 1380 | } else { |
| 1381 | if (ext.empty() && !sf) { |
| 1382 | // Special case for executable or library without extension |
| 1383 | // that is not a source file. We can't tell which without reading |
| 1384 | // its Mach-O header, but the file might not exist yet, so we |
| 1385 | // have to pick one here. |
| 1386 | useLastKnownFileType = true; |
| 1387 | fileType = "compiled.mach-o.executable"; |
| 1388 | } else { |
| 1389 | fileType = GetSourcecodeValueFromFileExtension( |
| 1390 | ext, lang, useLastKnownFileType, this->EnabledLangs); |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | std::string key = GetGroupMapKeyFromPath(target, path); |
| 1396 | cmXCodeObject* fileRef = this->FileRefs[key]; |
| 1397 | if (!fileRef) { |
| 1398 | fileRef = this->CreateObject(cmXCodeObject::PBXFileReference); |
| 1399 | fileRef->SetComment(path); |
| 1400 | this->FileRefs[key] = fileRef; |
| 1401 | } |
| 1402 | fileRef->AddAttribute("fileEncoding", this->CreateString("4")); |
| 1403 | fileRef->AddAttribute(useLastKnownFileType ? "lastKnownFileType" |
| 1404 | : "explicitFileType", |
| 1405 | this->CreateString(fileType)); |
| 1406 | // Store the file path relative to the top of the source tree. |
| 1407 | if (!IsLibraryType(fileType)) { |
no test coverage detected