Skip to content

[SYCL] Retrieve and print zstd version during configure #18840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions llvm/cmake/modules/Findzstd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@
# zstd::libzstd_shared
# zstd::libzstd_static

# Function to get zstd version.
function(get_zstd_version_string zstd_INCLUDE_DIR OUT_VAR)

# Check if zstd.h file is present. Expectation is that this function will only
# be called if zstd is found and the include directory is valid.
if(NOT EXISTS "${zstd_INCLUDE_DIR}/zstd.h")
message(FATAL_ERROR "zstd.h not found in ${zstd_INCLUDE_DIR}. "
"Please set zstd_INCLUDE_DIR to the directory containing zstd.h.")
endif()

# Read the version string from zstd.h.
# The version is defined as macros ZSTD_VERSION_MAJOR, ZSTD_VERSION_MINOR,
# and ZSTD_VERSION_RELEASE in zstd.h.
file(READ "${zstd_INCLUDE_DIR}/zstd.h" content)
string(REGEX MATCH "#define[ \t]+ZSTD_VERSION_MAJOR[ \t]+([0-9]+)" _major_match "${content}")
string(REGEX MATCH "#define[ \t]+ZSTD_VERSION_MINOR[ \t]+([0-9]+)" _minor_match "${content}")
string(REGEX MATCH "#define[ \t]+ZSTD_VERSION_RELEASE[ \t]+([0-9]+)" _patch_match "${content}")

if(_major_match AND _minor_match AND _patch_match)
string(REGEX REPLACE ".*#define[ \t]+ZSTD_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _major "${_major_match}")
string(REGEX REPLACE ".*#define[ \t]+ZSTD_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _minor "${_minor_match}")
string(REGEX REPLACE ".*#define[ \t]+ZSTD_VERSION_RELEASE[ \t]+([0-9]+).*" "\\1" _patch "${_patch_match}")
set(_version "${_major}.${_minor}.${_patch}")
set(${OUT_VAR} "${_version}" PARENT_SCOPE)
else()
set(${OUT_VAR} "" PARENT_SCOPE)
endif()
endfunction()

if(MSVC OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
else()
Expand All @@ -28,6 +57,12 @@ find_package_handle_standard_args(
zstd_LIBRARY zstd_INCLUDE_DIR
)

# Get zstd version.
if (zstd_FOUND AND zstd_INCLUDE_DIR)
get_zstd_version_string("${zstd_INCLUDE_DIR}" zstd_VERSION_STRING)
message(STATUS "Found zstd version ${zstd_VERSION_STRING}.")
endif()

if(zstd_FOUND)
if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$")
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
Expand Down