Skip to content

Commit 56f94ed

Browse files
committed
[llvm] [cmake] Support finding both static and shared zstd via FindZstd
Improve the logic in FindZstd to support finding both shared and static variants of the zstd library simultaneously. Otherwise, if the shared library is installed, zstd::libzstd_static is not declared at all and CMake fails if LLVM_USE_STATIC_ZSTD is used. Differential Revision: https://reviews.llvm.org/D135457
1 parent d3ce133 commit 56f94ed

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

llvm/cmake/modules/Findzstd.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# If successful, the following variables will be defined:
44
# zstd_INCLUDE_DIR
55
# zstd_LIBRARY
6+
# zstd_STATIC_LIBRARY
67
# zstd_FOUND
78
#
89
# Additionally, one of the following import targets will be defined:
@@ -19,6 +20,9 @@ endif()
1920

2021
find_path(zstd_INCLUDE_DIR NAMES zstd.h)
2122
find_library(zstd_LIBRARY NAMES zstd zstd_static)
23+
find_library(zstd_STATIC_LIBRARY NAMES
24+
zstd_static
25+
"${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}")
2226

2327
include(FindPackageHandleStandardArgs)
2428
find_package_handle_standard_args(
@@ -33,17 +37,19 @@ if(zstd_FOUND)
3337
set_target_properties(zstd::libzstd_shared PROPERTIES
3438
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
3539
IMPORTED_LOCATION "${zstd_LIBRARY}")
40+
else()
41+
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
3642
endif()
37-
if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
43+
if(zstd_STATIC_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
3844
NOT TARGET zstd::libzstd_static)
3945
add_library(zstd::libzstd_static STATIC IMPORTED)
4046
set_target_properties(zstd::libzstd_static PROPERTIES
4147
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
42-
IMPORTED_LOCATION "${zstd_LIBRARY}")
48+
IMPORTED_LOCATION "${zstd_STATIC_LIBRARY}")
4349
endif()
4450
endif()
4551

4652
unset(zstd_SHARED_LIBRARY_SUFFIX)
4753
unset(zstd_STATIC_LIBRARY_SUFFIX)
4854

49-
mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY)
55+
mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)

0 commit comments

Comments
 (0)