Skip to content

Commit 5c602c4

Browse files
committed
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
1 parent 5541f47 commit 5c602c4

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
@@ -2049,13 +2049,19 @@ function(llvm_install_library_symlink name dest type)
20492049
set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
20502050
set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
20512051

2052+
if(LLVM_USE_SYMLINKS)
2053+
set(LLVM_LINK_OR_COPY create_symlink)
2054+
else()
2055+
set(LLVM_LINK_OR_COPY copy)
2056+
endif()
2057+
20522058
set(output_dir lib${LLVM_LIBDIR_SUFFIX})
20532059
if(WIN32 AND "${type}" STREQUAL "SHARED")
20542060
set(output_dir "${CMAKE_INSTALL_BINDIR}")
20552061
endif()
20562062

20572063
install(SCRIPT ${INSTALL_SYMLINK}
2058-
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
2064+
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\" \"${LLVM_LINK_OR_COPY}\")"
20592065
COMPONENT ${component})
20602066

20612067
endfunction()
@@ -2092,10 +2098,16 @@ function(llvm_install_symlink project name dest)
20922098
set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
20932099
endif()
20942100

2101+
if(LLVM_USE_SYMLINKS)
2102+
set(LLVM_LINK_OR_COPY create_symlink)
2103+
else()
2104+
set(LLVM_LINK_OR_COPY copy)
2105+
endif()
2106+
20952107
set(output_dir "${${project}_TOOLS_INSTALL_DIR}")
20962108

20972109
install(SCRIPT ${INSTALL_SYMLINK}
2098-
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
2110+
CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\" \"${LLVM_LINK_OR_COPY}\")"
20992111
COMPONENT ${component})
21002112

21012113
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)