From dc5b6b6a74ee6ec7a3b02866fa0f9e7b85b31b70 Mon Sep 17 00:00:00 2001 From: maybe-sybr <58414429+maybe-sybr@users.noreply.github.com> Date: Wed, 4 Dec 2019 12:39:56 +1100 Subject: [PATCH] Add support for arm Xcompilers on Red Hat distros This change introduces a `gcc` hunting helper function to `gcc.cmake` in order to help us find an appropriately prefixed `gcc` for the target being built for. We use this helper to find 32b ARM cross-compiling `gcc`s for both Debian and Red Hat based distros. --- gcc.cmake | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/gcc.cmake b/gcc.cmake index c6d3b8e1f..d6668e152 100644 --- a/gcc.cmake +++ b/gcc.cmake @@ -26,10 +26,31 @@ set(sel4_arch @KernelSel4Arch@) set(arch @KernelArch@) set(mode @KernelWordSize@) +# This function hunts for an extant `gcc` with one of the candidate prefixes +# specified in `ARGN`, allowing us to try different target triple prefixes for +# cross-compilers built in various ways. +function(FindPrefixedGCC out_var) + set("${out_var}" "PrefixedGCC-NOTFOUND") + foreach(prefix ${ARGN}) + set("test_var" "_GCC_${prefix}") + find_program("${test_var}" "${prefix}gcc") + if(${test_var}) + message(STATUS "Found GCC with prefix ${prefix}") + set("${out_var}" "${prefix}") + break() + endif() + endforeach() + if(${out_var}) + set("${out_var}" "${${out_var}}" PARENT_SCOPE) + else() + message(FATAL_ERROR "Unable to find valid cross-compiling GCC") + endif() +endfunction(FindPrefixedGCC) + if("${CROSS_COMPILER_PREFIX}" STREQUAL "") if(("${arch}" STREQUAL "arm") OR ("${arch}" STREQUAL "x86") OR ("${arch}" STREQUAL "riscv")) if(${sel4_arch} STREQUAL "aarch32" OR ${sel4_arch} STREQUAL "arm_hyp") - set(CROSS_COMPILER_PREFIX "arm-linux-gnueabi-" CACHE INTERNAL "") + FindPrefixedGCC(CROSS_COMPILER_PREFIX "arm-linux-gnueabi-" "arm-linux-gnu-") elseif(${sel4_arch} STREQUAL "aarch64") set(CROSS_COMPILER_PREFIX "aarch64-linux-gnu-" CACHE INTERNAL "") elseif(${arch} STREQUAL "riscv") @@ -40,7 +61,7 @@ if("${CROSS_COMPILER_PREFIX}" STREQUAL "") # If initialised with -DCMAKE_TOOLCHAIN_FILE="$SCRIPT_PATH/gcc.cmake" this script # understood the following arguments: ARM, AARCH32, AARCH32HF, AARCH64, RISCV32, RISCV64, APPLE if(AARCH32 OR ARM) - set(CROSS_COMPILER_PREFIX "arm-linux-gnueabi-" CACHE INTERNAL "") + FindPrefixedGCC(CROSS_COMPILER_PREFIX "arm-linux-gnueabi-" "arm-linux-gnu-") if(ARM) message("ARM flag is deprecated, please use AARCH32") endif() @@ -51,7 +72,11 @@ if("${CROSS_COMPILER_PREFIX}" STREQUAL "") endif() endif() if(AARCH32HF) - set(CROSS_COMPILER_PREFIX "arm-linux-gnueabihf-" CACHE INTERNAL "") + FindPrefixedGCC( + CROSS_COMPILER_PREFIX + "arm-linux-gnueabihf-" + "arm-linux-gnu-" # Later checks should confirm this has `hardfp` + ) endif() if("${CROSS_COMPILER_PREFIX}" STREQUAL "")