Skip to content

Commit 24f2055

Browse files
mplatingsSvyatoslavScherbina
authored andcommitted
Use LLVM_USE_SYMLINKS option in install_symlink
The change to potentially use symlinks on Windows was added in https://reviews.llvm.org/D99170. LLVM_USE_SYMLINKS was added more recently in https://reviews.llvm.org/D135578 and allows specifying at configure time whether or not symlinks should be created. The benefit of using this option is it allows building the package on a symlink-capable Windows machine with symlinks disabled so that the resulting package can be used on a Windows machine that doesn't support symlinks. Differential Revision: https://reviews.llvm.org/D145443 (cherry picked from commit 5c602c4)
1 parent dde9444 commit 24f2055

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,13 +2043,19 @@ function(llvm_install_library_symlink name dest type)
20432043
set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
20442044
set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
20452045

2046+
if(LLVM_USE_SYMLINKS)
2047+
set(LLVM_LINK_OR_COPY create_symlink)
2048+
else()
2049+
set(LLVM_LINK_OR_COPY copy)
2050+
endif()
2051+
20462052
set(output_dir lib${LLVM_LIBDIR_SUFFIX})
20472053
if(WIN32 AND "${type}" STREQUAL "SHARED")
20482054
set(output_dir "${CMAKE_INSTALL_BINDIR}")
20492055
endif()
20502056

20512057
install(SCRIPT ${INSTALL_SYMLINK}
2052-
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
2058+
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\" \"${LLVM_LINK_OR_COPY}\")"
20532059
COMPONENT ${component})
20542060

20552061
endfunction()
@@ -2086,10 +2092,16 @@ function(llvm_install_symlink project name dest)
20862092
set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
20872093
endif()
20882094

2095+
if(LLVM_USE_SYMLINKS)
2096+
set(LLVM_LINK_OR_COPY create_symlink)
2097+
else()
2098+
set(LLVM_LINK_OR_COPY copy)
2099+
endif()
2100+
20892101
set(output_dir "${${project}_TOOLS_INSTALL_DIR}")
20902102

20912103
install(SCRIPT ${INSTALL_SYMLINK}
2092-
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
2104+
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\" \"${LLVM_LINK_OR_COPY}\")"
20932105
COMPONENT ${component})
20942106

20952107
if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)

llvm/cmake/modules/LLVMInstallSymlink.cmake

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
set(CMAKE_INSTALL_LIBDIR "lib")
88
include(GNUInstallDirs)
99

10-
function(install_symlink name target outdir)
10+
function(install_symlink name target outdir link_or_copy)
11+
# link_or_copy is the "command" to pass to cmake -E.
12+
# It should be either "create_symlink" or "copy".
13+
1114
set(DESTDIR $ENV{DESTDIR})
1215
if(NOT IS_ABSOLUTE "${outdir}")
1316
set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}")
@@ -17,12 +20,7 @@ function(install_symlink name target outdir)
1720
message(STATUS "Creating ${name}")
1821

1922
execute_process(
20-
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
21-
WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
22-
if(CMAKE_HOST_WIN32 AND has_err)
23-
execute_process(
24-
COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
25-
WORKING_DIRECTORY "${outdir}")
26-
endif()
23+
COMMAND "${CMAKE_COMMAND}" -E ${link_or_copy} "${target}" "${name}"
24+
WORKING_DIRECTORY "${outdir}")
2725

2826
endfunction()

0 commit comments

Comments
 (0)