From 5035af490ae688dfb5dadce78fc005aec125ae6a Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Thu, 27 Jun 2024 09:24:41 +0800 Subject: [PATCH] cmake: fix relative path calculate error ```C file(RELATIVE_PATH relpath ${ZEPHYR_BASE}/include ${path}) ``` The prerequisite path assumed here must be the prefix of ZEPHYR, but if use symbolic links it will calculate error: like this: https://github.com/zephyrproject-rtos/zephyr/issues/74647#issuecomment-2183912468 Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/74647 Signed-off-by: Lingao Meng --- cmake/modules/extensions.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index 43750f93d2dee7..0c89f3bc65ceba 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -1335,7 +1335,10 @@ function(zephyr_linker_sources location) endif() # Find the relative path to the linker file from the include folder. - file(RELATIVE_PATH relpath ${ZEPHYR_BASE}/include ${path}) + get_filename_component(ZEPHYR_BASE_REALPATH "${ZEPHYR_BASE}/include" REALPATH) + get_filename_component(PATH_REALPATH "${path}" REALPATH) + + file(RELATIVE_PATH relpath "${ZEPHYR_BASE_REALPATH}" "${PATH_REALPATH}") # Create strings to be written into the file set (include_str "/* Sort key: \"${SORT_KEY}\" */#include \"${relpath}\"")