@@ -974,8 +974,8 @@ macro(add_llvm_library name)
974974 endif ()
975975 install (TARGETS ${name}
976976 ${export_to_llvmexports}
977- LIBRARY DESTINATION lib ${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
978- ARCHIVE DESTINATION lib ${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
977+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
978+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ${LLVM_LIBDIR_SUFFIX} COMPONENT ${name}
979979 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} " COMPONENT ${name} )
980980
981981 if (NOT LLVM_ENABLE_IDE)
@@ -2243,7 +2243,7 @@ function(llvm_install_library_symlink name dest type)
22432243 set (LLVM_LINK_OR_COPY copy)
22442244 endif ()
22452245
2246- set (output_dir lib ${LLVM_LIBDIR_SUFFIX} )
2246+ set (output_dir ${CMAKE_INSTALL_FULL_LIBDIR} ${LLVM_LIBDIR_SUFFIX} )
22472247 if (WIN32 AND "${type} " STREQUAL "SHARED" )
22482248 set (output_dir "${CMAKE_INSTALL_BINDIR} " )
22492249 endif ()
@@ -2519,16 +2519,37 @@ function(llvm_setup_rpath name)
25192519
25202520 if (APPLE )
25212521 set (_install_name_dir INSTALL_NAME_DIR "@rpath" )
2522- set (_install_rpath "@loader_path/../lib ${LLVM_LIBDIR_SUFFIX} " ${extra_libdir} )
2522+ set (_install_rpath ${extra_libdir} )
25232523 elseif (${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS )
25242524 # $ORIGIN is not interpreted at link time by aix ld.
25252525 # Since BUILD_SHARED_LIBS is only recommended for use by developers,
25262526 # hardcode the rpath to build/install lib dir first in this mode.
25272527 # FIXME: update this when there is better solution.
2528- set (_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR} " "${CMAKE_INSTALL_PREFIX} /lib ${LLVM_LIBDIR_SUFFIX} " ${extra_libdir} )
2528+ set (_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR} " "${CMAKE_INSTALL_FULL_LIBDIR} ${LLVM_LIBDIR_SUFFIX} " ${extra_libdir} )
25292529 elseif (UNIX )
2530+ # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back
2531+ # to `_install_rpath` here.
2532+ #
2533+ # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e.
2534+ # clang); instead LLVM is its own package and thus lands at its own nix
2535+ # store path. This makes it so that the default relative rpath (`../lib/`)
2536+ # does not point at the LLVM shared objects.
2537+ #
2538+ # More discussion here:
2539+ # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329
2540+ # - https://reviews.llvm.org/D146918 (16.0.5+)
2541+ #
2542+ # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is
2543+ # no potential that this will result in us pulling in the "wrong" LLVM.
2544+ # Adding this to the build rpath means we aren't forced to use
2545+ # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build
2546+ # dir, pre-install, will have the right rpath for LLVM).
2547+ #
2548+ # As noted in the differential above, an alternative solution is to have
2549+ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set
2550+ # `CMAKE_INSTALL_RPATH`.
25302551 set (_build_rpath "\$ ORIGIN/../lib${LLVM_LIBDIR_SUFFIX} " ${extra_libdir} )
2531- set (_install_rpath " \$ ORIGIN/../lib ${LLVM_LIBDIR_SUFFIX} " )
2552+ set (_install_rpath ${extra_libdir} )
25322553 if (${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)" )
25332554 set_property (TARGET ${name} APPEND_STRING PROPERTY
25342555 LINK_FLAGS " -Wl,-z,origin " )
0 commit comments