|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +set(NOSTDINC "") |
| 4 | + |
| 5 | +# Note that NOSYSDEF_CFLAG may be an empty string, and |
| 6 | +# set_ifndef() does not work with empty string. |
| 7 | +if(NOT DEFINED NOSYSDEF_CFLAG) |
| 8 | + set(NOSYSDEF_CFLAG -undef) |
| 9 | +endif() |
| 10 | + |
| 11 | +find_program(CMAKE_C_COMPILER "${CROSS_COMPILE}clang" PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH REQUIRED) |
| 12 | +find_program(CMAKE_CXX_COMPILER "${CROSS_COMPILE}clang++" PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH REQUIRED) |
| 13 | + |
| 14 | +if(SYSROOT_DIR) |
| 15 | + # The toolchain has specified a sysroot dir, pass it to the compiler |
| 16 | + list(APPEND TOOLCHAIN_C_FLAGS "--sysroot=${SYSROOT_DIR}") |
| 17 | + list(APPEND TOOLCHAIN_LD_FLAGS "--sysroot=${SYSROOT_DIR}") |
| 18 | +endif() |
| 19 | + |
| 20 | +include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake) |
| 21 | +include(${ZEPHYR_BASE}/cmake/gcc-m-fpu.cmake) |
| 22 | + |
| 23 | +include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_riscv.cmake) |
| 24 | + |
| 25 | +execute_process( |
| 26 | + COMMAND ${CMAKE_C_COMPILER} --version |
| 27 | + OUTPUT_VARIABLE full_version_output |
| 28 | + ) |
| 29 | + |
| 30 | +string(REGEX REPLACE ".*clang version ([0-9]+(\\.[0-9]+)*).*" "\\1" CLANG_COMPILER_VERSION "${full_version_output}") |
| 31 | + |
| 32 | +# Clang < 17 doesn't support zicsr, zifencei in -march, strip them. |
| 33 | +if(CLANG_COMPILER_VERSION VERSION_LESS "17.0.0") |
| 34 | + foreach(var TOOLCHAIN_C_FLAGS TOOLCHAIN_LD_FLAGS LLEXT_APPEND_FLAGS) |
| 35 | + list(TRANSFORM ${var} REPLACE "^-march=([^ ]*)_zicsr([^ ]*)$" "-march=\\1\\2") |
| 36 | + list(TRANSFORM ${var} REPLACE "^-march=([^ ]*)_zifencei([^ ]*)$" "-march=\\1\\2") |
| 37 | + endforeach() |
| 38 | +endif() |
| 39 | + |
| 40 | +foreach(file_name include/stddef.h) |
| 41 | + execute_process( |
| 42 | + COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name} |
| 43 | + OUTPUT_VARIABLE _OUTPUT |
| 44 | + ) |
| 45 | + get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY) |
| 46 | + string(REGEX REPLACE "\n" "" _OUTPUT ${_OUTPUT}) |
| 47 | + |
| 48 | + list(APPEND NOSTDINC ${_OUTPUT}) |
| 49 | +endforeach() |
| 50 | + |
| 51 | +foreach(isystem_include_dir ${NOSTDINC}) |
| 52 | + list(APPEND isystem_include_flags -isystem "\"${isystem_include_dir}\"") |
| 53 | +endforeach() |
| 54 | + |
| 55 | +list(APPEND CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags}) |
| 56 | +string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") |
| 57 | + |
| 58 | +include(${ZEPHYR_BASE}/cmake/compiler/andes/common.cmake) |
0 commit comments