Skip to content

Commit e2df120

Browse files
committed
[cmake] Handle absolute install_dir in relative RPATH resolution
`ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH` assumed that `install_dir` is always relative to `CMAKE_INSTALL_PREFIX` when computing the relative path to `CMAKE_INSTALL_FULL_LIBDIR`. However, some build environments (e.g. Fedora or Nix) pass an absolute `CMAKE_INSTALL_LIBDIR`, which results in an incorrect relative path. Fix this by detecting whether `install_dir` is absolute and using it directly as the base directory when computing the relative path.
1 parent 01aeb02 commit e2df120

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

cmake/modules/RootMacros.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,10 +2266,19 @@ endfunction()
22662266
#
22672267
# Arguments:
22682268
# target - The CMake target (e.g., a shared library or executable)
2269-
# install_dir - The install subdirectory relative to CMAKE_INSTALL_PREFIX
2269+
# install_dir - The install subdirectory relative to CMAKE_INSTALL_PREFIX,
2270+
# or an absolute directory.
22702271
#----------------------------------------------------------------------------
22712272
function(ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH target install_dir)
2272-
cmake_path(RELATIVE_PATH CMAKE_INSTALL_FULL_LIBDIR BASE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/${install_dir}" OUTPUT_VARIABLE to_libdir)
2273+
2274+
# Check if install_dir is absolute
2275+
if(IS_ABSOLUTE "${install_dir}")
2276+
set(base_dir "${install_dir}")
2277+
else()
2278+
set(base_dir "${CMAKE_INSTALL_PREFIX}/${install_dir}")
2279+
endif()
2280+
2281+
cmake_path(RELATIVE_PATH CMAKE_INSTALL_FULL_LIBDIR BASE_DIRECTORY "${base_dir}" OUTPUT_VARIABLE to_libdir)
22732282

22742283
# New path
22752284
if(APPLE)

0 commit comments

Comments
 (0)