1 # Try to find the zstd library
3 # If successful, the following variables will be defined:
9 # Additionally, one of the following import targets will be defined:
10 # zstd::libzstd_shared
11 # zstd::libzstd_static
14 set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
16 set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
19 find_path(zstd_INCLUDE_DIR NAMES zstd.h)
20 find_library(zstd_LIBRARY NAMES zstd zstd_static)
21 find_library(zstd_STATIC_LIBRARY NAMES
23 "${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}")
25 include(FindPackageHandleStandardArgs)
26 find_package_handle_standard_args(
28 zstd_LIBRARY zstd_INCLUDE_DIR
32 if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$")
33 set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
34 elseif (NOT TARGET zstd::libzstd_shared)
35 add_library(zstd::libzstd_shared SHARED IMPORTED)
37 # IMPORTED_LOCATION is the path to the DLL and IMPORTED_IMPLIB is the "library".
38 get_filename_component(zstd_DIRNAME "${zstd_LIBRARY}" DIRECTORY)
39 string(REGEX REPLACE "${CMAKE_INSTALL_LIBDIR}$" "${CMAKE_INSTALL_BINDIR}" zstd_DIRNAME "${zstd_DIRNAME}")
40 get_filename_component(zstd_BASENAME "${zstd_LIBRARY}" NAME)
41 string(REGEX REPLACE "\\${CMAKE_LINK_LIBRARY_SUFFIX}$" "${CMAKE_SHARED_LIBRARY_SUFFIX}" zstd_BASENAME "${zstd_BASENAME}")
42 set_target_properties(zstd::libzstd_shared PROPERTIES
43 INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
44 IMPORTED_LOCATION "${zstd_DIRNAME}/${zstd_BASENAME}"
45 IMPORTED_IMPLIB "${zstd_LIBRARY}")
49 set_target_properties(zstd::libzstd_shared PROPERTIES
50 INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
51 IMPORTED_LOCATION "${zstd_LIBRARY}")
54 if(zstd_STATIC_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
55 NOT TARGET zstd::libzstd_static)
56 add_library(zstd::libzstd_static STATIC IMPORTED)
57 set_target_properties(zstd::libzstd_static PROPERTIES
58 INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
59 IMPORTED_LOCATION "${zstd_STATIC_LIBRARY}")
63 unset(zstd_STATIC_LIBRARY_SUFFIX)
65 mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)