Apple: generate_apple_platform_selection_file per-architecture dispatch
Splitting discussion out of #25262 (comment 1444954), in which @alcroito wrote:
The limitation is that the generated file differentiates only based on platform name, but not on architecture. That means that different architecture object files need to be
lipo
-ed into one file per platform before they can be used with the platform selection file. In principle that's not a problem, I confirmed it's possible to do. But it gets a bit weird if each architecture build is done separately.Taking
iOS
as an example, I do 3 builds:iphoneos sdk + arm64
,iphonesimulator sdk + x86_64
,iphonesimulator sdk + arm64
. The object files are installed in the following locations:$CMAKE_INSTALL_PREFIX1/lib/obj/lib/iphonesimulator-arm64/objects-Release/mytgt/obj1.cpp.o $CMAKE_INSTALL_PREFIX2/lib/obj/lib/iphonesimulator-x86_64/objects-Release/mytgt/obj1.cpp.o $CMAKE_INSTALL_PREFIX3/lib/obj/lib/iphoneos-arm64/objects-Release/mytgt/obj1.cpp.o
I also generate
mytgtTargets.cmake
files for each of those, and they specify theIMPORTED_OBJECTS_RELEASE
properties with the paths above.Now if i want to move those into an
xcframework
-ified SDK, and use thegenerate_apple_platform_selection_file
file to select between them, i need to firstlipo
theiphonesimulator-arm64
andiphonesimulator-x86_64
and keep one of the two file paths, to keep the generated paths inmytgtTargets.cmake
valid.The file path on disk will thus not reflect the reality of the file actually containing 2 architectures.
You could say, don't add the architecture to the directory name when doing the per-arch builds, and i guess that's one way around the confusion, but you'd still need the extra
lipo
-ing of the object files.So I was thinking if we could avoid the need for the
lipo
-ing object files entirely, and also keep the platform+arch specific names, by changinggenerate_apple_platform_selection_file
to optionally accommodate for architecture as well.Perhaps something like
generate_apple_platform_selection_file("${platform_selection_path}" INSTALL_DESTINATION "${dest}" MACOS_CONFIG_FILE "lib/macos/cmake/mylib/mylib-targets.cmake" IOS_ARCHITECTURES "arm64" IOS_CONFIG_FILES "lib/iphoneos/cmake/mylib/mylib-targets.cmake" IOS_SIMULATOR_ARCHITECTURES "arm64;x86_64" IOS_SIMULATOR_CONFIG_FILES "lib/iphonesimulator-arm64/cmake/mylib/mylib-targets.cmake;lib/iphonesimulator-x86_64/cmake/mylib/mylib-targets.cmake" IOS_SIMULATOR_CONFIG_FILE "lib/iphonesimulator/cmake/mylib/mylib-targets.cmake" )
where path 0 of the
CONFIG_FILES
would be chosen if currentCMAKE_OSX_ARCHITECTURES
== value 0 of givenARCHITECTURES
option, same with 1, and a fallback to the singularCONFIG_FILE
.
Also, in #25262 (comment 1445714), @alcroito wrote:
When I say "platforms", I consider iOS and iOS Simulator to be different platforms.
Same.
Are you trying to
lipo
together iOS and iOS Simulator builds? That doesn't make sense to me.No. Sorry about the confusion. No lipo-ing of simulator and device builds. In fact, I'd like to avoid lipo-ing of the object files entirely.
Within the same platform, I would still expect to be able to set
CMAKE_OSX_ARCHITECTURES
to all the arches you want to build for on that platform, and be able to have the same compile definitions and such.99% the that's the case, but talking about simulator arm64 vs x86_64, in Qt code we sometimes need to pass different compile definitions to different arches for example in code related to JIT-ing (because that's what the 3rd party code expects).
That's why i want to avoid passing 2 architectures to
CMAKE_OSX_ARCHITECTURES
, as well as avoid lipo-ing due the file path confusion and all the extra complexity that comes with it, for little gain.