Skip to content

Commit 6354891

Browse files
committed
cmake: Add LLVM toolchain support
This commit adds the support file for the `zephyr-llvm` toolchain variant. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 073761c commit 6354891

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

cmake/Zephyr-sdkConfig.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ set(SDK_MAJOR_MINOR_MICRO ${SDK_VERSION})
1111

1212
get_filename_component(ZEPHYR_SDK_INSTALL_DIR ${CMAKE_CURRENT_LIST_DIR}/.. ABSOLUTE)
1313
set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR})
14-
set(ZEPHYR_TOOLCHAIN_VARIANT zephyr-gnu)
14+
15+
if(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT)
16+
set(ZEPHYR_TOOLCHAIN_VARIANT zephyr-gnu)
17+
endif()
1518

1619
# Those are CMake package parameters.
1720
set(Zephyr-sdk_FOUND True)

cmake/zephyr/Kconfig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ config TOOLCHAIN_ZEPHYR_0_17
44
def_bool y
55
# FIXME: Newlib-nano is disabled for Xtensa targets due to the memset
66
# bug causing crashes (see the GitHub issue #660).
7-
select HAS_NEWLIB_LIBC_NANO if !XTENSA
7+
select HAS_NEWLIB_LIBC_NANO if !XTENSA \
8+
&& "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "zephyr-llvm"
89

910
config TOOLCHAIN_ZEPHYR_SUPPORTS_THREAD_LOCAL_STORAGE
1011
def_bool y
@@ -16,6 +17,7 @@ config TOOLCHAIN_ZEPHYR_SUPPORTS_GNU_EXTENSIONS
1617

1718
config PICOLIBC_SUPPORTED
1819
def_bool y
19-
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr-gnu"
20+
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr-gnu" \
21+
|| "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr-llvm"
2022
help
2123
Zephyr SDK >=0.16 always supports Picolibc for C and C++ development.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2023 The ChromiumOS Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
--rtlib=compiler-rt

cmake/zephyr/llvm/generic.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
set(LLVM_TOOLCHAIN_PATH ${ZEPHYR_SDK_INSTALL_DIR}/llvm)
4+
5+
set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR}/llvm/bin)
6+
7+
set(COMPILER clang)
8+
set(LINKER lld)
9+
set(BINTOOLS llvm)
10+
11+
set(TOOLCHAIN_HAS_PICOLIBC ON CACHE BOOL "True if toolchain supports picolibc")

cmake/zephyr/llvm/target.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if("${ARCH}" STREQUAL "arm")
4+
if(DEFINED CONFIG_ARMV8_M_MAINLINE)
5+
# ARMv8-M mainline is ARMv7-M with additional features from ARMv8-M.
6+
set(triple armv8m.main-none-eabi)
7+
elseif(DEFINED CONFIG_ARMV8_M_BASELINE)
8+
# ARMv8-M baseline is ARMv6-M with additional features from ARMv8-M.
9+
set(triple armv8m.base-none-eabi)
10+
elseif(DEFINED CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
11+
# ARMV7_M_ARMV8_M_MAINLINE means that ARMv7-M or backward compatible ARMv8-M
12+
# processor is used.
13+
set(triple armv7m-none-eabi)
14+
elseif(DEFINED CONFIG_ARMV6_M_ARMV8_M_BASELINE)
15+
# ARMV6_M_ARMV8_M_BASELINE means that ARMv6-M or ARMv8-M supporting the
16+
# Baseline implementation processor is used.
17+
set(triple armv6m-none-eabi)
18+
else()
19+
# Default ARM target supported by all processors.
20+
set(triple arm-none-eabi)
21+
endif()
22+
elseif("${ARCH}" STREQUAL "arm64")
23+
set(triple aarch64-none-elf)
24+
# TODO: Add RISC-V target support.
25+
endif()
26+
27+
if(DEFINED triple)
28+
set(CMAKE_C_COMPILER_TARGET ${triple})
29+
set(CMAKE_ASM_COMPILER_TARGET ${triple})
30+
set(CMAKE_CXX_COMPILER_TARGET ${triple})
31+
32+
unset(triple)
33+
endif()
34+
35+
list(APPEND TOOLCHAIN_C_FLAGS --config
36+
${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/clang_compiler_rt.cfg)
37+
list(APPEND TOOLCHAIN_LD_FLAGS --config
38+
${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/clang_compiler_rt.cfg)

0 commit comments

Comments
 (0)