Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: fix relative path calculate error #74710

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +1338 to +1339
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command get_filename_component(... REALPATH) has been superseded by file(REAL_PATH ...) cmake.

get_filename_component

Get a specific component of a full filename.

Changed in version 3.20: This command has been superseded by the cmake_path() command, except for REALPATH, which is now offered by file(REAL_PATH),

https://cmake.org/cmake/help/latest/command/get_filename_component.html#command:cmake_path

but please note that file(REAL_PATH ...) is affected by CMP0152., and before you ask, then yes, get_filename_component(... REAL_PATH) suffers the same issue related to symlink resolving, but doesn't have a policy for controlling this (always fixed at OLD behavior).

Which again shows that the use of symlinks can be tricky.

Also, variables intended for local use should be written in lowercase, like path_realpath and zephyr_base_realpath.
And please use another name than zephyr_base_realpath, as it is not the real path of Zephyr you are defining, but a subfolder (include).


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}\"")
Expand Down
Loading