Browse Source

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>
pull/56732/head
Martin Jäger 2 years ago committed by Carles Cufí
parent
commit
a0ffaa763c
  1. 15
      CMakeLists.txt
  2. 14
      Kconfig.zephyr

15
CMakeLists.txt

@ -442,14 +442,15 @@ zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) @@ -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)
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

14
Kconfig.zephyr

@ -684,6 +684,20 @@ config BUILD_OUTPUT_META_STATE_PROPAGATE @@ -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

Loading…
Cancel
Save