Skip to content

Commit

Permalink
make cross compilation possible on macOS with CMake
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
busterb committed Jul 4, 2023
1 parent 71ce0b8 commit 2203c13
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,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")
Expand Down

0 comments on commit 2203c13

Please sign in to comment.