Skip to content

Commit 82a7f02

Browse files
committed
feat: make __FILE__ relative
This makes the build location-independent, so that it ends up the same binary size in all cases when given the same options.
1 parent 67b7021 commit 82a7f02

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(FEAT_TIMER ON CACHE BOOL "Timer support")
2626
set(BUILD_OPT "s" CACHE STRING "Optimization level")
2727
set(BUILD_DBG OFF CACHE BOOL "Enable debug symbols")
2828
set(BUILD_LTO OFF CACHE BOOL "Enable Link-Time-Optimisations")
29+
set(BUILD_RELPATH ON CACHE BOOL "make __FILE__ be relative instead of absolute")
2930

3031
set(USB_PID 0 CACHE STRING "")
3132
set(USB_VID 0 CACHE STRING "")
@@ -46,6 +47,13 @@ ensure_CMSIS(${CMSIS5_PATH} ${AUTODL_CMSIS})
4647

4748
add_library(core_config INTERFACE)
4849

50+
if(${BUILD_RELPATH})
51+
# $<TARGET_PROPERTY:SOURCE_DIR> is evaluated by the final consumer, no core_config
52+
target_compile_options(core_config INTERFACE
53+
"-fmacro-prefix-map=$<TARGET_PROPERTY:SOURCE_DIR>=."
54+
)
55+
endif()
56+
4957
# configuration specifics
5058
if (${FEAT_XSERIAL} STREQUAL "GENERIC")
5159
target_compile_definitions(core_config INTERFACE

0 commit comments

Comments
 (0)