Skip to content

Commit e7fc754

Browse files
committed
[CMake] Fix Findzstd module for shared DLL on Windows
Differential Revision: https://reviews.llvm.org/D136065
1 parent 327c45d commit e7fc754

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

llvm/cmake/modules/Findzstd.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,23 @@ if(zstd_FOUND)
3434
if(zstd_LIBRARY MATCHES "${zstd_SHARED_LIBRARY_SUFFIX}$" AND
3535
NOT TARGET zstd::libzstd_shared)
3636
add_library(zstd::libzstd_shared SHARED IMPORTED)
37-
set_target_properties(zstd::libzstd_shared PROPERTIES
37+
if(MSVC)
38+
# IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library".
39+
get_filename_component(zstd_DIRNAME "${zstd_LIBRARY}" DIRECTORY)
40+
string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}")
41+
get_filename_component(zstd_BASENAME "${zstd_LIBRARY}" NAME)
42+
string(REGEX REPLACE "\\${CMAKE_LINK_LIBRARY_SUFFIX}$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" zstd_BASENAME "${zstd_BASENAME}")
43+
set_target_properties(zstd::libzstd_shared PROPERTIES
44+
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
45+
IMPORTED_LOCATION "${zstd_DIRNAME}/${zstd_BASENAME}"
46+
IMPORTED_IMPLIB "${zstd_LIBRARY}")
47+
unset(zstd_DIRNAME)
48+
unset(zstd_BASENAME)
49+
else()
50+
set_target_properties(zstd::libzstd_shared PROPERTIES
3851
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
3952
IMPORTED_LOCATION "${zstd_LIBRARY}")
53+
endif()
4054
else()
4155
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
4256
endif()

0 commit comments

Comments
 (0)