Wrong apple platform or variant when linking xcframework in 3.28+

Hi, I’m trying to use the new xcframework support for find_library and target_link_libraries for apple. I’m trying to build for both ios and ios-simulator, but I’m running into this xcode error with my generated project:

ld: building for 'iOS-simulator', but linking in object file (/<library path>/google-mobile-ads-sdk-ios/10.14.0/GoogleAppMeasurement.xcframework/ios-arm64/GoogleAppMeasurement.framework/GoogleAppMeasurement[3](apm_experimentation.pb.o)) built for 'iOS'

I have the relevant area in my cmake files:


# omitted...

        NAMES GoogleAppMeasurement
        PATHS "${THIRDPARTY_DIR}/google-mobile-ads-sdk-ios/${GMA_VERSION}"

target_link_libraries(<my target> PRIVATE "${GOOGLE_APP_MEASUREMENT_LIB}")

I have some sort of idea that I need to set some other variable to tell cmake what platform variant I’m using. I have set CMAKE_SYSTEM_NAME and I think that is somehow causing the ios-arm64 target to be selected, but I don’t know which variables I need to set to tell it to use the simulator target. (ios-arm64_x86_64-simulator in my case).

I’ve search a whole bunch, but there doesn’t seem to be much documentation, or that I’m not familiar enough with the ecosystem to know which terms to use. (Sorry, I’m new to this…)

Thank you for your attention!

Update: I found some relevant conversations in the CMake gitlab.

  1. https://gitlab.kitware.com/cmake/cmake/-/issues/21752#note_1440301

This looks like this person is having the same exact error. I’m not entirely sure I followed the chain, but it looks like the person’s problem was fixed. I’m using cmake 3.28.3, and looking into the repo, it looks like the relevant PR was included in this version, however, my build is still failing. I even tried setting CMAKE_XCODE_LINK_BUILD_PHASE_MODE to KNOWN_LOCATION, but there was no difference.

  1. https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8619#note_1399635

This person had a similar error in a slightly newer build, except instead of iOS and iOS-simulator, it’s between ios-arm64_x86_64-simulator and maccatalyst. Somehow the user’s issue was resolved, and I again confirmed that the mentioned PR was merged and included in 3.28.3.

The search continues…

Cc: @brad.king @kyle.edwards