Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toolchain abstraction #24851

382 changes: 171 additions & 211 deletions CMakeLists.txt

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion arch/arm/core/aarch32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
zephyr_library()

if (CONFIG_COVERAGE)
toolchain_cc_coverage()
zephyr_compile_options($<TARGET_PROPERTY:compiler,coverage>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,coverage>)
endif ()

zephyr_library_sources(
Expand Down
3 changes: 2 additions & 1 deletion arch/arm/core/aarch64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
zephyr_library()

if (CONFIG_COVERAGE)
toolchain_cc_coverage()
zephyr_compile_options($<TARGET_PROPERTY:compiler,coverage>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,coverage>)
endif ()

zephyr_library_sources(
Expand Down
11 changes: 7 additions & 4 deletions arch/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@ zephyr_compile_options(
)

# @Intent: Obtain compiler specific flags for no freestanding compilation
toolchain_cc_no_freestanding_options()
zephyr_compile_options($<TARGET_PROPERTY:compiler,hosted>)

zephyr_include_directories(${BOARD_DIR})

if (CONFIG_COVERAGE)
toolchain_cc_coverage()
zephyr_compile_options($<TARGET_PROPERTY:compiler,coverage>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,coverage>)
endif ()

if (CONFIG_ASAN)
toolchain_cc_asan()
zephyr_compile_options($<TARGET_PROPERTY:compiler,sanitize_address>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,sanitize_address>)
endif ()

if (CONFIG_UBSAN)
toolchain_cc_ubsan()
zephyr_compile_options($<TARGET_PROPERTY:compiler,sanitize_undefined>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,sanitize_undefined>)
endif ()

zephyr_compile_definitions(_POSIX_C_SOURCE=200809 _XOPEN_SOURCE=600 _XOPEN_SOURCE_EXTENDED)
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
zephyr_library()

if (CONFIG_COVERAGE)
toolchain_cc_coverage()
zephyr_compile_options($<TARGET_PROPERTY:compiler,coverage>)
zephyr_link_libraries($<TARGET_PROPERTY:linker,coverage>)
endif ()

zephyr_library_sources(cpuhalt.c)
Expand Down
20 changes: 13 additions & 7 deletions cmake/app/boilerplate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ alternate .overlay file using this parameter. These settings will override the \
settings in the board's .dts file. Multiple files may be listed, e.g. \
DTC_OVERLAY_FILE=\"dts1.overlay dts2.overlay\"")

# Populate USER_CACHE_DIR with a directory that user applications may
# write cache files to.
if(NOT DEFINED USER_CACHE_DIR)
find_appropriate_cache_directory(USER_CACHE_DIR)
endif()
message(STATUS "Cache files will be written to: ${USER_CACHE_DIR}")

# Prevent CMake from testing the toolchain
set(CMAKE_C_COMPILER_FORCED 1)
set(CMAKE_CXX_COMPILER_FORCED 1)
Expand Down Expand Up @@ -605,6 +612,12 @@ include(${ZEPHYR_BASE}/cmake/target_toolchain.cmake)

project(Zephyr-Kernel VERSION ${PROJECT_VERSION})
enable_language(C CXX ASM)
# The setup / configuration of the toolchain itself and the configuration of
# supported compilation flags are now split, as this allows to use the toolchain
# for generic purposes, for example DTS, and then test the toolchain for
# supported flags at stage two.
# Testing the toolchain flags requires the enable_language() to have been called in CMake.
include(${ZEPHYR_BASE}/cmake/target_toolchain_flags.cmake)

# 'project' sets PROJECT_BINARY_DIR to ${CMAKE_CURRENT_BINARY_DIR},
# but for legacy reasons we need it to be set to
Expand All @@ -624,13 +637,6 @@ set(KERNEL_EXE_NAME ${KERNEL_NAME}.exe)
set(KERNEL_STAT_NAME ${KERNEL_NAME}.stat)
set(KERNEL_STRIP_NAME ${KERNEL_NAME}.strip)

# Populate USER_CACHE_DIR with a directory that user applications may
# write cache files to.
if(NOT DEFINED USER_CACHE_DIR)
find_appropriate_cache_directory(USER_CACHE_DIR)
endif()
message(STATUS "Cache files will be written to: ${USER_CACHE_DIR}")

include(${BOARD_DIR}/board.cmake OPTIONAL)

# If we are using a suitable ethernet driver inside qemu, then these options
Expand Down
157 changes: 157 additions & 0 deletions cmake/bintools/bintools_template.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# This template file can be used as a starting point for implementing support
# for additional tools for reading and/or conversion of elf files.
#
# Although GNU bintools is used as name, then the template can be used to
# support other tools.
#
# Overview of bintools used commands:
# - memusage : Tool for reporting target memory usage
# (if linker support memusage reporting leave this property empty)
# - disassembly : Tool for disassemble the target
# - elfconvert : Tool for converting from elf into another format.
# - readelf : Tool for elf file processing
# - strip : Tool for symnbol stripping
#
# Each tool will have the following minimum properties:
# - <tool>_command : Name of executable to call
# - <tool>_flag : Flags that must always be used with this command
# - <tool>_flag_infile : Flag to use when specifying the file to process
# - <tool>_flag_outfile : Flag to use to specify the result of the processing.
#
# each tool might require more flags depending on its use, as example:
# - elfconvert_flag_section_remove : Flag to use when specifying sections to remove
# - readelf_flags_headers : Flag to use to specify headers should be displayed
#
# If a given tool / flag / feature is not supported, then keep the property empty.
# As bintools_template.cmake default has empty flags, then it is sufficient to
# only set those flags that a given set of tools support.
#
# Commands will default echo a message if called, but no command has been defined.
# This is done, so that unexpected calls to non-implemented command can be easily detected.
# To disable the message, simply silence the command with:
# set_property(TARGET bintools PROPERTY <command>_command ${CMAKE_COMMAND} -E echo "")
#
# The bintools properties are made generic so that implementing support for an
# additional native tool should be as easy as possible.
# However, there might be tools and/or use cases where the current property
# scheme does not cover the exact needs. For those use-cases it is possible
# to implement the call to a native tool inside a CMake script.
# For example, to call a custom script for elfconvert command, one can specify:
# set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_COMMAND})
# set_property(TARGET bintools PROPERTY elfconvert_flag "")
# set_property(TARGET bintools PROPERTY elfconvert_flag_final -P custom_elfconvert.cmake)
# set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-DSTRIP_ALL=True")
# set_property(TARGET bintools PROPERTY elfconvert_flag_infile "-DINFILE=")
# set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "-DOUT_FILE=")

#
#
# bintools property overview of all commands:
#
# Command:
# - memusage : Name of command to execute
# Note: For gcc compilers this command is not used,
# instead a linker flag is used for this)
# memusage_flag : Flags that must always be applied when calling memusage command
# memusage_flag_final : Flags that must always be applied last at the memusage command
# memusage_byproducts : Byproducts (files) generated when calling memusage
#
#
# - elfconvert : Name of command for elf file conversion.
# For GNU binary utilities this is objcopy
# elfconvert_formats : Formats supported by this command.
# elfconvert_flag : Flags that must always be applied when calling elfconvert command
# elfconvert_flag_final : Flags that must always be applied last at the elfconvert command
# elfconvert_flag_strip_all : Flag that is used for stripping all symbols when converting
# elfconvert_flag_strip_debug : Flag that is used to strip debug symbols when converting
# elfconvert_flag_intarget : Flag for specifying target used for infile
# elfconvert_flag_outtarget : Flag for specifying target to use for converted file.
# Target value must be one of those listed described by: elfconvert_formats
# elfconvert_flag_section_remove: Flag for specifying that following section must be removed
# elfconvert_flag_section_only : Flag for specifying that only the following section should be kept
# elfconvert_flag_section_rename: Flag for specifying that following section must be renamed
# elfconvert_flag_gapfill : Flag for specifying the value to fill in gaps between sections
# elfconvert_flag_srec_len : Flag for specifying maximum length of Srecord values
# elfconvert_flag_infile : Flag for specifying the input file
# elfconvert_flag_outfile : Flag for specifying the output file
# For tools that prints to standard out, this should be ">" to indicate redirection
#
#
# - disassembly : Name of command for disassembly of files
# For GNU binary utilities this is objdump
# disassembly_flag : Flags that must always be applied when calling disassembly command
# disassembly_flag_final : Flags that must always be applied last at the disassembly command
# disassembly_flag_inline_source : Flag to use to display source code mixed with disassembly
# disassembly_flag_all : Flag to use for disassemble everything, including zeroes
# disassembly_flag_infile : Flag for specifying the input file
# disassembly_flag_outfile : Flag for specifying the output file
# For tools that prints to standard out, this should be ">" to indicate redirection
#
#
# - readelf : Name of command for reading elf files.
# For GNU binary utilities this is readelf
# readelf_flag : Flags that must always be applied when calling readelf command
# readelf_flag_final : Flags that must always be applied last at the readelf command
# readelf_flag_headers : Flag to use for specifying ELF headers should be read
# readelf_flag_infile : Flag for specifying the input file
# readelf_flag_outfile : Flag for specifying the output file
# For tools that prints to standard out, this should be ">" to indicate redirection
#
#
# - strip: Name of command for stripping symbols
# For GNU binary utilities this is strip
# strip_flag : Flags that must always be applied when calling strip command
# strip_flag_final : Flags that must always be applied last at the strip command
# strip_flag_all : Flag for removing all symbols
# strip_flag_debug : Flag for removing debug symbols
# strip_flag_dwo : Flag for removing dwarf sections
# strip_flag_infile : Flag for specifying the input file
# strip_flag_outfile : Flag for specifying the output file

set(COMMAND_NOT_SUPPORTED "command not supported on bintools: ")

# If memusage is supported as post-build command, set memusage_type to: command
# and this value to the command to execute in the form: <command> <arguments>
# Note: If memusage is supported during linking, please use:
# set_property(TARGET linker ... ) found in cmake/linker/linker_flags.cmake instead
set_property(TARGET bintools PROPERTY memusage_command "")
set_property(TARGET bintools PROPERTY memusage_flag "")
set_property(TARGET bintools PROPERTY memusage_flag_final "")
set_property(TARGET bintools PROPERTY memusage_byproducts "")

# disassembly command to use for generation of list file.
set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_COMMAND} -E echo "disassembly ${COMMAND_NOT_SUPPORTED} ${BINTOOLS}")
set_property(TARGET bintools PROPERTY disassembly_flag "")
set_property(TARGET bintools PROPERTY disassembly_flag_final "")
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source "")
set_property(TARGET bintools PROPERTY disassembly_flag_infile "")
set_property(TARGET bintools PROPERTY disassembly_flag_outfile "")

