xref: /aosp_15_r20/external/executorch/backends/cadence/cadence.cmake (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the BSD-style license found in the
5# LICENSE file in the root directory of this source tree.
6
7set(XTENSA_TOOLCHAIN_PATH $ENV{XTENSA_TOOLCHAIN})
8
9if(NOT EXISTS ${XTENSA_TOOLCHAIN_PATH})
10  message(
11    FATAL_ERROR
12      "Nothing found at XTENSA_TOOLCHAIN_PATH: '${XTENSA_TOOLCHAIN_PATH}'"
13  )
14endif()
15
16set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/$ENV{TOOLCHAIN_VER}/XtensaTools)
17
18set(LINKER ld)
19set(BINTOOLS gnu)
20
21set(CROSS_COMPILE_TARGET xt)
22set(SYSROOT_TARGET xtensa-elf)
23
24set(CROSS_COMPILE ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-)
25set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
26
27set(NOSYSDEF_CFLAG "")
28
29list(APPEND TOOLCHAIN_C_FLAGS -fms-extensions)
30
31set(TOOLCHAIN_HAS_NEWLIB
32    OFF
33    CACHE BOOL "True if toolchain supports newlib"
34)
35
36set(COMPILER xt-clang)
37# set(CC clang) set(C++ clang++)
38set(LINKER xt-ld)
39
40set(CMAKE_CROSSCOMPILING TRUE)
41set(CMAKE_C_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang)
42set(CMAKE_CXX_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang++)
43
44set(CMAKE_C_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
45set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
46#workaround for larger compilation time
47set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -fno-strict-aliasing")
48
49set(CMAKE_SYSROOT ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
50set(CMAKE_LINKER ${TOOLCHAIN_HOME}/bin/xt-ld)
51add_link_options(-lm -stdlib=libc++ -Wl,--no-as-needed -static)
52message(STATUS "Found toolchain: xt-clang (${XTENSA_TOOLCHAIN_PATH})")
53