cmake: Fix macOS ARM64 -> x86_64 cross-compilation
./cerbero-uninstalled -c config/cross-macos-universal.cbc package gstreamer-1.0
was failing on M1 Macs when attempting to build cmake
based projects for x86_64. The part that was failing was the initial compiler functionality check, fail caused by:
[...]-x86_64.out and [...]-arm64.out have the same architectures (x86_64) and can't be in the same fat output file
Turns out, cmake
for some reason was adding an -arch=arm64
flag by default even when building for x86_64 which, alongside cerbero-added -arch=x86_64
, caused clang
to build for both architectures at once, and that later caused lipo
to fail when attempting to merge those into a single file (no idea why exactly, I found posts mentioning that an arm64
-targeted file can contain some other-arch code...).
However, this does not occur when going the other way around (x86 compiling for M1, e.g our CI) so there's a suspicion this might be a CMake bug. Might want to create an issue on their GitLab to check if that's the case.
Either way, the fix was to add a CMAKE_OSX_ARCHITECTURES
flag which specifies which architecture we're targeting exactly, thus getting rid of the wrong flag.