[PATCH] D135153: [CMake] Provide Findzstd module

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 4 06:06:35 PDT 2022


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

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

Based on earlier work of Petr Hosek.  The support for pkg-config is
inspired by FindLibEdit.cmake.


https://reviews.llvm.org/D135153

Files:
  llvm/cmake/modules/Findzstd.cmake


Index: llvm/cmake/modules/Findzstd.cmake
===================================================================
--- /dev/null
+++ llvm/cmake/modules/Findzstd.cmake
@@ -0,0 +1,47 @@
+# Try to find the zstd library
+#
+# If successful, the following variables will be defined:
+# zstd_INCLUDE_DIR
+# zstd_LIBRARY
+# zstd_STATIC_LIBRARY
+# zstd_FOUND
+#
+# Additionally, the following import targets will be defined:
+# zstd::libzstd_shared
+# zstd::libzstd_static
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_LIBZSTD QUIET libzstd)
+
+find_path(zstd_INCLUDE_DIR NAMES zstd.h HINTS ${PC_LIBZSTD_INCLUDE_DIRS})
+find_library(zstd_LIBRARY NAMES zstd HINTS ${PC_LIBZSTD_LIBRARY_DIRS})
+
+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}")
+
+    # Try to find the static library in addition to the shared library.
+    find_library(zstd_STATIC_LIBRARY
+      NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}")
+  else()
+    set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
+  endif()
+  if(zstd_STATIC_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_STATIC_LIBRARY}")
+  endif()
+endif()
+
+mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135153.464982.patch
Type: text/x-patch
Size: 1852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221004/051bc0a5/attachment.bin>


More information about the llvm-commits mailing list