3 # Find Zstd includes and library
5 # ZSTD_INCLUDE_DIRS - where to find zstd.h, etc.
6 # ZSTD_LIBRARIES - List of libraries when using Zstd.
7 # ZSTD_FOUND - True if Zstd found.
8 # ZSTD_DLL_DIR - (Windows) Path to the Zstd DLL
9 # ZSTD_DLL - (Windows) Name of the Zstd DLL
11 include( FindWSWinLibs )
12 FindWSWinLibs( "zstd-.*" "ZSTD_HINTS" )
14 if( NOT USE_REPOSITORY)
15 find_package(PkgConfig)
16 pkg_search_module(ZSTD libzstd)
19 find_path(ZSTD_INCLUDE_DIR
21 HINTS "${ZSTD_INCLUDEDIR}" "${ZSTD_HINTS}/include"
26 find_library(ZSTD_LIBRARY
28 HINTS "${ZSTD_LIBDIR}" "${ZSTD_HINTS}/lib"
34 if( ZSTD_INCLUDE_DIR AND ZSTD_LIBRARY )
35 file(STRINGS ${ZSTD_INCLUDE_DIR}/zstd.h ZSTD_VERSION_MAJOR
36 REGEX "#define[ ]+ZSTD_VERSION_MAJOR[ ]+[0-9]+")
37 string(REGEX MATCH "[0-9]+" ZSTD_VERSION_MAJOR ${ZSTD_VERSION_MAJOR})
38 file(STRINGS ${ZSTD_INCLUDE_DIR}/zstd.h ZSTD_VERSION_MINOR
39 REGEX "#define[ ]+ZSTD_VERSION_MINOR[ ]+[0-9]+")
40 string(REGEX MATCH "[0-9]+" ZSTD_VERSION_MINOR ${ZSTD_VERSION_MINOR})
41 file(STRINGS ${ZSTD_INCLUDE_DIR}/zstd.h ZSTD_VERSION_RELEASE
42 REGEX "#define[ ]+ZSTD_VERSION_RELEASE[ ]+[0-9]+")
43 string(REGEX MATCH "[0-9]+" ZSTD_VERSION_RELEASE ${ZSTD_VERSION_RELEASE})
44 set(ZSTD_VERSION ${ZSTD_VERSION_MAJOR}.${ZSTD_VERSION_MINOR}.${ZSTD_VERSION_RELEASE})
47 include(FindPackageHandleStandardArgs)
48 find_package_handle_standard_args(ZSTD
49 REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR
50 VERSION_VAR ZSTD_VERSION)
53 set( ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR} )
54 set( ZSTD_LIBRARIES ${ZSTD_LIBRARY} )
56 set ( ZSTD_DLL_DIR "${ZSTD_HINTS}/bin"
57 CACHE PATH "Path to Zstd DLL"
59 file( GLOB _zstd_dll RELATIVE "${ZSTD_DLL_DIR}"
60 "${ZSTD_DLL_DIR}/zstd*.dll"
62 set ( ZSTD_DLL ${_zstd_dll}
63 # We're storing filenames only. Should we use STRING instead?
64 CACHE FILEPATH "Zstd DLL file name"
66 mark_as_advanced( ZSTD_DLL_DIR ZSTD_DLL )
69 set( ZSTD_INCLUDE_DIRS )
73 mark_as_advanced( ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS )