1# SPDX-License-Identifier: Apache-2.0 2 3# Purpose of the generic.cmake is to define a generic C compiler which can be 4# used for devicetree pre-processing and other pre-processing tasks which must 5# be performed before the target can be determined. 6 7# Todo: deprecate CLANG_ROOT_DIR 8set_ifndef(LLVM_TOOLCHAIN_PATH "$ENV{CLANG_ROOT_DIR}") 9zephyr_get(LLVM_TOOLCHAIN_PATH) 10 11if(LLVM_TOOLCHAIN_PATH) 12 set(TOOLCHAIN_HOME ${LLVM_TOOLCHAIN_PATH}/bin/) 13endif() 14 15set(LLVM_TOOLCHAIN_PATH ${CLANG_ROOT_DIR} CACHE PATH "clang install directory") 16 17set(COMPILER clang) 18set(BINTOOLS llvm) 19 20# LLVM is flexible, meaning that it can in principle always support newlib or picolibc. 21# This is not decided by LLVM itself, but depends on libraries distributed with the installation. 22# Also newlib or picolibc may be created as add-ons. Thus always stating that LLVM does not have 23# newlib or picolibc would be wrong. Same with stating that LLVM has newlib or Picolibc. 24# The best assumption for TOOLCHAIN_HAS_<NEWLIB|PICOLIBC> is to check for the presence of 25# '_newlib_version.h' / 'picolibc' and have the default value set accordingly. 26# This provides a best effort mechanism to allow developers to have the newlib C / Picolibc library 27# selection available in Kconfig. 28# Developers can manually indicate library support with '-DTOOLCHAIN_HAS_<NEWLIB|PICOLIBC>=<ON|OFF>' 29 30# Support for newlib is indicated by the presence of '_newlib_version.h' in the toolchain path. 31if(NOT LLVM_TOOLCHAIN_PATH STREQUAL "") 32 file(GLOB_RECURSE newlib_header ${LLVM_TOOLCHAIN_PATH}/_newlib_version.h) 33 if(newlib_header) 34 set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib") 35 endif() 36 37 # Support for picolibc is indicated by the presence of 'picolibc.h' in the toolchain path. 38 file(GLOB_RECURSE picolibc_header ${LLVM_TOOLCHAIN_PATH}/picolibc.h) 39 if(picolibc_header) 40 set(TOOLCHAIN_HAS_PICOLIBC ON CACHE BOOL "True if toolchain supports picolibc") 41 endif() 42endif() 43 44message(STATUS "Found toolchain: llvm (clang/ld)") 45