2019-04-06 09:08:09 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2019-03-08 13:29:29 +02:00
|
|
|
# Configuration for host installed clang
|
2018-05-02 00:09:31 -05: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-03-08 13:08:14 +02:00
|
|
|
if(DEFINED TOOLCHAIN_HOME)
|
|
|
|
set(find_program_clang_args PATH ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
|
|
|
|
endif()
|
|
|
|
|
cmake: Toolchain abstraction: Abstraction of binary tools, foundation.
This forms the foundation for the abstraction of the binary tools,
where the following steps are taken:
- Move binary tool resolving, such as objcopy, objdump, readelf and
so forth, out of compiler definitions and place in a dedicated binary
tools folder with the binary tools supplier as subfolder, similar to
the compiler and linker directories.
- Create binary tool sets, gnu, host-gnu and llvm.
- Each toolchain selects the required set of binary tools by setting
BINTOOLS via its generic.cmake as it also does for compiler and linker.
The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.
No functional change expected.
Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-07-18 15:06:51 +02:00
|
|
|
find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
|
|
|
|
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})
|
2018-12-10 15:08:59 +01:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
if(NOT "${ARCH}" STREQUAL "posix")
|
2019-09-17 06:37:01 -05:00
|
|
|
include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
|
|
|
|
|
|
|
|
if("${ARCH}" STREQUAL "arm")
|
|
|
|
list(APPEND TOOLCHAIN_C_FLAGS
|
|
|
|
-fshort-enums
|
|
|
|
)
|
|
|
|
list(APPEND TOOLCHAIN_LD_FLAGS
|
|
|
|
-fshort-enums
|
|
|
|
)
|
|
|
|
|
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_arm.cmake)
|
|
|
|
endif()
|
2018-05-02 00:09:31 -05:00
|
|
|
|
2019-05-09 14:00:06 +09:00
|
|
|
foreach(file_name include/stddef.h include-fixed/limits.h)
|
2019-04-20 15:37:37 +03: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)
|
2019-04-20 15:37:37 +03:00
|
|
|
string(REGEX REPLACE "\n" "" _OUTPUT ${_OUTPUT})
|
2018-05-02 00:09:31 -05:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
list(APPEND NOSTDINC ${_OUTPUT})
|
|
|
|
endforeach()
|
2018-05-02 00:09:31 -05:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
foreach(isystem_include_dir ${NOSTDINC})
|
|
|
|
list(APPEND isystem_include_flags -isystem ${isystem_include_dir})
|
|
|
|
endforeach()
|
2018-12-10 15:18:20 +01:00
|
|
|
|
2019-04-20 15:37:37 +03: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
|
|
|
|
)
|
2018-12-10 15:18:20 +01:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
assert_exists(LIBGCC_FILE_NAME)
|
2018-12-10 15:18:20 +01:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY)
|
2018-12-10 15:18:20 +01:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
assert_exists(LIBGCC_DIR)
|
2018-12-10 15:18:20 +01:00
|
|
|
|
2019-04-20 15:37:37 +03:00
|
|
|
list(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"")
|
|
|
|
list(APPEND TOOLCHAIN_LIBS gcc)
|
|
|
|
|
|
|
|
set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files)
|
|
|
|
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
|
|
|
|
|
|
|
|
endif()
|
2019-01-10 12:07:51 +01:00
|
|
|
|
|
|
|
# Load toolchain_cc-family macros
|
2019-03-08 13:46:27 +02:00
|
|
|
|
|
|
|
macro(toolchain_cc_nostdinc)
|
|
|
|
if(NOT "${ARCH}" STREQUAL "posix")
|
|
|
|
zephyr_compile_options( -nostdinc)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2019-01-10 12:07:51 +01:00
|
|
|
# Clang and GCC are almost feature+flag compatible, so reuse freestanding gcc
|
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_security_canaries.cmake)
|
2019-01-30 10:12:30 +01:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_optimizations.cmake)
|
2019-02-18 23:54:30 +01:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake)
|
2019-01-30 21:48:25 +01:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake)
|
2019-03-04 11:17:02 -08:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake)
|
2019-05-06 15:21:58 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake)
|
2019-06-11 13:55:53 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_imacros.cmake)
|
2019-06-12 14:56:46 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_base.cmake)
|
2019-08-24 11:12:38 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_coverage.cmake)
|
2019-08-22 22:03:22 +02:00
|
|
|
include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_sanitizers.cmake)
|
2019-03-08 13:39:32 +02:00
|
|
|
|
|
|
|
macro(toolchain_cc_security_fortify)
|
|
|
|
# No op, clang doesn't understand fortify at all
|
|
|
|
endmacro()
|
2019-03-08 12:29:31 +02:00
|
|
|
|
|
|
|
macro(toolchain_cc_no_freestanding_options)
|
|
|
|
# No op, this is used by the native_posix, clang has problems
|
|
|
|
# compiling the native_posix with -fno-freestanding.
|
|
|
|
endmacro()
|