1# SPDX-License-Identifier: Apache-2.0 2 3set_ifndef(C++ g++) 4 5# Configures CMake for using GCC, this script is re-used by several 6# GCC-based toolchains 7 8find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) 9 10if(CONFIG_CPP) 11 set(cplusplus_compiler ${CROSS_COMPILE}${C++}) 12else() 13 if(EXISTS ${CROSS_COMPILE}${C++}) 14 set(cplusplus_compiler ${CROSS_COMPILE}${C++}) 15 else() 16 # When the toolchain doesn't support C++, and we aren't building 17 # with C++ support just set it to something so CMake doesn't 18 # crash, it won't actually be called 19 set(cplusplus_compiler ${CMAKE_C_COMPILER}) 20 endif() 21endif() 22find_program(CMAKE_CXX_COMPILER ${cplusplus_compiler} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) 23 24set(NOSTDINC "") 25 26# Note that NOSYSDEF_CFLAG may be an empty string, and 27# set_ifndef() does not work with empty string. 28if(NOT DEFINED NOSYSDEF_CFLAG) 29 set(NOSYSDEF_CFLAG -undef) 30endif() 31 32foreach(file_name include/stddef.h include-fixed/limits.h) 33 execute_process( 34 COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name} 35 OUTPUT_VARIABLE _OUTPUT 36 ) 37 get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY) 38 string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}") 39 40 list(APPEND NOSTDINC ${_OUTPUT}) 41endforeach() 42 43list(APPEND TOOLCHAIN_LIBS 44 gcc 45 hal 46 ) 47 48 49# For CMake to be able to test if a compiler flag is supported by the 50# toolchain we need to give CMake the necessary flags to compile and 51# link a dummy C file. 52# 53# CMake checks compiler flags with check_c_compiler_flag() (Which we 54# wrap with target_cc_option() in extensions.cmake) 55foreach(isystem_include_dir ${NOSTDINC}) 56 list(APPEND isystem_include_flags -isystem "\"${isystem_include_dir}\"") 57endforeach() 58# The CMAKE_REQUIRED_FLAGS variable is used by check_c_compiler_flag() 59# (and other commands which end up calling check_c_source_compiles()) 60# to add additional compiler flags used during checking. These flags 61# are unused during "real" builds of Zephyr source files linked into 62# the final executable. 63# 64# Appending onto any existing values lets users specify 65# toolchain-specific flags at generation time. 66list(APPEND CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files) 67string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 68