iOS architectures flexibility, global ONLY_ACTIVE_ARCH ignored
Before new iOS/tvOS/appleOS support was introduced, I was specifying iOS architectures this way:
# old-approach.cmake
set(CMAKE_OSX_SYSROOT "iphoneos" CACHE STRING "System root for iOS" FORCE)
set(__iphoneos_archs "armv7 armv7s arm64")
set(__iphonesimulator_archs "i386 x86_64")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] "${__iphoneos_archs}")
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] "${__iphoneos_archs}")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}")
set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] "${__iphonesimulator_archs}")
Next Xcode project will be generated using this toolchain:
- "Build Active Architecture Only" (
ONLY_ACTIVE_ARCH
) will be set toYES
- When I choose arm64 device and click Run - only arm64 will be built
- When I choose armv7 device and click Run - only armv7 will be built
- When I choose x86_64 simulator and click Run - only x86_64 will be built
- When I switch global project
ONLY_ACTIVE_ARCH
toNO
it will be applied to all targets
Note that I don't have to touch CMake code. All this happens in single Xcode instance and there is no project re-generation involved. Also if I generate a project with CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=YES
- ONLY_ACTIVE_ARCH
will be set to YES
everywhere in Xcode project.
As far as I understand with new iOS support it should look like this:
# new-approach.cmake
set(CMAKE_SYSTEM_NAME "iOS" CACHE STRING "System name" FORCE)
set(__iphoneos_archs armv7 armv7s arm64)
set(__iphonesimulator_archs i386 x86_64)
set(
CMAKE_OSX_ARCHITECTURES
"${__iphoneos_archs};${__iphonesimulator_archs}"
# ...
)
However, in a generated Xcode project:
-
ONLY_ACTIVE_ARCH
set toNO
for each target. When I switch a global project setting toYES
it doesn't affect any targets - I have to switch it for every target manually - Generating project with
CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=YES
will not have any effects
Environment:
- Xcode 10.1
- CMake 3.14.0-rc4
- Example: https://github.com/forexample/new-ios-toolchain
I have tried to remove modification of the ONLY_ACTIVE_ARCH
to apply Xcode defaults:
- https://gitlab.kitware.com/cmake/cmake/blob/v3.14.0-rc4/Source/cmGlobalXCodeGenerator.cxx#L1908
- https://gitlab.kitware.com/cmake/cmake/blob/v3.14.0-rc4/Source/cmGlobalXCodeGenerator.cxx#L3143
Error while configuring with CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=YES
:
No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=arm64 arm64e armv7 armv7s)
I guess it's not that simple :) Any hints are welcome.