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
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
2018-01-11 18:28:07 +01:00
|
|
|
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE}objcopy PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
find_program(CMAKE_OBJDUMP ${CROSS_COMPILE}objdump PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
2017-12-12 23:29:37 +05:30
|
|
|
find_program(CMAKE_AS ${CROSS_COMPILE}as PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
find_program(CMAKE_LINKER ${CROSS_COMPILE}ld PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
2018-01-11 18:28:07 +01:00
|
|
|
find_program(CMAKE_AR ${CROSS_COMPILE}ar PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
find_program(CMAKE_GDB ${CROSS_COMPILE}gdb PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
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()
|
2018-08-23 11:50:26 +02:00
|
|
|
find_program(CMAKE_CXX_COMPILER ${cplusplus_compiler} PATH ${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()
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
foreach(file_name include include-fixed)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}
|
|
|
|
OUTPUT_VARIABLE _OUTPUT
|
|
|
|
)
|
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()
|
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xcc")
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2018-12-07 12:42:53 +01:00
|
|
|
list(APPEND TOOLCHAIN_LIBS
|
|
|
|
gcc
|
|
|
|
hal
|
|
|
|
)
|
2017-12-12 23:29:37 +05:30
|
|
|
|
|
|
|
else()
|
|
|
|
include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
|
|
|
|
|
|
|
|
if("${ARCH}" STREQUAL "arm")
|
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS
|
|
|
|
-mthumb
|
|
|
|
-mcpu=${GCC_M_CPU}
|
|
|
|
)
|
2018-11-26 13:48:34 +01:00
|
|
|
list(APPEND TOOLCHAIN_LD_FLAGS
|
|
|
|
-mthumb
|
|
|
|
-mcpu=${GCC_M_CPU}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
include(${ZEPHYR_BASE}/cmake/fpu-for-gcc-m-cpu.cmake)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
if(CONFIG_FLOAT)
|
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS -mfpu=${FPU_FOR_${GCC_M_CPU}})
|
2018-11-26 13:48:34 +01:00
|
|
|
list(APPEND TOOLCHAIN_LD_FLAGS -mfpu=${FPU_FOR_${GCC_M_CPU}})
|
2017-12-12 23:29:37 +05:30
|
|
|
if (CONFIG_FP_SOFTABI)
|
2018-09-19 13:27:01 +02:00
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS -mfloat-abi=softfp)
|
2018-11-26 13:48:34 +01:00
|
|
|
list(APPEND TOOLCHAIN_LD_FLAGS -mfloat-abi=softfp)
|
2017-12-12 23:29:37 +05:30
|
|
|
elseif(CONFIG_FP_HARDABI)
|
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS -mfloat-abi=hard)
|
2018-11-26 13:48:34 +01:00
|
|
|
list(APPEND TOOLCHAIN_LD_FLAGS -mfloat-abi=hard)
|
2017-12-12 23:29:37 +05:30
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2017-12-12 23:29:37 +05:30
|
|
|
elseif("${ARCH}" STREQUAL "arc")
|
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS
|
|
|
|
-mcpu=${GCC_M_CPU}
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
endif()
|
2017-12-12 23:29:37 +05:30
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
assert_exists(LIBGCC_FILE_NAME)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
assert_exists(LIBGCC_DIR)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
LIST(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"")
|
|
|
|
LIST(APPEND TOOLCHAIN_LIBS gcc)
|
2018-01-08 17:31:51 +01:00
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
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
|
|
|
|
2017-12-12 23:29:37 +05:30
|
|
|
set(LIBC_LIBRARY_DIR "\"${SYSROOT_DIR}\"/lib/${NEWLIB_DIR}")
|
|
|
|
set(LIBC_INCLUDE_DIR ${SYSROOT_DIR}/include)
|
|
|
|
endif()
|
2017-10-27 15:43:34 +02:00
|
|
|
|
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
|
|
|
|
# wrap with target_cc_option() in extentions.cmake)
|
|
|
|
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()
|
|
|
|
set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files)
|
|
|
|
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
|