[llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

If `CMAKE_INSTALL_BINDIR` is a different absolute path per project, as
it is with NixOS when we install every package to its own prefix, the
old way fails when the absolute path gets prepended with `CMAKE_INSTALL_PREFIX`.

Using `extend_path` from the install-time script isn't really possible, so we just make the caller responsible for making the path absolute instead.

Also fix one stray `bin` -> `CMAKE_INSTALL_BINDIR`

Reviewed By: sebastian-ne

Differential Revision: https://reviews.llvm.org/D101070
This commit is contained in:
John Ericson 2022-01-21 02:54:54 +00:00
parent ac0d1d5c7b
commit 5acd376438
2 changed files with 18 additions and 7 deletions

View File

@ -1,4 +1,5 @@
include(GNUInstallDirs) include(GNUInstallDirs)
include(ExtendPath)
include(LLVMDistributionSupport) include(LLVMDistributionSupport)
include(LLVMProcessSources) include(LLVMProcessSources)
include(LLVM-Config) include(LLVM-Config)
@ -1953,7 +1954,7 @@ endfunction()
function(add_lit_testsuites project directory) function(add_lit_testsuites project directory)
if (NOT LLVM_ENABLE_IDE) if (NOT LLVM_ENABLE_IDE)
cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN}) cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN})
if (NOT ARG_FOLDER) if (NOT ARG_FOLDER)
set(ARG_FOLDER "Test Subdirectories") set(ARG_FOLDER "Test Subdirectories")
endif() endif()
@ -2009,11 +2010,14 @@ function(llvm_install_library_symlink name dest type)
set(output_dir lib${LLVM_LIBDIR_SUFFIX}) set(output_dir lib${LLVM_LIBDIR_SUFFIX})
if(WIN32 AND "${type}" STREQUAL "SHARED") if(WIN32 AND "${type}" STREQUAL "SHARED")
set(output_dir bin) set(output_dir "${CMAKE_INSTALL_BINDIR}")
endif() endif()
# `install_symlink` needs an absoute path.
extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" "${output_dir}")
install(SCRIPT ${INSTALL_SYMLINK} install(SCRIPT ${INSTALL_SYMLINK}
CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
COMPONENT ${component}) COMPONENT ${component})
endfunction() endfunction()
@ -2048,8 +2052,11 @@ function(llvm_install_symlink project name dest)
set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX}) set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
endif() endif()
# `install_symlink` needs an absoute path.
extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" "${${project}_TOOLS_INSTALL_DIR}")
install(SCRIPT ${INSTALL_SYMLINK} install(SCRIPT ${INSTALL_SYMLINK}
CODE "install_symlink(${full_name} ${full_dest} ${${project}_TOOLS_INSTALL_DIR})" CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
COMPONENT ${component}) COMPONENT ${component})
if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)

View File

@ -1,22 +1,26 @@
# We need to execute this script at installation time because the # We need to execute this script at installation time because the
# DESTDIR environment variable may be unset at configuration time. # DESTDIR environment variable may be unset at configuration time.
# See PR8397. # See PR8397.
#
# `outdir` must be an absolute path. This module gets a very reduced
# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
# for this.
include(GNUInstallDirs) include(GNUInstallDirs)
function(install_symlink name target outdir) function(install_symlink name target outdir)
set(DESTDIR $ENV{DESTDIR}) set(DESTDIR $ENV{DESTDIR})
set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}") set(outdir "${DESTDIR}${outdir}")
message(STATUS "Creating ${name}") message(STATUS "Creating ${name}")
execute_process( execute_process(
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}" COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err) WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
if(CMAKE_HOST_WIN32 AND has_err) if(CMAKE_HOST_WIN32 AND has_err)
execute_process( execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}" COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
WORKING_DIRECTORY "${bindir}") WORKING_DIRECTORY "${outdir}")
endif() endif()
endfunction() endfunction()