Default settings for Xcode generator and Xcode 11 lead to failure
Since CMake 3.14, it should be possible to set just CMAKE_SYSTEM_NAME
to iOS
, tvOS
or watchOS
and the project should configure successfully. That appears to be the case for Xcode 9 and Xcode 10, but with Xcode 11 you get a failure at configure time if anything tries to do a try_compile()
. Already reported examples often mention find_package(Threads)
as one common case (e.g. #18993, #19112 (closed)). The failures usually relate to code signing being active in the try_compile()
, either as part of compiler checks or as part of calls like those made by find_package(Threads)
. After experimenting with various Xcode and CMake versions today, it seems that when using the Xcode generator, you really want to have the variable CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED
set to false during any try_compile()
call. You don't want it set for the main part of the build though, because you will likely have code signing enabled for your main app or library targets.
A workaround toolchain file is already given in #20013 (comment 731872), but its more minimal form is simply this:
set(CMAKE_SYSTEM_NAME iOS) # works for tvOS or watchOS too
get_property(__in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE)
if(__in_try_compile)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
endif()
unset(__in_try_compile)
I'm struggling to think of a valid reason why we shouldn't just get CMake to define this during try_compile()
calls altogether. If we wanted to be ultra-conservative, I guess we could set the variable only if it isn't already defined. I propose we do this for CMake 3.18, not sure if a policy would be needed or not though. I took a bit of a look in the various platform files, etc. to see if there was an obvious place to do something like this. I see some existing logic in a few places which only affect compiler feature detection for things like _CMAKE_FEATURE_DETECTION_TARGET_TYPE
, but not try_compile()
in general. It isn't clear to me exactly where something like this proposed change should go.