# elfconvert to use for transforming an elf file into another format, such as intel hex, s-rec, binary, etc.
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_COMMAND} -E echo "elfconvert ${COMMAND_NOT_SUPPORTED} ${BINTOOLS}")
set_property(TARGET bintools PROPERTY elfconvert_formats "")
set_property(TARGET bintools PROPERTY elfconvert_flag "")
set_property(TARGET bintools PROPERTY elfconvert_flag_final "")
set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "")
set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "")
set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "")
set_property(TARGET bintools PROPERTY elfconvert_flag_infile "")
set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "")

# readelf for processing of elf files.
set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_COMMAND} -E echo "readelf ${COMMAND_NOT_SUPPORTED} ${BINTOOLS}")
set_property(TARGET bintools PROPERTY readelf_flag "")
set_property(TARGET bintools PROPERTY readelf_flag_final "")
set_property(TARGET bintools PROPERTY readelf_flag_headers "")
set_property(TARGET bintools PROPERTY readelf_flag_infile "")
set_property(TARGET bintools PROPERTY readelf_flag_outfile "")

# strip command for stripping symbols
set_property(TARGET bintools PROPERTY strip_command ${CMAKE_COMMAND} -E echo "strip ${COMMAND_NOT_SUPPORTED} ${BINTOOLS}")
set_property(TARGET bintools PROPERTY strip_flag "")
set_property(TARGET bintools PROPERTY strip_flag_final "")
set_property(TARGET bintools PROPERTY strip_flag_all "")
set_property(TARGET bintools PROPERTY strip_flag_debug "")
set_property(TARGET bintools PROPERTY strip_flag_dwo "")
set_property(TARGET bintools PROPERTY strip_flag_infile "")
set_property(TARGET bintools PROPERTY strip_flag_outfile "")
9 changes: 3 additions & 6 deletions cmake/bintools/gnu/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ find_program(CMAKE_AR ${CROSS_COMPILE}ar PATHS ${TOOLCHAIN_HOME} NO_DE
find_program(CMAKE_RANLIB ${CROSS_COMPILE}ranlib PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${CROSS_COMPILE}readelf PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_NM ${CROSS_COMPILE}nm PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_STRIP ${CROSS_COMPILE}strip PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)

find_program(CMAKE_GDB ${CROSS_COMPILE}gdb PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB gdb-multiarch PATHS ${TOOLCHAIN_HOME} )

# Include bin tool abstraction macros
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_memusage.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objcopy.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_objdump.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_readelf.cmake)
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_strip.cmake)
# Include bin tool properties
include(${ZEPHYR_BASE}/cmake/bintools/gnu/target_bintools.cmake)
Loading