I suspect this is CMake Issue 21845. On macOS arm64, all binaries have to be signed before running. In local development, the linker adds an ad-hoc placeholder signature. In Xcode however, the ad-hoc signature is delayed until after the “Run Script” build phase, so the POST_BUILD
command added by gtest_discover_tests
cannot run.
Fortunately, gtest_discover_tests
supports delaying test discovery until test time:
-gtest_discover_tests("${target_test}")
+gtest_discover_tests("${target_test}" DISCOVERY_MODE PRE_TEST)