summaryrefslogtreecommitdiffstats
path: root/externals/find-modules/Findzstd.cmake
blob: 539abbafc12c61022afaf14df4adb6cff4cdcf9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

find_package(PkgConfig QUIET)
pkg_check_modules(PC_zstd QUIET libzstd)

find_path(zstd_INCLUDE_DIR
  NAMES zstd.h
  PATHS ${PC_zstd_INCLUDE_DIRS}
)
find_library(zstd_LIBRARY
  NAMES zstd
  PATHS ${PC_zstd_LIBRARY_DIRS}
)

if(zstd_INCLUDE_DIR)
  file(STRINGS "${zstd_INCLUDE_DIR}/zstd.h" _zstd_version_lines
    REGEX "#define[ \t]+ZSTD_VERSION_(MAJOR|MINOR|RELEASE)")
  string(REGEX REPLACE ".*ZSTD_VERSION_MAJOR *\([0-9]*\).*" "\\1" _zstd_version_major "${_zstd_version_lines}")
  string(REGEX REPLACE ".*ZSTD_VERSION_MINOR *\([0-9]*\).*" "\\1" _zstd_version_minor "${_zstd_version_lines}")
  string(REGEX REPLACE ".*ZSTD_VERSION_RELEASE *\([0-9]*\).*" "\\1" _zstd_version_release "${_zstd_version_lines}")
  set(zstd_VERSION "${_zstd_version_major}.${_zstd_version_minor}.${_zstd_version_release}")
  unset(_zstd_version_major)
  unset(_zstd_version_minor)
  unset(_zstd_version_release)
  unset(_zstd_version_lines)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(zstd
  FOUND_VAR zstd_FOUND
  REQUIRED_VARS
    zstd_LIBRARY
    zstd_INCLUDE_DIR
    zstd_VERSION
  VERSION_VAR zstd_VERSION
)

if(zstd_FOUND)
  set(zstd_LIBRARIES ${zstd_LIBRARY})
  set(zstd_INCLUDE_DIRS ${zstd_INCLUDE_DIR})
  set(zstd_DEFINITIONS ${PC_zstd_CFLAGS_OTHER})
endif()

if(zstd_FOUND AND NOT TARGET zstd::zstd)
  add_library(zstd::zstd UNKNOWN IMPORTED)
  set_target_properties(zstd::zstd PROPERTIES
    IMPORTED_LOCATION "${zstd_LIBRARY}"
    INTERFACE_COMPILE_OPTIONS "${PC_zstd_CFLAGS_OTHER}"
    INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
  )
endif()

mark_as_advanced(
    zstd_INCLUDE_DIR
    zstd_LIBRARY
)