Skip to content

Commit 8d5cb0d

Browse files
[SYCL] Retrieve and print zstd version during configure (#18840)
Here's how the output will look: ``` -- Looking for compress2 - found -- Found zstd: /iusers/uagarwal/zstd_build/zstd-1.5.6/install/usr/local/lib/libzstd.so -- Found zstd version 1.5.5. ```
1 parent 3cb953b commit 8d5cb0d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llvm/cmake/modules/Findzstd.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010
# zstd::libzstd_shared
1111
# zstd::libzstd_static
1212

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+
1342
if(MSVC OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
1443
set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
1544
else()
@@ -28,6 +57,12 @@ find_package_handle_standard_args(
2857
zstd_LIBRARY zstd_INCLUDE_DIR
2958
)
3059

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+
3166
if(zstd_FOUND)
3267
if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$")
3368
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")

0 commit comments

Comments
 (0)