mirror of
https://github.com/apache/nuttx.git
synced 2026-03-23 14:05:12 +08:00
cmake: strip file full path to save the code size
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. 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. Test config sabre-6quad/citest: Before: $ size build/nuttx text data bss dec hex filename 279309 908 13652 293869 47bed build/nuttx After: $ size build/nuttx text data bss dec hex filename 269313 908 13652 283873 454e1 build/nuttx Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
@@ -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,20 @@ 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 contain many invalid paths.
|
||||
# This saves some memory, stops exposing build systems locations in binaries,
|
||||
# make failure logs more deterministic and most importantly makes builds more
|
||||
# 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(
|
||||
|
||||
Reference in New Issue
Block a user