cmake: strip paths in build output based on Kconfig option

Add CONFIG_BUILD_OUTPUT_STRIP_PATHS to allow keeping absolute paths
in the build output.

This can be helpful for IDEs to detect links in a console output and
jump to the code location (e.g. when running tests in native_posix
locally).

Debuggers usually have a path mapping feature to ensure the files are
still found.

Signed-off-by: Martin Jäger <martin@libre.solar>
This commit is contained in:
Martin Jäger 2023-03-29 16:06:30 +02:00 committed by Carles Cufí
parent d6dfacc9c6
commit a0ffaa763c
2 changed files with 23 additions and 8 deletions

View file

@ -442,14 +442,15 @@ zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage)
# application code. This saves some memory, stops leaking user locations
# in binaries, makes failure logs more deterministic and most
# importantly makes builds more deterministic
# If several match then the last one wins. This matters for instances
# like tests/ and samples/: they're inside all of them! Then let's
# strip as little as possible.
zephyr_cc_option(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR)
zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE)
if(WEST_TOPDIR)
zephyr_cc_option(-fmacro-prefix-map=${WEST_TOPDIR}=WEST_TOPDIR)
if(CONFIG_BUILD_OUTPUT_STRIP_PATHS)
# If several match then the last one wins. This matters for instances
# like tests/ and samples/: they're inside all of them! Then let's
# strip as little as possible.
zephyr_cc_option(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR)
zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE)
if(WEST_TOPDIR)
zephyr_cc_option(-fmacro-prefix-map=${WEST_TOPDIR}=WEST_TOPDIR)
endif()
endif()
# TODO: Archiver arguments

View file

@ -684,6 +684,20 @@ config BUILD_OUTPUT_META_STATE_PROPAGATE
defined when `west update` was run the last time (`manifest-rev`).
The off state is only present if a west workspace is found.
config BUILD_OUTPUT_STRIP_PATHS
bool "Strip absolute paths from binaries"
default y
help
If the compiler supports it, strip the ${ZEPHYR_BASE} prefix from the
__FILE__ macro used in __ASSERT*, in the
.noinit."/home/joe/zephyr/fu/bar.c" section names and in any
application code.
This saves some memory, stops leaking user locations in binaries, makes
failure logs more deterministic and most importantly makes builds more
deterministic.
Debuggers usually have a path mapping feature to ensure the files are
still found.
endmenu
config DEPRECATED