1# find the compilers for C, CPP, assembly
2find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}armclang PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
3find_program(CMAKE_CXX_COMPILER ${CROSS_COMPILE}armclang PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
4find_program(CMAKE_ASM_COMPILER ${CROSS_COMPILE}armclang PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
5
6# The CMAKE_REQUIRED_FLAGS variable is used by check_c_compiler_flag()
7# (and other commands which end up calling check_c_source_compiles())
8# to add additional compiler flags used during checking. These flags
9# are unused during "real" builds of Zephyr source files linked into
10# the final executable.
11#
12include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
13include(${ZEPHYR_BASE}/cmake/gcc-m-fpu.cmake)
14
15# Strip out any trailing +<FOO> from GCC_M_CPU for cases when GCC_M_CPU is
16# 'cortex-m33+nodsp' we need that to be 'cortex-m33' for CMAKE_SYSTEM_PROCESSOR
17string(REGEX REPLACE "\\+.*" "" CMAKE_SYSTEM_PROCESSOR ${GCC_M_CPU})
18
19if(CONFIG_ARM64)
20  list(APPEND TOOLCHAIN_C_FLAGS   -mcpu=${GCC_M_CPU})
21
22  list(APPEND TOOLCHAIN_C_FLAGS   -mabi=lp64)
23  list(APPEND TOOLCHAIN_LD_FLAGS  -mabi=lp64)
24else()
25  list(APPEND TOOLCHAIN_C_FLAGS   -mcpu=${GCC_M_CPU})
26
27  if(CONFIG_COMPILER_ISA_THUMB2)
28    list(APPEND TOOLCHAIN_C_FLAGS   -mthumb)
29  endif()
30
31  list(APPEND TOOLCHAIN_C_FLAGS -mabi=aapcs)
32
33  if(CONFIG_FPU)
34    if(NOT "${GCC_M_FPU}" STREQUAL "auto")
35      list(APPEND TOOLCHAIN_C_FLAGS   -mfpu=${GCC_M_FPU})
36    endif()
37    if    (CONFIG_FP_SOFTABI)
38      list(APPEND TOOLCHAIN_C_FLAGS   -mfloat-abi=softfp)
39    elseif(CONFIG_FP_HARDABI)
40      list(APPEND TOOLCHAIN_C_FLAGS   -mfloat-abi=hard)
41    endif()
42  else()
43    list(APPEND TOOLCHAIN_C_FLAGS   -mfloat-abi=soft)
44  endif()
45endif()
46
47foreach(file_name include/stddef.h)
48  execute_process(
49    COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}
50    OUTPUT_VARIABLE _OUTPUT
51    )
52  get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
53  string(REGEX REPLACE "\n" "" _OUTPUT ${_OUTPUT})
54
55  list(APPEND NOSTDINC ${_OUTPUT})
56endforeach()
57
58foreach(isystem_include_dir ${NOSTDINC})
59  list(APPEND isystem_include_flags -isystem ${isystem_include_dir})
60endforeach()
61
62set(CMAKE_REQUIRED_FLAGS ${isystem_include_flags})
63string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
64
65if(CONFIG_ARMCLANG_STD_LIBC)
66  # Zephyr requires AEABI portability to ensure correct functioning of the C
67  # library, for example error numbers, errno.h.
68  list(APPEND TOOLCHAIN_C_FLAGS -D_AEABI_PORTABILITY_LEVEL=1)
69endif()
70