Xcode: CMake adds same file multiple times
The project has multiple targets (for example: macos, ios). Some sources are shared between the targets. When CMake creates XCode project, it creates separate fileRef for common sources. This causes problems with XCode. For example, autocomplete does not work.
XCode project should only contain one fileRef per file, and multiple PBXBuildFile point to this single fileRef.
cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath
has a map that keeps track of what fileRefs have been created, using the key calculated by
cmGlobalXCodeGenerator::GetGroupMapKeyFromPath
, but the latter creates the key per-target, not per-project.
If we change GetGroupMapKeyFromPath:
static std::string GetGroupMapKeyFromPath(cmGeneratorTarget* target,
const std::string& fullpath)
{
- std::string key(target->GetName());
- key += "-";
- key += fullpath;
- return key;
+ return fullpath;
}
We get the wanted behaviour, except empty groups are created under the targets. The source tree should also be per-project, not per-target.