Skip to content

Commit 12d2e2d

Browse files
committed
build: Support SYSROOT_DIR in native_sim and clang
When running naive sim builds using clang, respect user passed SYSROOT_DIR values. Additionally, allow overriding the archive tool when calling Make for the native simulator. Add the sysroot (if available) to the native_simulator target and TOOLCHAIN_C_FLAGS and TOOLCHAIN_LD_FLAGS. Additionally pass CMAKE_AR to NSI_AR. Signed-off-by: Yuval Peress <[email protected]>
1 parent 75d5074 commit 12d2e2d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

boards/native/common/natsim_config.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ get_property(CCACHE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
77
target_link_options(native_simulator INTERFACE
88
"-T ${ZEPHYR_BASE}/boards/native/common/natsim_linker_script.ld")
99

10+
if(SYSROOT_DIR)
11+
message(NOTICE "Appending --sysroot=${SYSROOT_DIR} to native_simulator")
12+
target_compile_options(native_simulator INTERFACE "--sysroot=${SYSROOT_DIR}")
13+
target_link_options(native_simulator INTERFACE "--sysroot=${SYSROOT_DIR}")
14+
endif()
15+
1016
set(nsi_config_content
1117
${nsi_config_content}
18+
"NSI_AR:=${CMAKE_AR}"
1219
"NSI_BUILD_OPTIONS:=$<JOIN:$<TARGET_PROPERTY:native_simulator,INTERFACE_COMPILE_OPTIONS>,\ >"
1320
"NSI_BUILD_PATH:=${zephyr_build_path}/NSI"
1421
"NSI_CC:=${CCACHE} ${CMAKE_C_COMPILER}"
@@ -21,9 +28,11 @@ set(nsi_config_content
2128
"NSI_PATH:=${NSI_DIR}/"
2229
"NSI_N_CPUS:=${CONFIG_NATIVE_SIMULATOR_NUMBER_MCUS}"
2330
"NSI_LOCALIZE_OPTIONS:=--localize-symbol=CONFIG_* $<JOIN:$<TARGET_PROPERTY:native_simulator,LOCALIZE_EXTRA_OPTIONS>,\ >"
31+
"NSI_BUILD_VERBOSE:=1"
2432
)
2533

2634
string(REPLACE ";" "\n" nsi_config_content "${nsi_config_content}")
35+
message(NOTICE "NSI Config:\n${nsi_config_content}")
2736

2837
file(GENERATE OUTPUT "${zephyr_build_path}/NSI/nsi_config"
2938
CONTENT "${nsi_config_content}"

cmake/compiler/clang/target.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ endif()
1818
find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
1919
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})
2020

21+
if(SYSROOT_DIR)
22+
# The toolchain has specified a sysroot dir, pass it to the compiler
23+
list(APPEND TOOLCHAIN_C_FLAGS "--sysroot=${SYSROOT_DIR}")
24+
list(APPEND TOOLCHAIN_LD_FLAGS "--sysroot=${SYSROOT_DIR}")
25+
endif()
26+
2127
if(NOT "${ARCH}" STREQUAL "posix")
2228
include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
2329
include(${ZEPHYR_BASE}/cmake/gcc-m-fpu.cmake)
@@ -72,7 +78,8 @@ if(NOT "${ARCH}" STREQUAL "posix")
7278
#
7379
# Other clang/LLVM distributions may come with other pre-built C libraries.
7480
# clang/LLVM supports using an alternative C library, either by direct linking,
75-
# or by specifying '--sysroot <path>'.
81+
# or by specifying '--sysroot <path>'. Sysroot can also be passed using the
82+
# CMake variable SYSROOT_DIR which will append the '--sysroot <path>' flags.
7683
#
7784
# LLVM for Arm provides a 'newlib.cfg' file for newlib C selection.
7885
# Let us support this principle by looking for a dedicated 'newlib.cfg' or

0 commit comments

Comments
 (0)