diff --git a/CMakeLists.txt b/CMakeLists.txt index b152fe01d2e77..80113e21b2b0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,7 @@ if(NOT EXISTS "${NUTTX_APPS_DIR}") message(FATAL_ERROR "Application directory ${NUTTX_APPS_DIR} is not found") endif() +get_filename_component(NUTTX_APPS_DIR ${NUTTX_APPS_DIR} ABSOLUTE) get_filename_component(apps_dir ${NUTTX_APPS_DIR} NAME) set(NUTTX_APPS_BINDIR "${CMAKE_BINARY_DIR}/${apps_dir}") @@ -513,6 +514,21 @@ if(CONFIG_NDEBUG) add_compile_options(-DNDEBUG) endif() +# Cmake build provide absolute paths to compile files. If __FILE__ macros are +# used in the source code(ASSERT), the binary will be occupied by many invalid +# paths. If the compiler support preprocessing files and expand the "__FILE__" +# and "__BASE_FILE__" macros as if the files resided in directory new instead. +# 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. +if(CONFIG_OUTPUT_STRIP_PATHS) + add_compile_options(-fmacro-prefix-map=${NUTTX_DIR}=) + add_compile_options(-fmacro-prefix-map=${NUTTX_APPS_DIR}=) + add_compile_options(-fmacro-prefix-map=${NUTTX_BOARD_ABS_DIR}=) + add_compile_options(-fmacro-prefix-map=${NUTTX_CHIP_ABS_DIR}=) +endif() + add_definitions(-D__NuttX__) set_property( diff --git a/Kconfig b/Kconfig index 0550e05c99e26..4463a7ff87dcc 100644 --- a/Kconfig +++ b/Kconfig @@ -447,6 +447,23 @@ config DFU_PID hex "PID to use for DFU image" endif # DFU_BINARY + +config OUTPUT_STRIP_PATHS + bool "Strip absolute paths from binaries" + default y + depends on ARCH_TOOLCHAIN_GNU + ---help--- + Cmake build provide absolute paths to compile files. If __FILE__ + macros are used in the source code(ASSERT), the binary will be occupied + by many invalid paths. + If the compiler support preprocessing files and expand the "__FILE__" + and "__BASE_FILE__" macros as if the files resided in directory new instead. + 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 # Binary Output Formats menu "Customize Header Files"