cmake: toolchain: Toolchain abstraction templates

As part of toolchain abstraction three template files to facilitate
additional toolchain support development has been introduced.

Those covers:
- bintools
- compiler flags
- linker flags

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-04-28 08:33:37 +02:00 committed by Carles Cufí
commit 31a1411cbd
5 changed files with 258 additions and 0 deletions

View file

@ -0,0 +1,132 @@
# 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 "")
#
# 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_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_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_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_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_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_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_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_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_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_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 "")

View file

@ -0,0 +1,102 @@
# Overview of used compiler properties for gcc / g++ compilers.
#
# Define the flags your toolchain support, and keep the unsupported flags empty.
#####################################################
# This section covers flags related to optimization #
#####################################################
set_compiler_property(PROPERTY no_optimization)
set_compiler_property(PROPERTY optimization_debug)
set_compiler_property(PROPERTY optimization_speed)
set_compiler_property(PROPERTY optimization_size)
#######################################################
# This section covers flags related to warning levels #
#######################################################
# Property for standard warning base in Zephyr, this will always bet set when compiling.
set_compiler_property(PROPERTY warning_base)
# GCC options for warning levels 1, 2, 3, when using `-DW=[1|2|3]`
# Property for warning levels 1, 2, 3 in Zephyr when using `-DW=[1|2|3]`
set_compiler_property(PROPERTY warning_dw_1)
set_compiler_property(PROPERTY warning_dw_2)
set_compiler_property(PROPERTY warning_dw_3)
# Extended warning set supported by the compiler
set_compiler_property(PROPERTY warning_extended)
# Compiler property that will issue error if a declaration does not specify a type
set_compiler_property(PROPERTY warning_error_implicit_int)
# Compiler flags to use when compiling according to MISRA
set_compiler_property(PROPERTY warning_error_misra_sane)
###########################################################################
# This section covers flags related to C or C++ standards / standard libs #
###########################################################################
# Compiler flags for C standard. The specific standard must be appended by user.
# For example, gcc specifies this as: set_compiler_property(PROPERTY cstd -std=)
set_compiler_property(PROPERTY cstd)
# Compiler flags for disabling C standard include and instead specify include
# dirs in nostdinc_include to use.
set_compiler_property(PROPERTY nostdinc)
set_compiler_property(PROPERTY nostdinc_include)
# Required C++ flags when compiling C++ code
set_property(TARGET compiler-cpp PROPERTY required)
# Compiler flags to use for specific C++ dialects
set_property(TARGET compiler-cpp PROPERTY dialect_cpp98)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp11)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp14)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp17)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a)
# Flag for disabling exeptions in C++
set_property(TARGET compiler-cpp PROPERTY no_exceptions)
# Flag for disabling rtti in C++
set_property(TARGET compiler-cpp PROPERTY no_rtti)
###################################################
# This section covers all remaining C / C++ flags #
###################################################
# Flags for coverage generation
set_compiler_property(PROPERTY coverage)
# Security canaries flags.
set_compiler_property(PROPERTY security_canaries)
set_compiler_property(PROPERTY security_fortify)
# Flag for a hosted (no-freestanding) application
set_compiler_property(PROPERTY hosted)
# gcc flag for a freestanding application
set_compiler_property(PROPERTY freestanding)
# Flag to include debugging symbol in compilation
set_compiler_property(PROPERTY debug)
set_compiler_property(PROPERTY no_common)
# Flags for imacros. The specific header must be appended by user.
set_compiler_property(PROPERTY imacros)
# Compiler flags for sanitizing.
set_compiler_property(PROPERTY sanitize_address)
set_compiler_property(PROPERTY sanitize_undefined)
# Required ASM flags when compiling
set_property(TARGET asm PROPERTY required)

View file

@ -0,0 +1,16 @@
# coverage is a property holding the linker flag required for coverage support on the toolchain.
# For example, on ld/gcc this would be: -lgcov
# Set the property for the corresponding flags of the given toolchain.
set_property(TARGET linker PROPERTY coverage)
# Linker flags for sanitizing.
check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_address)
check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_undefined)
# Linker flag for printing of memusage.
# Set this flag if the linker supports reporting of memusage as part of link,
# such as ls --print-memory-usage flag.
# If memory reporting is a post build command, please use
# cmake/bintools/bintools.cmake insted.
check_set_linker_property(TARGET linker PROPERTY memusage)

View file

@ -50,6 +50,7 @@ add_custom_target(bintools)
include(${TOOLCHAIN_ROOT}/cmake/compiler/${COMPILER}/target.cmake OPTIONAL)
include(${TOOLCHAIN_ROOT}/cmake/linker/${LINKER}/target.cmake OPTIONAL)
include(${CMAKE_CURRENT_LIST_DIR}/bintools/bintools_template.cmake)
include(${TOOLCHAIN_ROOT}/cmake/bintools/${BINTOOLS}/target.cmake OPTIONAL)
# Uniquely identify the toolchain wrt. it's capabilities.

View file

@ -4,6 +4,13 @@ add_custom_target(compiler)
add_custom_target(compiler-cpp)
add_custom_target(linker)
# Loading of templates are strictly not needed as they does not set any
# properties.
# They purely provides an overview as well as a starting point for supporting
# a new toolchain.
include(${CMAKE_CURRENT_LIST_DIR}/compiler/compiler_flags_template.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/linker/linker_flags_template.cmake)
# Configure the toolchain flags based on what toolchain technology is used
# (gcc, host-gcc etc.)
include(${TOOLCHAIN_ROOT}/cmake/compiler/${COMPILER}/compiler_flags.cmake OPTIONAL)