1# SPDX-License-Identifier: Apache-2.0
2
3zephyr_get(ARCMWDT_TOOLCHAIN_PATH)
4
5set(METAWARE_ROOT $ENV{METAWARE_ROOT})
6if(NOT DEFINED ARCMWDT_TOOLCHAIN_PATH AND DEFINED METAWARE_ROOT)
7  message(STATUS "ARCMWDT_TOOLCHAIN_PATH is not set, use default toolchain from METAWARE_ROOT: '${METAWARE_ROOT}'")
8  if(NOT EXISTS ${METAWARE_ROOT})
9    message(FATAL_ERROR "Nothing found at METAWARE_ROOT: '${METAWARE_ROOT}'")
10  endif()
11  cmake_path(GET METAWARE_ROOT PARENT_PATH ARCMWDT_TOOLCHAIN_PATH)
12elseif(NOT DEFINED ARCMWDT_TOOLCHAIN_PATH AND NOT DEFINED METAWARE_ROOT)
13  message(FATAL_ERROR "No MWDT toolchain specified: neither ARCMWDT_TOOLCHAIN_PATH nor METAWARE_ROOT defined")
14endif()
15
16if(NOT EXISTS ${ARCMWDT_TOOLCHAIN_PATH})
17  message(FATAL_ERROR "Nothing found at ARCMWDT_TOOLCHAIN_PATH: '${ARCMWDT_TOOLCHAIN_PATH}'")
18endif()
19
20# arcmwdt relies on Zephyr SDK for the use of C preprocessor (devicetree) and objcopy
21find_package(Zephyr-sdk 0.15 REQUIRED)
22# Handling to be improved in Zephyr SDK, we can drop setting TOOLCHAIN_HOME after
23# https://github.com/zephyrproject-rtos/sdk-ng/pull/682 got merged and we switch to proper SDK
24# version.
25set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR})
26include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/target.cmake)
27set(ZEPHYR_SDK_CROSS_COMPILE ${CROSS_COMPILE})
28# Handling to be improved in Zephyr SDK, to avoid overriding ZEPHYR_TOOLCHAIN_VARIANT by
29# find_package(Zephyr-sdk) if it's already set
30set(ZEPHYR_TOOLCHAIN_VARIANT arcmwdt)
31
32set(TOOLCHAIN_HOME ${ARCMWDT_TOOLCHAIN_PATH}/MetaWare)
33
34set(COMPILER arcmwdt)
35set(LINKER arcmwdt)
36set(BINTOOLS arcmwdt)
37
38set(SYSROOT_TARGET arc)
39
40set(CROSS_COMPILE ${TOOLCHAIN_HOME}/arc/bin/)
41set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
42
43set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")
44