Skip to content

Commit 2fbfbf4

Browse files
authored
[cmake] Resolve symlink when finding install prefix (llvm#124743)
When determining the install prefix in LLVMConfig.cmake etc resolve symlinks in CMAKE_CURRENT_LIST_FILE first. The motivation for this is to support symlinks like `/usr/lib64/cmake/llvm` to `/usr/lib64/llvm19/lib/cmake/llvm`. This only works correctly if the paths are relative to the resolved symlink. It's worth noting that this *mostly* already works out of the box, because cmake automatically does the symlink resolution when the library is found via CMAKE_PREFIX_PATH. It just doesn't happen when it's found via the default prefix path.
1 parent 22c6674 commit 2fbfbf4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cmake/Modules/FindPrefixFromConfig.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ function(find_prefix_from_config out_var prefix_var path_to_leave)
3939
# install prefix, and avoid hard-coding any absolute paths.
4040
set(config_code
4141
"# Compute the installation prefix from this LLVMConfig.cmake file location."
42-
"get_filename_component(${prefix_var} \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
42+
"get_filename_component(${prefix_var} \"\${CMAKE_CURRENT_LIST_FILE}\" REALPATH)")
4343
# Construct the proper number of get_filename_component(... PATH)
4444
# calls to compute the installation prefix.
45-
string(REGEX REPLACE "/" ";" _count "${path_to_leave}")
45+
string(REGEX REPLACE "/" ";" _count "${path_to_leave}/plus_one")
4646
foreach(p ${_count})
4747
list(APPEND config_code
4848
"get_filename_component(${prefix_var} \"\${${prefix_var}}\" PATH)")

0 commit comments

Comments
 (0)