[llvm] [llvm-shlib] Fix the version naming style of libLLVM for Windows (PR #85710)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 15:29:27 PDT 2024


https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/85710

This reverts the changes from 91a384621e5b762d9c173ffd247cfeadd5f436a2 for Windows targets. The changes in that commit don't work as expected for Windows targets (those parts of llvm_add_library don't quite behave the same for Windows), while the previous status quo (producing a library named "libLLVM-<major>.dll") is the defacto standard way of doing versioned library names there, contrary to on Unix.

After that commit, the library always ended up named "libLLVM.dll", executables linking against it would reference "libLLVM.dll", and "libLLVM-<major>.dll" was provided as a symlink.

Thus revert this bit back to as it were, so that executables actually link against a versioned libLLVM, and no separate symlink is needed.

The only thing that might be improved compared to the status quo as it was before these changes, is that the import library is named "lib/libLLVM-<major>.dll.a", while the common style would be to name it plainly "lib/libLLVM.dll.a" (even while it produces references to "libLLVM-<major>.dll", but none of these had that effect for Windows targets.

(As a side note, the llvm-shlib library can be built for MinGW, but not currently in MSVC configurations.)

>From 9b867de4ae43bd100a6547724e63c23517e75686 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Tue, 19 Mar 2024 00:11:35 +0200
Subject: [PATCH] [llvm-shlib] Fix the version naming style of libLLVM for
 Windows

This reverts the changes from 91a384621e5b762d9c173ffd247cfeadd5f436a2
for Windows targets. The changes in that commit don't work
as expected for Windows targets (those parts of llvm_add_library
don't quite behave the same for Windows), while the previous status
quo (producing a library named "libLLVM-<major>.dll") is the
defacto standard way of doing versioned library names there,
contrary to on Unix.

After that commit, the library always ended up named "libLLVM.dll",
executables linking against it would reference "libLLVM.dll", and
"libLLVM-<major>.dll" was provided as a symlink.

Thus revert this bit back to as it were, so that executables
actually link against a versioned libLLVM, and no separate
symlink is needed.

The only thing that might be improved compared to the status quo
as it was before these changes, is that the import library is
named "lib/libLLVM-<major>.dll.a", while the common style would
be to name it plainly "lib/libLLVM.dll.a" (even while it produces
references to "libLLVM-<major>.dll", but none of these had that
effect for Windows targets.

(As a side note, the llvm-shlib library can be built for MinGW, but
not currently in MSVC configurations.)
---
 llvm/tools/llvm-shlib/CMakeLists.txt | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
index 0ad350bcbe0d7b..b20ac318e768db 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -33,9 +33,13 @@ if(LLVM_BUILD_LLVM_DYLIB)
   if (LLVM_LINK_LLVM_DYLIB)
     set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN)
   endif()
-  add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB OUTPUT_NAME LLVM ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
-  # Add symlink for backwards compatibility with old library name
-  llvm_install_library_symlink(LLVM-${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX} $<TARGET_FILE_NAME:LLVM> SHARED FULL_DEST COMPONENT LLVM)
+  if (WIN32)
+    add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
+  else()
+    add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB OUTPUT_NAME LLVM ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
+    # Add symlink for backwards compatibility with old library name
+    llvm_install_library_symlink(LLVM-${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX} $<TARGET_FILE_NAME:LLVM> SHARED FULL_DEST COMPONENT LLVM)
+  endif()
 
   list(REMOVE_DUPLICATES LIB_NAMES)
   if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")



More information about the llvm-commits mailing list