Skip to content

Commit b484027

Browse files
petrhosektru
authored andcommitted
[CMake] Provide Findzstd module
This module is used to find the system zstd library. The imported targets intentionally use the same name as the generate zstd config CMake file so these can be used interchangeably. Differential Revision: https://reviews.llvm.org/D134990 (cherry picked from commit 2d4fd0b)
1 parent 6fba785 commit b484027

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

llvm/cmake/modules/Findzstd.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Try to find the zstd library
2+
#
3+
# If successful, the following variables will be defined:
4+
# zstd_INCLUDE_DIR
5+
# zstd_LIBRARY
6+
# zstd_FOUND
7+
#
8+
# Additionally, one of the following import targets will be defined:
9+
# zstd::libzstd_shared
10+
# zstd::libzstd_static
11+
12+
if(MSVC)
13+
set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_LINK_LIBRARY_SUFFIX}$")
14+
set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
15+
else()
16+
set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
17+
set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
18+
endif()
19+
20+
find_path(zstd_INCLUDE_DIR NAMES zstd.h)
21+
find_library(zstd_LIBRARY NAMES zstd zstd_static)
22+
23+
include(FindPackageHandleStandardArgs)
24+
find_package_handle_standard_args(
25+
zstd DEFAULT_MSG
26+
zstd_LIBRARY zstd_INCLUDE_DIR
27+
)
28+
29+
if(zstd_FOUND)
30+
if(zstd_LIBRARY MATCHES "${zstd_SHARED_LIBRARY_SUFFIX}$" AND
31+
NOT TARGET zstd::libzstd_shared)
32+
add_library(zstd::libzstd_shared SHARED IMPORTED)
33+
set_target_properties(zstd::libzstd_shared PROPERTIES
34+
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
35+
IMPORTED_LOCATION "${zstd_LIBRARY}")
36+
endif()
37+
if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
38+
NOT TARGET zstd::libzstd_static)
39+
add_library(zstd::libzstd_static STATIC IMPORTED)
40+
set_target_properties(zstd::libzstd_static PROPERTIES
41+
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
42+
IMPORTED_LOCATION "${zstd_LIBRARY}")
43+
endif()
44+
endif()
45+
46+
unset(zstd_SHARED_LIBRARY_SUFFIX)
47+
unset(zstd_STATIC_LIBRARY_SUFFIX)
48+
49+
mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY)

0 commit comments

Comments
 (0)