10
10
# zstd::libzstd_shared
11
11
# zstd::libzstd_static
12
12
13
+ # Function to get zstd version.
14
+ function (get_zstd_version_string zstd_INCLUDE_DIR OUT_VAR )
15
+
16
+ # Check if zstd.h file is present. Expectation is that this function will only
17
+ # be called if zstd is found and the include directory is valid.
18
+ if (NOT EXISTS "${zstd_INCLUDE_DIR} /zstd.h" )
19
+ message (FATAL_ERROR "zstd.h not found in ${zstd_INCLUDE_DIR} . "
20
+ "Please set zstd_INCLUDE_DIR to the directory containing zstd.h." )
21
+ endif ()
22
+
23
+ # Read the version string from zstd.h.
24
+ # The version is defined as macros ZSTD_VERSION_MAJOR, ZSTD_VERSION_MINOR,
25
+ # and ZSTD_VERSION_RELEASE in zstd.h.
26
+ file (READ "${zstd_INCLUDE_DIR} /zstd.h" content )
27
+ string (REGEX MATCH "#define[ \t ]+ZSTD_VERSION_MAJOR[ \t ]+([0-9]+)" _major_match "${content} " )
28
+ string (REGEX MATCH "#define[ \t ]+ZSTD_VERSION_MINOR[ \t ]+([0-9]+)" _minor_match "${content} " )
29
+ string (REGEX MATCH "#define[ \t ]+ZSTD_VERSION_RELEASE[ \t ]+([0-9]+)" _patch_match "${content} " )
30
+
31
+ if (_major_match AND _minor_match AND _patch_match )
32
+ string (REGEX REPLACE ".*#define[ \t ]+ZSTD_VERSION_MAJOR[ \t ]+([0-9]+).*" "\\ 1" _major "${_major_match} " )
33
+ string (REGEX REPLACE ".*#define[ \t ]+ZSTD_VERSION_MINOR[ \t ]+([0-9]+).*" "\\ 1" _minor "${_minor_match} " )
34
+ string (REGEX REPLACE ".*#define[ \t ]+ZSTD_VERSION_RELEASE[ \t ]+([0-9]+).*" "\\ 1" _patch "${_patch_match} " )
35
+ set (_version "${_major} .${_minor} .${_patch} " )
36
+ set (${OUT_VAR} "${_version} " PARENT_SCOPE )
37
+ else ()
38
+ set (${OUT_VAR} "" PARENT_SCOPE )
39
+ endif ()
40
+ endfunction ()
41
+
13
42
if (MSVC OR "${CMAKE_CXX_SIMULATE_ID} " STREQUAL "MSVC" )
14
43
set (zstd_STATIC_LIBRARY_SUFFIX "_static\\ ${CMAKE_STATIC_LIBRARY_SUFFIX} $" )
15
44
else ()
@@ -28,6 +57,12 @@ find_package_handle_standard_args(
28
57
zstd_LIBRARY zstd_INCLUDE_DIR
29
58
)
30
59
60
+ # Get zstd version.
61
+ if (zstd_FOUND AND zstd_INCLUDE_DIR )
62
+ get_zstd_version_string ("${zstd_INCLUDE_DIR} " zstd_VERSION_STRING )
63
+ message (STATUS "Found zstd version ${zstd_VERSION_STRING} ." )
64
+ endif ()
65
+
31
66
if (zstd_FOUND )
32
67
if (zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX} $" )
33
68
set (zstd_STATIC_LIBRARY "${zstd_LIBRARY} " )
0 commit comments