[llvm-branch-commits] [llvm] b484027 - [CMake] Provide Findzstd module
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 17 23:30:12 PDT 2022
Author: Petr Hosek
Date: 2022-10-18T08:28:56+02:00
New Revision: b4840279846e1eea44c3dca575395a90c9d77ca0
URL: https://github.com/llvm/llvm-project/commit/b4840279846e1eea44c3dca575395a90c9d77ca0
DIFF: https://github.com/llvm/llvm-project/commit/b4840279846e1eea44c3dca575395a90c9d77ca0.diff
LOG: [CMake] Provide Findzstd module
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.
Differential Revision: https://reviews.llvm.org/D134990
(cherry picked from commit 2d4fd0b6d5d5582ebb8b521d807104235d67aee4)
Added:
llvm/cmake/modules/Findzstd.cmake
Modified:
Removed:
################################################################################
diff --git a/llvm/cmake/modules/Findzstd.cmake b/llvm/cmake/modules/Findzstd.cmake
new file mode 100644
index 0000000000000..fab9ea803261b
--- /dev/null
+++ b/llvm/cmake/modules/Findzstd.cmake
@@ -0,0 +1,49 @@
+# Try to find the zstd library
+#
+# If successful, the following variables will be defined:
+# zstd_INCLUDE_DIR
+# zstd_LIBRARY
+# zstd_FOUND
+#
+# Additionally, one of the following import targets will be defined:
+# zstd::libzstd_shared
+# zstd::libzstd_static
+
+if(MSVC)
+ set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_LINK_LIBRARY_SUFFIX}$")
+ set(zstd_STATIC_LIBRARY_SUFFIX "_static\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
+else()
+ set(zstd_SHARED_LIBRARY_SUFFIX "\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
+ set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$")
+endif()
+
+find_path(zstd_INCLUDE_DIR NAMES zstd.h)
+find_library(zstd_LIBRARY NAMES zstd zstd_static)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ zstd DEFAULT_MSG
+ zstd_LIBRARY zstd_INCLUDE_DIR
+)
+
+if(zstd_FOUND)
+ if(zstd_LIBRARY MATCHES "${zstd_SHARED_LIBRARY_SUFFIX}$" AND
+ NOT TARGET zstd::libzstd_shared)
+ add_library(zstd::libzstd_shared SHARED IMPORTED)
+ set_target_properties(zstd::libzstd_shared PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${zstd_LIBRARY}")
+ endif()
+ if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
+ NOT TARGET zstd::libzstd_static)
+ add_library(zstd::libzstd_static STATIC IMPORTED)
+ set_target_properties(zstd::libzstd_static PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${zstd_LIBRARY}")
+ endif()
+endif()
+
+unset(zstd_SHARED_LIBRARY_SUFFIX)
+unset(zstd_STATIC_LIBRARY_SUFFIX)
+
+mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY)
More information about the llvm-branch-commits
mailing list