[llvm] 56f94ed - [llvm] [cmake] Support finding both static and shared zstd via FindZstd

Michał Górny via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 11 22:14:53 PDT 2022


Author: Michał Górny
Date: 2022-10-12T07:14:28+02:00
New Revision: 56f94ede2af9a327e59fe84dbf8cbbb7bb1dfa79

URL: https://github.com/llvm/llvm-project/commit/56f94ede2af9a327e59fe84dbf8cbbb7bb1dfa79
DIFF: https://github.com/llvm/llvm-project/commit/56f94ede2af9a327e59fe84dbf8cbbb7bb1dfa79.diff

LOG: [llvm] [cmake] Support finding both static and shared zstd via FindZstd

Improve the logic in FindZstd to support finding both shared and static
variants of the zstd library simultaneously.  Otherwise, if the shared
library is installed, zstd::libzstd_static is not declared at all
and CMake fails if LLVM_USE_STATIC_ZSTD is used.

Differential Revision: https://reviews.llvm.org/D135457

Added: 
    

Modified: 
    llvm/cmake/modules/Findzstd.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/Findzstd.cmake b/llvm/cmake/modules/Findzstd.cmake
index fab9ea803261b..2994eaf7c9980 100644
--- a/llvm/cmake/modules/Findzstd.cmake
+++ b/llvm/cmake/modules/Findzstd.cmake
@@ -3,6 +3,7 @@
 # If successful, the following variables will be defined:
 # zstd_INCLUDE_DIR
 # zstd_LIBRARY
+# zstd_STATIC_LIBRARY
 # zstd_FOUND
 #
 # Additionally, one of the following import targets will be defined:
@@ -19,6 +20,9 @@ endif()
 
 find_path(zstd_INCLUDE_DIR NAMES zstd.h)
 find_library(zstd_LIBRARY NAMES zstd zstd_static)
+find_library(zstd_STATIC_LIBRARY NAMES
+  zstd_static
+  "${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}")
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(
@@ -33,17 +37,19 @@ if(zstd_FOUND)
     set_target_properties(zstd::libzstd_shared PROPERTIES
           INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
           IMPORTED_LOCATION "${zstd_LIBRARY}")
+  else()
+    set(zstd_STATIC_LIBRARY "${zstd_LIBRARY}")
   endif()
-  if(zstd_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND
+  if(zstd_STATIC_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}")
+        IMPORTED_LOCATION "${zstd_STATIC_LIBRARY}")
   endif()
 endif()
 
 unset(zstd_SHARED_LIBRARY_SUFFIX)
 unset(zstd_STATIC_LIBRARY_SUFFIX)
 
-mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY)
+mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY)


        


More information about the llvm-commits mailing list