Skip to content

Commit 5279e6a

Browse files
committed
[cmake] Fix Findzstd.cmake to handle OpenBSD shared libraries
Fix Findzstd CMake to handle shared libraries on OpenBSD correctly. This userland does not use shared library symlinks without SOVERSION, so the result of find_library() does not ever end with zstd_SHARED_LIBRARY_SUFFIX. To work around this, reverse the logic to compare the result against zstd_STATIC_LIBRARY_SUFFIX and assume shared library otherwise. While at it, fix the conditions not to fall back to "result is static library" path if it actually was recognized as a shared library but zstd_shared target already existed. Fixes #59056 Differential Revision: https://reviews.llvm.org/D138361
1 parent 910204c commit 5279e6a

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

llvm/cmake/modules/Findzstd.cmake

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
# zstd::libzstd_static
1212

1313
if(MSVC)
14-
set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_LINK_LIBRARY_SUFFIX}$")
1514
set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
1615
else()
17-
set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
1816
set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
1917
endif()
2018

@@ -31,8 +29,9 @@ find_package_handle_standard_args(
3129
)
3230

3331
if(zstd_FOUND)
34-
if(zstd_LIBRARY MATCHES "${zstd_SHARED_LIBRARY_SUFFIX}$" AND
35-
NOT TARGET zstd::libzstd_shared)
32+
if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$")
33+
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
34+
elseif (NOT TARGET zstd::libzstd_shared)
3635
add_library(zstd::libzstd_shared SHARED IMPORTED)
3736
if(MSVC)
3837
# IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library".
@@ -51,8 +50,6 @@ if(zstd_FOUND)
5150
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
5251
IMPORTED_LOCATION "${zstd_LIBRARY}")
5352
endif()
54-
else()
55-
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
5653
endif()
5754
if(zstd_STATIC_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
5855
NOT TARGET zstd::libzstd_static)
@@ -63,7 +60,6 @@ if(zstd_FOUND)
6360
endif()
6461
endif()
6562

66-
unset(zstd_SHARED_LIBRARY_SUFFIX)
6763
unset(zstd_STATIC_LIBRARY_SUFFIX)
6864

6965
mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)

0 commit comments

Comments
 (0)