From 3a97fe256ceb05eb8e9335e5ed6879b74b01f11d Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Fri, 14 Jul 2023 19:30:05 +0200 Subject: [PATCH] clang: Provide --target option when determining path to runtime library Clang/LLVM is natively a cross-compiler, so one set of applications can compile code to all supported targets. The default target can be changed using '--target' option. CMake supports this type of compilers. To change compiling target, one should set CMAKE_C_COMPILER_TARGET accorgindly. The '--target' option has impact on the path to clang-rt library returned by compiler when run with '--print-libgcc-file-name' option. Without specifying target, Clang will return path to runtime library of the host target (e.g. x86_64-pc-linux-gnu). Signed-off-by: Patryk Duda --- cmake/compiler/clang/target.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/compiler/clang/target.cmake b/cmake/compiler/clang/target.cmake index ada96392f8e..2289856941f 100644 --- a/cmake/compiler/clang/target.cmake +++ b/cmake/compiler/clang/target.cmake @@ -32,6 +32,10 @@ if(NOT "${ARCH}" STREQUAL "posix") include(${ZEPHYR_BASE}/cmake/compiler/clang/target_arm.cmake) endif() + if(DEFINED CMAKE_C_COMPILER_TARGET) + set(clang_target_flag "--target=${CMAKE_C_COMPILER_TARGET}") + endif() + foreach(file_name include/stddef.h) execute_process( COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name} @@ -57,7 +61,8 @@ if(NOT "${ARCH}" STREQUAL "posix") # This libgcc code is partially duplicated in compiler/*/target.cmake execute_process( - COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name + COMMAND ${CMAKE_C_COMPILER} ${clang_target_flag} ${TOOLCHAIN_C_FLAGS} + --print-libgcc-file-name OUTPUT_VARIABLE RTLIB_FILE_NAME OUTPUT_STRIP_TRAILING_WHITESPACE )