From f160dee9356580e027322dd3b20e7d3016dfa162 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Fri, 4 Sep 2020 10:05:00 +0200 Subject: [PATCH] cmake: bintools abstraction, support _flag_final property This command add support for `_flag_final` to all bintools commands. This allows users that has special use-cases to use a CMake script for bintool command execution, and thereby have full control of command invocation and argument processing. Example of how to specify the property for such use: Calling a custom script for elfconvert command: 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 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=") Signed-off-by: Torsten Rasmussen --- CMakeLists.txt | 8 ++++++++ cmake/bintools/bintools_template.cmake | 25 ++++++++++++++++++++++++ cmake/bintools/gnu/target_bintools.cmake | 8 ++++++++ 3 files changed, 41 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 956cc9e7e6fdc2..9d47a0fb4e97e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -726,6 +726,7 @@ if(CONFIG_GEN_ISR_TABLES) $.intList $$ $isrList.bin + $ COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py --output-source isr_tables.c @@ -864,6 +865,7 @@ if(CONFIG_USERSPACE) $.rodata=.kobject_data.rodata $${OUTPUT_OBJ_PATH} $${OUTPUT_OBJ_RENAMED} + $ DEPENDS output_lib WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND_EXPAND_LISTS @@ -1114,6 +1116,7 @@ if(CONFIG_BUILD_OUTPUT_HEX OR BOARD_FLASH_RUNNER STREQUAL openocd) $.eh_frame $${KERNEL_ELF_NAME} $${KERNEL_HEX_NAME} + $ ) list(APPEND post_build_byproducts @@ -1137,6 +1140,7 @@ if(CONFIG_BUILD_OUTPUT_BIN) $.eh_frame $${KERNEL_ELF_NAME} $${KERNEL_BIN_NAME} + $ ) list(APPEND post_build_byproducts @@ -1159,6 +1163,7 @@ if(CONFIG_BUILD_OUTPUT_S19) $1 $${KERNEL_ELF_NAME} $${KERNEL_S19_NAME} + $ ) list(APPEND post_build_byproducts @@ -1182,6 +1187,7 @@ if(CONFIG_OUTPUT_DISASSEMBLE_ALL) ${disassembly_type} $${KERNEL_ELF_NAME} $${KERNEL_LST_NAME} + $ ) list(APPEND post_build_byproducts @@ -1199,6 +1205,7 @@ if(CONFIG_OUTPUT_STAT) $ $ ${KERNEL_ELF_NAME} $ ${KERNEL_STAT_NAME} + $ ) list(APPEND post_build_byproducts @@ -1214,6 +1221,7 @@ if(CONFIG_BUILD_OUTPUT_STRIPPED) $ $${KERNEL_ELF_NAME} $${KERNEL_STRIP_NAME} + $ ) list(APPEND post_build_byproducts diff --git a/cmake/bintools/bintools_template.cmake b/cmake/bintools/bintools_template.cmake index 3e7c93b62c7923..3dbe6a78c483d0 100644 --- a/cmake/bintools/bintools_template.cmake +++ b/cmake/bintools/bintools_template.cmake @@ -31,6 +31,21 @@ # To disable the message, simply silence the command with: # set_property(TARGET bintools PROPERTY _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: @@ -38,6 +53,7 @@ # 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 # # @@ -45,6 +61,7 @@ # 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 @@ -63,6 +80,7 @@ # - 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 @@ -73,6 +91,7 @@ # - 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 @@ -82,6 +101,7 @@ # - 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 @@ -96,11 +116,13 @@ set(COMMAND_NOT_SUPPORTED "command not supported on bintools: ") # 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 "") @@ -109,6 +131,7 @@ set_property(TARGET bintools PROPERTY disassembly_flag_outfile "") 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 "") @@ -118,6 +141,7 @@ 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 "") @@ -125,6 +149,7 @@ 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 "") diff --git a/cmake/bintools/gnu/target_bintools.cmake b/cmake/bintools/gnu/target_bintools.cmake index ad9feb5a4d5107..f8d810bc49725e 100644 --- a/cmake/bintools/gnu/target_bintools.cmake +++ b/cmake/bintools/gnu/target_bintools.cmake @@ -4,6 +4,7 @@ # In this implementation `objcopy` is used # elfconvert_formats : Formats supported: ihex, srec, binary # elfconvert_flag : empty +# elfconvert_flag_final : empty # elfconvert_flag_strip_all : -S # elfconvert_flag_strip_debug : -g # elfconvert_flag_intarget : --input-target= @@ -28,6 +29,7 @@ set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_OBJCOPY}) set_property(TARGET bintools PROPERTY elfconvert_formats ihex srec binary) set_property(TARGET bintools PROPERTY elfconvert_flag "") +set_property(TARGET bintools PROPERTY elfconvert_flag_final "") set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-S") set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-g") @@ -53,6 +55,7 @@ set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "") # - disassembly : Name of command for disassembly of files # In this implementation `objdump` is used # disassembly_flag : -d +# disassembly_flag_final : empty # disassembly_flag_inline_source : -S # disassembly_flag_all : -SDz # disassembly_flag_infile : empty, objdump doesn't take arguments for filenames @@ -60,6 +63,7 @@ set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "") set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_OBJDUMP}) set_property(TARGET bintools PROPERTY disassembly_flag -d) +set_property(TARGET bintools PROPERTY disassembly_flag_final "") set_property(TARGET bintools PROPERTY disassembly_flag_inline_source -S) set_property(TARGET bintools PROPERTY disassembly_flag_all -SDz) @@ -70,6 +74,7 @@ set_property(TARGET bintools PROPERTY disassembly_flag_outfile > ) # - strip: Name of command for stripping symbols # In this implementation `strip` is used # strip_flag : empty +# strip_flag_final : empty # strip_flag_all : --strip-all # strip_flag_debug : --strip-debug # strip_flag_dwo : --strip-dwo @@ -81,6 +86,7 @@ set_property(TARGET bintools PROPERTY strip_command ${CMAKE_STRIP}) # Any flag the strip command requires for processing set_property(TARGET bintools PROPERTY strip_flag "") +set_property(TARGET bintools PROPERTY strip_flag_final "") set_property(TARGET bintools PROPERTY strip_flag_all --strip-all) set_property(TARGET bintools PROPERTY strip_flag_debug --strip-debug) @@ -93,6 +99,7 @@ set_property(TARGET bintools PROPERTY strip_flag_outfile -o ) # - readelf : Name of command for reading elf files. # In this implementation `readelf` is used # readelf_flag : empty +# readelf_flag_final : empty # readelf_flag_headers : -e # readelf_flag_infile : empty, readelf doesn't take arguments for filenames # readelf_flag_outfile : '>', readelf doesn't take arguments for output @@ -103,6 +110,7 @@ set_property(TARGET bintools PROPERTY strip_flag_outfile -o ) set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_READELF}) set_property(TARGET bintools PROPERTY readelf_flag "") +set_property(TARGET bintools PROPERTY readelf_flag_final "") set_property(TARGET bintools PROPERTY readelf_flag_headers -e) set_property(TARGET bintools PROPERTY readelf_flag_infile "")