diff --git a/gcc.cmake b/gcc.cmake index f47aa9814..61947dc95 100644 --- a/gcc.cmake +++ b/gcc.cmake @@ -117,13 +117,19 @@ if("${CROSS_COMPILER_PREFIX}" STREQUAL "") endif() if("${CROSS_COMPILER_PREFIX}" STREQUAL "") - # If we haven't set a target above we assume x86_64/ia32 target - if(CMAKE_HOST_APPLE) - # CMAKE_HOST_APPLE is a CMake variable that evaluates to True on a Mac OSX system - FindPrefixedGCC(CROSS_COMPILER_PREFIX "x86_64-linux-gnu-" "x86_64-unknown-linux-gnu-") - elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64") - # If we're on an aarch64 host, gcc won't support x86. Set an x86 compatible toolchain - FindPrefixedGCC(CROSS_COMPILER_PREFIX "x86_64-linux-gnu-" "x86_64-unknown-linux-gnu-") + # If we haven't set a target above we assume x86_64/ia32 target, and hence have to + # find an appropriate x86 compatible toolchain. If we're on an AArch64 host, GCC will + # not support x86. If we're on macOS (detected via CMAKE_HOST_APPLE), we need to find + # the appropriate x86 compiler regardless of host architecture. This is as `gcc` + # usually actually uses clang on macOS, not GCC. + if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR CMAKE_HOST_APPLE) + if("${sel4_arch}" STREQUAL "ia32") + FindPrefixedGCC(CROSS_COMPILER_PREFIX "i686-linux-gnu-" "i686-unknown-linux-gnu-") + else() + FindPrefixedGCC( + CROSS_COMPILER_PREFIX "x86_64-linux-gnu-" "x86_64-unknown-linux-gnu-" + ) + endif() endif() endif() endif()