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
19list(APPEND TOOLCHAIN_C_FLAGS
20  -fshort-enums
21  )
22
23if(CONFIG_ARM64)
24  list(APPEND TOOLCHAIN_C_FLAGS   -mcpu=${GCC_M_CPU})
25
26  list(APPEND TOOLCHAIN_C_FLAGS   -mabi=lp64)
27  list(APPEND TOOLCHAIN_LD_FLAGS  -mabi=lp64)
28else()
29  list(APPEND TOOLCHAIN_C_FLAGS   -mcpu=${GCC_M_CPU})
30
31  if(CONFIG_COMPILER_ISA_THUMB2)
32    list(APPEND TOOLCHAIN_C_FLAGS   -mthumb)
33  endif()
34
35  list(APPEND TOOLCHAIN_C_FLAGS -mabi=aapcs)
36
37  if(CONFIG_FPU)
38    if(NOT "${GCC_M_FPU}" STREQUAL "auto")
39      list(APPEND TOOLCHAIN_C_FLAGS   -mfpu=${GCC_M_FPU})
40    endif()
41    if    (CONFIG_FP_SOFTABI)
42      list(APPEND TOOLCHAIN_C_FLAGS   -mfloat-abi=softfp)
43    elseif(CONFIG_FP_HARDABI)
44      list(APPEND TOOLCHAIN_C_FLAGS   -mfloat-abi=hard)
45    endif()
46  else()
47    list(APPEND TOOLCHAIN_C_FLAGS   -mfloat-abi=soft)
48  endif()
49endif()
50
51foreach(file_name include/stddef.h)
52  execute_process(
53    COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}
54    OUTPUT_VARIABLE _OUTPUT
55    )
56  get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
57  string(REGEX REPLACE "\n" "" _OUTPUT ${_OUTPUT})
58
59  list(APPEND NOSTDINC ${_OUTPUT})
60endforeach()
61
62foreach(isystem_include_dir ${NOSTDINC})
63  list(APPEND isystem_include_flags -isystem ${isystem_include_dir})
64endforeach()
65
66set(CMAKE_REQUIRED_FLAGS ${isystem_include_flags})
67string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
68
69if(CONFIG_ARMCLANG_STD_LIBC)
70  # Zephyr requires AEABI portability to ensure correct functioning of the C
71  # library, for example error numbers, errno.h.
72  list(APPEND TOOLCHAIN_C_FLAGS -D_AEABI_PORTABILITY_LEVEL=1)
73endif()
74