[PATCH] D101070: Make `llvm_install_symlink` robust with respect to absolute dirs.

John Ericson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 22 08:09:22 PDT 2021


Ericson2314 created this revision.
Herald added a subscriber: mgorny.
Ericson2314 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

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 downstream packages try to install symlinks in
the now-immutable `LLVM_TOOLS_INSTALL_DIR`.

The new way ensures the downstream projects' prefixes will be used
instead, as desired.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101070

Files:
  clang/cmake/modules/AddClang.cmake
  flang/cmake/modules/AddFlang.cmake
  lld/cmake/modules/AddLLD.cmake
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1875,7 +1875,7 @@
 
 endfunction()
 
-function(llvm_install_symlink name dest)
+function(llvm_install_symlink name dest output_dir)
   cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
   foreach(path ${CMAKE_MODULE_PATH})
     if(EXISTS ${path}/LLVMInstallSymlink.cmake)
@@ -1898,7 +1898,7 @@
   set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
 
   install(SCRIPT ${INSTALL_SYMLINK}
-          CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})"
+          CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
           COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
@@ -1981,7 +1981,8 @@
     endif()
 
     if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS)
-      llvm_install_symlink(${link_name} ${target})
+      GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR)
+      llvm_install_symlink(${link_name} ${target} ${output_dir})
     endif()
   endif()
 endfunction()
Index: lld/cmake/modules/AddLLD.cmake
===================================================================
--- lld/cmake/modules/AddLLD.cmake
+++ lld/cmake/modules/AddLLD.cmake
@@ -69,5 +69,5 @@
 macro(add_lld_symlink name dest)
   add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
   # Always generate install targets
-  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+  llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE)
 endmacro()
Index: flang/cmake/modules/AddFlang.cmake
===================================================================
--- flang/cmake/modules/AddFlang.cmake
+++ flang/cmake/modules/AddFlang.cmake
@@ -134,6 +134,6 @@
 macro(add_flang_symlink name dest)
   add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
   # Always generate install targets
-  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+  llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE)
 endmacro()
 
Index: clang/cmake/modules/AddClang.cmake
===================================================================
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -185,7 +185,7 @@
 macro(add_clang_symlink name dest)
   add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
   # Always generate install targets
-  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+  llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE)
 endmacro()
 
 function(clang_target_link_libraries target type)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101070.339641.patch
Type: text/x-patch
Size: 2727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210422/82d121c0/attachment.bin>


More information about the cfe-commits mailing list