Skip to content

Commit a27d82e

Browse files
MikhailSiomintpambor
authored andcommitted
cmake: fix build using clang when default and target arch do not match
Use CMAKE_C_COMPILER_TARGET to allow clang to correctly determine the runtime library for the target architecture. Otherwise, the default runtime library will be selected. Signed-off-by: Mikhail Siomin <[email protected]>
1 parent f3c12db commit a27d82e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cmake/compiler/clang/target.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ if(NOT "${ARCH}" STREQUAL "posix")
3636
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_riscv.cmake)
3737
endif()
3838

39-
if(DEFINED CMAKE_C_COMPILER_TARGET)
40-
set(clang_target_flag "--target=${CMAKE_C_COMPILER_TARGET}")
41-
endif()
42-
4339
foreach(file_name include/stddef.h)
4440
execute_process(
4541
COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}

cmake/compiler/target_template.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ if(NOT COMMAND compiler_file_path)
5252

5353
compiler_simple_options(simple_options)
5454

55+
if(DEFINED CMAKE_C_COMPILER_TARGET)
56+
set(target_flag "--target=${CMAKE_C_COMPILER_TARGET}")
57+
endif()
58+
5559
execute_process(
5660
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} ${COMPILER_OPTIMIZATION_FLAG} ${simple_options}
61+
${target_flag}
5762
--print-file-name ${filename}
5863
OUTPUT_VARIABLE filepath
5964
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -80,10 +85,15 @@ if(NOT COMMAND compiler_set_linker_properties)
8085

8186
compiler_simple_options(simple_options)
8287

88+
if(DEFINED CMAKE_C_COMPILER_TARGET)
89+
set(target_flag "--target=${CMAKE_C_COMPILER_TARGET}")
90+
endif()
91+
8392
# Compute complete path to the runtime library using the
8493
# --print-libgcc-file-name compiler flag
8594
execute_process(
8695
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} ${COMPILER_OPTIMIZATION_FLAG} ${simple_options}
96+
${target_flag}
8797
--print-libgcc-file-name
8898
OUTPUT_VARIABLE library_path
8999
OUTPUT_STRIP_TRAILING_WHITESPACE

0 commit comments

Comments
 (0)