Skip to content

Xcode: Use deterministic object ids for targets

When a CMake-generated Xcode project is included in another Xcode project, the used targets' object UUIDs are kept as remoteGlobalIDString. So whenever CMake regenerates the project, Xcode copies over that new UUID in the parent project and that creates unnecessary changes in git (and it's hard to deal with even if cmake doesn't run that often as everyone's computer wants to use a different id).

This is the fragment of code that changes in the parent project's pbxproj when the target is used as a dependency for another target:

DCAF7BD629F99E4400F1A1F9 /* PBXContainerItemProxy */ = {
    isa = PBXContainerItemProxy;
    containerPortal = B090E5C21EB8F9C00049FBB4 /* cmake-generated-subproject.xcodeproj */;
    proxyType = 1;
    remoteGlobalIDString = FBE1E1C73EC14DF890D6DA0E /* <--- this changes whenever cmake runs */;
    remoteInfo = transitLib;
};

The topic of generating deterministic UUIDs for Xcode has been discussed here already: https://discourse.cmake.org/t/deterministic-ids-in-the-xcode-generator-to-avoid-unnecessary-rebuilds/1870

Ideally every Xcode object's id would be deterministically generated, but doing it for PBXNativeTarget is a quick fix that addresses the biggest pain point for us (and I see we're not alone).

Topic-rename: xcode-deterministic-target-objects

Edited by Brad King

Merge request reports