From 83fdd2ee995f470cc66b4689d117dab53458feff Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Tue, 4 Jul 2023 12:36:57 +0300 Subject: [PATCH] make cross compilation possible on macOS with CMake Sync CMAKE_SYSTEM_PROCESSOR to CMAKE_OSX_ARCHITECTURES. This doesn't support universal binaries, but does allow cross-compiling for a single architecture by setting -DCMAKE_OSX_ARCHITECTURES=(arm64|x86_64) --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f35f89..ef99dc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,15 @@ if(HAVE_NETINET_IP_H) add_definitions(-DHAVE_NETINET_IP_H) endif() +# This isn't ready for universal binaries yet, since we do conditional +# compilation based on the architecture, but this makes cross compiling for a +# single architecture work on macOS at least. +# +# Don't set CMAKE_OSX_ARCHITECTURES to more than a single value for now. +if(APPLE) + set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}") +endif() + if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(aarch64|arm64)") set(HOST_AARCH64 true) elseif("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")