2019-04-06 09:08:09 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
set_ifndef(C++ g++)
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# Configures CMake for using GCC, this script is re-used by several
|
|
|
|
# GCC-based toolchains
|
2018-12-13 16:32:07 +01:00
|
|
|
|
2022-03-14 17:26:18 +01:00
|
|
|
if("${SPARSE}" STREQUAL "y")
|
|
|
|
find_program(CMAKE_C_COMPILER cgcc)
|
|
|
|
find_program(REAL_CC ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
set(ENV{REAL_CC} ${REAL_CC})
|
|
|
|
else()
|
|
|
|
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
endif()
|
|
|
|
|
2020-05-19 11:30:26 +02:00
|
|
|
if(${CMAKE_C_COMPILER} STREQUAL CMAKE_C_COMPILER-NOTFOUND)
|
|
|
|
message(FATAL_ERROR "C compiler ${CROSS_COMPILE}${CC} not found - Please check your toolchain installation")
|
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
if(CONFIG_CPLUSPLUS)
|
2017-12-12 23:29:37 +05:30
|
|
|
set(cplusplus_compiler ${CROSS_COMPILE}${C++})
|
2017-10-27 15:43:34 +02:00
|
|
|
else()
|
2017-12-12 23:29:37 +05:30
|
|
|
if(EXISTS ${CROSS_COMPILE}${C++})
|
|
|
|
set(cplusplus_compiler ${CROSS_COMPILE}${C++})
|
2017-10-27 15:43:34 +02:00
|
|
|
else()
|
|
|
|
# When the toolchain doesn't support C++, and we aren't building
|
|
|
|
# with C++ support just set it to something so CMake doesn't
|
|
|
|
# crash, it won't actually be called
|
|
|
|
set(cplusplus_compiler ${CMAKE_C_COMPILER})
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-05-19 17:09:28 +09:00
|
|
|
find_program(CMAKE_CXX_COMPILER ${cplusplus_compiler} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
set(NOSTDINC "")
|
|
|
|
|
2018-11-01 09:45:54 -07:00
|
|
|
# Note that NOSYSDEF_CFLAG may be an empty string, and
|
|
|
|
# set_ifndef() does not work with empty string.
|
|
|
|
if(NOT DEFINED NOSYSDEF_CFLAG)
|
|
|
|
set(NOSYSDEF_CFLAG -undef)
|
|
|
|
endif()
|
|
|
|
|
2019-05-09 14:00:06 +09:00
|
|
|
foreach(file_name include/stddef.h include-fixed/limits.h)
|
2017-10-27 15:43:34 +02:00
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}
|
|
|
|
OUTPUT_VARIABLE _OUTPUT
|
|
|
|
)
|
2019-05-09 14:00:06 +09:00
|
|
|
get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
|
2018-07-31 15:11:15 +02:00
|
|
|
string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}")
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
list(APPEND NOSTDINC ${_OUTPUT})
|
|
|
|
endforeach()
|
|
|
|
|
2019-02-21 17:01:20 -05:00
|
|
|
include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-02-21 17:01:20 -05:00
|
|
|
if("${ARCH}" STREQUAL "arm")
|
2019-09-18 19:41:37 -05:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_arm.cmake)
|
2021-03-25 11:56:15 +01:00
|
|
|
elseif("${ARCH}" STREQUAL "arm64")
|
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_arm64.cmake)
|
2019-02-21 17:01:20 -05:00
|
|
|
elseif("${ARCH}" STREQUAL "arc")
|
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS
|
|
|
|
-mcpu=${GCC_M_CPU}
|
|
|
|
)
|
2019-07-25 23:04:17 -04:00
|
|
|
elseif("${ARCH}" STREQUAL "riscv")
|
2020-03-04 11:04:26 -08:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/target_riscv.cmake)
|
2019-10-08 01:14:02 -07:00
|
|
|
elseif("${ARCH}" STREQUAL "x86")
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/target_x86.cmake)
|
2020-10-16 20:55:04 +02:00
|
|
|
elseif("${ARCH}" STREQUAL "sparc")
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/target_sparc.cmake)
|
2021-12-05 22:47:41 +00:00
|
|
|
elseif("${ARCH}" STREQUAL "mips")
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/target_mips.cmake)
|
2019-02-21 17:01:20 -05:00
|
|
|
endif()
|
2017-12-12 23:29:37 +05:30
|
|
|
|
2021-06-15 19:10:35 +09:00
|
|
|
# This libgcc code is partially duplicated in compiler/*/target.cmake
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
|
|
|
|
OUTPUT_VARIABLE LIBGCC_FILE_NAME
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-06-15 19:10:35 +09:00
|
|
|
assert_exists(LIBGCC_FILE_NAME)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-06-15 19:10:35 +09:00
|
|
|
get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-06-15 19:10:35 +09:00
|
|
|
assert_exists(LIBGCC_DIR)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-06-15 19:10:35 +09:00
|
|
|
LIST(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"")
|
|
|
|
LIST(APPEND TOOLCHAIN_LIBS gcc)
|
2018-01-08 17:31:51 +01:00
|
|
|
|
2019-02-21 17:01:20 -05:00
|
|
|
if(SYSROOT_DIR)
|
|
|
|
# The toolchain has specified a sysroot dir that we can use to set
|
|
|
|
# the libc path's
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-multi-directory
|
|
|
|
OUTPUT_VARIABLE NEWLIB_DIR
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2019-02-21 17:01:20 -05:00
|
|
|
set(LIBC_LIBRARY_DIR "\"${SYSROOT_DIR}\"/lib/${NEWLIB_DIR}")
|
2018-01-08 17:06:42 +01:00
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
# For CMake to be able to test if a compiler flag is supported by the
|
|
|
|
# toolchain we need to give CMake the necessary flags to compile and
|
|
|
|
# link a dummy C file.
|
|
|
|
#
|
|
|
|
# CMake checks compiler flags with check_c_compiler_flag() (Which we
|
2022-02-24 12:00:55 +00:00
|
|
|
# wrap with target_cc_option() in extensions.cmake)
|
2017-10-27 15:43:34 +02:00
|
|
|
foreach(isystem_include_dir ${NOSTDINC})
|
2017-12-12 13:54:08 +01:00
|
|
|
list(APPEND isystem_include_flags -isystem "\"${isystem_include_dir}\"")
|
2017-10-27 15:43:34 +02:00
|
|
|
endforeach()
|
2019-04-25 15:45:39 +02:00
|
|
|
|
2018-10-27 16:14:41 +01:00
|
|
|
# The CMAKE_REQUIRED_FLAGS variable is used by check_c_compiler_flag()
|
|
|
|
# (and other commands which end up calling check_c_source_compiles())
|
|
|
|
# to add additional compiler flags used during checking. These flags
|
|
|
|
# are unused during "real" builds of Zephyr source files linked into
|
|
|
|
# the final executable.
|
|
|
|
#
|
|
|
|
# Appending onto any existing values lets users specify
|
|
|
|
# toolchain-specific flags at generation time.
|
2019-08-28 14:24:17 +02:00
|
|
|
list(APPEND CMAKE_REQUIRED_FLAGS
|
|
|
|
-nostartfiles
|
|
|
|
-nostdlib
|
|
|
|
${isystem_include_flags}
|
|
|
|
-Wl,--unresolved-symbols=ignore-in-object-files
|
|
|
|
-Wl,--entry=0 # Set an entry point to avoid a warning
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
|