[llvm] [cmake] Update Findzstd.cmake to detect the version of zstd (PR #87331)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 2 03:55:13 PDT 2024
https://github.com/andriish created https://github.com/llvm/llvm-project/pull/87331
Update Findzstd.cmake to detect the version of zstd
>From 347ef0c67cc237477b803b2f41d80db0d2d5bae8 Mon Sep 17 00:00:00 2001
From: andriish <andriish at users.noreply.github.com>
Date: Tue, 2 Apr 2024 12:54:42 +0200
Subject: [PATCH] Update Findzstd.cmake to detect the version of zstd
Update Findzstd.cmake to detect the version of zstd
---
llvm/cmake/modules/Findzstd.cmake | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/llvm/cmake/modules/Findzstd.cmake b/llvm/cmake/modules/Findzstd.cmake
index 178d99565f044e..4f392cf7065659 100644
--- a/llvm/cmake/modules/Findzstd.cmake
+++ b/llvm/cmake/modules/Findzstd.cmake
@@ -5,6 +5,7 @@
# zstd_LIBRARY
# zstd_STATIC_LIBRARY
# zstd_FOUND
+# zstd_VERSION
#
# Additionally, one of the following import targets will be defined:
# zstd::libzstd_shared
@@ -29,6 +30,16 @@ find_package_handle_standard_args(
)
if(zstd_FOUND)
+ file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h ZSTD_VERSION_MAJOR_STRING_CONTENT REGEX "^#define[ ]+ZSTD_VERSION_MAJOR[ ]+" )
+ file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h ZSTD_VERSION_MINOR_STRING_CONTENT REGEX "^#define[ ]+ZSTD_VERSION_MINOR[ ]+" )
+ file(STRINGS ${zstd_INCLUDE_DIR}/zstd.h ZSTD_VERSION_RELEASE_STRING_CONTENT REGEX "^#define[ ]+ZSTD_VERSION_RELEASE[ ]+" )
+ set(zstd_VERSION "0.0.0")
+ if (ZSTD_VERSION_MAJOR_STRING_CONTENT AND ZSTD_VERSION_MINOR_STRING_CONTENT AND ZSTD_VERSION_RELEASE_STRING_CONTENT)
+ string(REGEX MATCH "[1234567890.]+[a-zA-Z]*" ZSTD_VERSION_MAJOR ${ZSTD_VERSION_MAJOR_STRING_CONTENT})
+ string(REGEX MATCH "[1234567890.]+[a-zA-Z]*" ZSTD_VERSION_MINOR ${ZSTD_VERSION_MINOR_STRING_CONTENT})
+ string(REGEX MATCH "[1234567890.]+[a-zA-Z]*" ZSTD_VERSION_RELEASE ${ZSTD_VERSION_RELEASE_STRING_CONTENT})
+ set(zstd_VERSION "${ZSTD_VERSION_MAJOR}.${ZSTD_VERSION_MINOR}.${ZSTD_VERSION_RELEASE}")
+ endif()
if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$")
set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
elseif (NOT TARGET zstd::libzstd_shared)
@@ -62,4 +73,10 @@ endif()
unset(zstd_STATIC_LIBRARY_SUFFIX)
-mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(zstd REQUIRED_VARS zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY
+ VERSION_VAR zstd_VERSION
+ )
+
+mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY zstd_VERSION)
More information about the llvm-commits
mailing list