[llvm] Fix the issue of linking a wrong import library of zstd (PR #134812)

Jianshan Jiang via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 01:50:45 PDT 2025


https://github.com/jiangjianshan created https://github.com/llvm/llvm-project/pull/134812

Hello,
I use the scripts from `https://github.com/jiangjianshan/msvc-pkg` to build many libraries if they are list in `packages` folder on that github repository. One time I have found in current or previous version of llvm-project, after you run `llvm-config --system-libs`, you will find 'zstd.dll.lib' but not 'zstd.lib' in the output. But 'zstd.dll.lib' is not exist when using MSVC compiler. This pull request will fix the issue and make llvm-project link to the correct import library of zstd when using MSVC compiler. 

>From 44f5b53ed74ed09a7c7f58fa45b218bb87b68ebe Mon Sep 17 00:00:00 2001
From: Jianshan Jiang <jiangjianshan1103 at gmail.com>
Date: Tue, 8 Apr 2025 16:43:48 +0800
Subject: [PATCH] Fix the issue of linking a wrong import library of zstd

---
 llvm/lib/Support/CMakeLists.txt | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 98ffd829d80b8..19f97444a6e37 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -336,10 +336,18 @@ if(LLVM_ENABLE_ZSTD)
   # CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
   if(CMAKE_BUILD_TYPE)
     string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
-    get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION_${build_type})
+    if(MSVC)
+      get_property(zstd_library TARGET ${zstd_target} PROPERTY IMPORTED_IMPLIB_${build_type})
+    else()
+      get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION_${build_type})
+    endif()
   endif()
   if(NOT zstd_library)
-    get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION)
+    if(MSVC)
+      get_property(zstd_library TARGET ${zstd_target} PROPERTY IMPORTED_IMPLIB)
+    else()
+      get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION)
+    endif()
   endif()
   if (zstd_target STREQUAL zstd::libzstd_shared)
     get_library_name(${zstd_library} zstd_library)



More information about the llvm-commits mailing list