Add cross-compilation for arm64 on macOS (#8758)
[cvc5.git] / cmake / Toolchain-aarch64.cmake
index cec586246d1af76bb9662bb38243c60d5e7b72c1..9e8423691221f34f1337dca23dae910b8ea5f18f 100644 (file)
 # Use: cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-aarch64.cmake
 ##
 
-SET(CMAKE_SYSTEM_NAME Linux)
-SET(CMAKE_SYSTEM_PROCESSOR aarch64)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
 
-set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
+  set(CMAKE_SYSTEM_NAME Linux)
+  set(CMAKE_SYSTEM_PROCESSOR aarch64)
 
-SET(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
-SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
+  set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
 
-# Set target environment path
-SET(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
+  set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
+  set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
 
-# Adjust the default behaviour of the find_XXX() commands:
-# search headers and libraries in the target environment, search
-# programs in the host environment
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+  # Set target environment path
+  set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
+
+  # Adjust the default behaviour of the find_XXX() commands:
+  # search headers and libraries in the target environment, search
+  # programs in the host environment
+  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+
+  set(CMAKE_SYSTEM_NAME Darwin)
+  set(CMAKE_SYSTEM_PROCESSOR arm64)
+
+  set(TOOLCHAIN_PREFIX arm64-apple-darwin)
+
+  set(CMAKE_CROSSCOMPILING_MACOS TRUE)
+  set(CMAKE_OSX_ARCHITECTURES arm64 CACHE INTERNAL "")
+
+endif()