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)