[PATCH] D138361: [cmake] Fix Findzstd.cmake to handle OpenBSD shared libraries
Michał Górny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 19 11:59:57 PST 2022
mgorny created this revision.
mgorny added reviewers: brad, phosek, MaskRay, thesamesam.
Herald added subscribers: StephenFan, krytarowski.
Herald added a project: All.
mgorny requested review of this revision.
Herald added a project: LLVM.
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
https://reviews.llvm.org/D138361
Files:
llvm/cmake/modules/Findzstd.cmake
Index: llvm/cmake/modules/Findzstd.cmake
===================================================================
--- llvm/cmake/modules/Findzstd.cmake
+++ llvm/cmake/modules/Findzstd.cmake
@@ -11,10 +11,8 @@
# zstd::libzstd_static
if(MSVC)
- set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_LINK_LIBRARY_SUFFIX}$")
set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
else()
- set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
endif()
@@ -31,28 +29,29 @@
)
if(zstd_FOUND)
- if(zstd_LIBRARY MATCHES "${zstd_SHARED_LIBRARY_SUFFIX}$" AND
- NOT TARGET zstd::libzstd_shared)
- add_library(zstd::libzstd_shared SHARED IMPORTED)
- if(MSVC)
- # IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library".
- get_filename_component(zstd_DIRNAME "${zstd_LIBRARY}" DIRECTORY)
- string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}")
- get_filename_component(zstd_BASENAME "${zstd_LIBRARY}" NAME)
- string(REGEX REPLACE "\\${CMAKE_LINK_LIBRARY_SUFFIX}$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" zstd_BASENAME "${zstd_BASENAME}")
- set_target_properties(zstd::libzstd_shared PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
- IMPORTED_LOCATION "${zstd_DIRNAME}/${zstd_BASENAME}"
- IMPORTED_IMPLIB "${zstd_LIBRARY}")
- unset(zstd_DIRNAME)
- unset(zstd_BASENAME)
- else()
- set_target_properties(zstd::libzstd_shared PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
- IMPORTED_LOCATION "${zstd_LIBRARY}")
- endif()
- else()
+ if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$")
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
+ else()
+ if (NOT TARGET zstd::libzstd_shared)
+ add_library(zstd::libzstd_shared SHARED IMPORTED)
+ if(MSVC)
+ # IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library".
+ get_filename_component(zstd_DIRNAME "${zstd_LIBRARY}" DIRECTORY)
+ string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}")
+ get_filename_component(zstd_BASENAME "${zstd_LIBRARY}" NAME)
+ string(REGEX REPLACE "\\${CMAKE_LINK_LIBRARY_SUFFIX}$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" zstd_BASENAME "${zstd_BASENAME}")
+ set_target_properties(zstd::libzstd_shared PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${zstd_DIRNAME}/${zstd_BASENAME}"
+ IMPORTED_IMPLIB "${zstd_LIBRARY}")
+ unset(zstd_DIRNAME)
+ unset(zstd_BASENAME)
+ else()
+ set_target_properties(zstd::libzstd_shared PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${zstd_LIBRARY}")
+ endif()
+ endif()
endif()
if(zstd_STATIC_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
NOT TARGET zstd::libzstd_static)
@@ -63,7 +62,6 @@
endif()
endif()
-unset(zstd_SHARED_LIBRARY_SUFFIX)
unset(zstd_STATIC_LIBRARY_SUFFIX)
mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138361.476695.patch
Type: text/x-patch
Size: 3264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221119/496ca7c9/attachment.bin>
More information about the llvm-commits
mailing list