[PATCH] D134990: [CMake] Provide Findzstd module

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 13:36:10 PDT 2022


phosek created this revision.
phosek added reviewers: Ericson2314, MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
phosek requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This module is used to find the system zstd library. The imported
targets intentionally use the same name as the generate zstd config
CMake file so these can be used interchangeably.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134990

Files:
  llvm/cmake/modules/Findzstd.cmake


Index: llvm/cmake/modules/Findzstd.cmake
===================================================================
--- /dev/null
+++ llvm/cmake/modules/Findzstd.cmake
@@ -0,0 +1,38 @@
+# Try to find the zstd library
+#
+# If successful, the following variables will be defined:
+# ZSTD_INCLUDE_DIR
+# ZSTD_LIBRARY
+# ZSTD_FOUND
+#
+# Additionally, the following import target will be defined:
+# zstd::libzstd_shared
+# zstd::libzstd_static
+
+find_path(ZSTD_INCLUDE_DIR NAMES zstd.h)
+find_library(ZSTD_LIBRARY NAMES zstd)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+    ZSTD DEFAULT_MSG
+    ZSTD_LIBRARY ZSTD_INCLUDE_DIR
+)
+
+if(ZSTD_FOUND)
+  if("${ZSTD_LIBRARY}" MATCHES "\\${CMAKE_SHARED_LIBRARY_SUFFIX}$" AND
+     NOT TARGET zstd::libzstd_shared)
+    add_library(zstd::libzstd_shared UNKNOWN IMPORTED)
+    set_target_properties(zstd::libzstd_shared PROPERTIES
+          INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}"
+          IMPORTED_LOCATION "${ZSTD_LIBRARY}")
+  endif()
+  if("${ZSTD_LIBRARY}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$" AND
+     NOT TARGET zstd::libzstd_static)
+    add_library(zstd::libzstd_static UNKNOWN IMPORTED)
+    set_target_properties(zstd::libzstd_static PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}"
+        IMPORTED_LOCATION "${ZSTD_LIBRARY}")
+  endif()
+endif()
+
+mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134990.464385.patch
Type: text/x-patch
Size: 1426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220930/47131681/attachment.bin>


More information about the llvm-commits mailing list