diff --git a/CMakeLists.txt b/CMakeLists.txt index 405b18e2d5c..549c2a4f297 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 8f9576b7c97..8fa4faec87c 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -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