1# SPDX-License-Identifier: Apache-2.0
2
3zephyr_get(ESPRESSIF_TOOLCHAIN_PATH)
4assert(    ESPRESSIF_TOOLCHAIN_PATH "ESPRESSIF_TOOLCHAIN_PATH is not set")
5
6set(TOOLCHAIN_HOME ${ESPRESSIF_TOOLCHAIN_PATH})
7
8set(COMPILER gcc)
9set(LINKER ld)
10set(BINTOOLS gnu)
11
12# find some toolchain
13file(GLOB toolchain_paths
14  LIST_DIRECTORIES true
15  ${TOOLCHAIN_HOME}/*-esp32*/*-elf
16  ${TOOLCHAIN_HOME}/*-esp*/*-elf
17  )
18
19# Old toolchain installation path has been deprecated in 2.7.
20# This code and related code depending on ESPRESSIF_DEPRECATED_PATH can be removed after two releases.
21if(NOT toolchain_paths)
22  # find some toolchain
23  file(GLOB toolchain_paths
24    LIST_DIRECTORIES true
25    ${TOOLCHAIN_HOME}
26    )
27
28  set(ESPRESSIF_DEPRECATED_PATH TRUE)
29endif()
30
31if(toolchain_paths)
32  list(GET toolchain_paths 0 some_toolchain_path)
33
34  get_filename_component(one_toolchain_root "${some_toolchain_path}" DIRECTORY)
35  get_filename_component(one_toolchain "${some_toolchain_path}" NAME)
36
37  set(CROSS_COMPILE_TARGET ${one_toolchain})
38  set(SYSROOT_TARGET	   ${one_toolchain})
39
40  if(ESPRESSIF_DEPRECATED_PATH)
41    set(CROSS_COMPILE ${ESPRESSIF_TOOLCHAIN_PATH}/bin/${CROSS_COMPILE_TARGET}-)
42    set(SYSROOT_DIR   ${ESPRESSIF_TOOLCHAIN_PATH}/${SYSROOT_TARGET})
43  else()
44    set(CROSS_COMPILE ${one_toolchain_root}/bin/${CROSS_COMPILE_TARGET}-)
45    set(SYSROOT_DIR   ${one_toolchain_root}/${SYSROOT_TARGET})
46  endif()
47
48endif()
49
50if(NOT CROSS_COMPILE_TARGET)
51  message(FATAL_ERROR
52    "Unable to find toolchain in ${TOOLCHAIN_HOME} "
53    "Run `west espressif install` to download it. Then, export to path accordingly.")
54endif()
55
56set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
57