From a0ffaa763cf2d63eea2725bac8da4ff82a681c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Wed, 29 Mar 2023 16:06:30 +0200 Subject: [PATCH] cmake: strip paths in build output based on Kconfig option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CMakeLists.txt | 17 +++++++++-------- Kconfig.zephyr | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) 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