|
| 1 | +# SPDX-License-Identifier: GPL-3.0-or-later; (c) 2025 Andrew D Smith (author) |
| 2 | +#[=======================================================================[.rst: |
| 3 | +FindLIBDEFLATE |
| 4 | +-------------- |
| 5 | +
|
| 6 | +Find the native libdeflate includes and library. |
| 7 | +
|
| 8 | +#]=======================================================================] |
| 9 | + |
| 10 | +# FindLIBDEFLATE.cmake |
| 11 | +# Custom CMake module to find libdeflate |
| 12 | + |
| 13 | +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES |
| 14 | +# ADS: this is taken from the FindBoost.cmake file |
| 15 | +if(LIBDEFLATE_USE_STATIC_LIBS) |
| 16 | + set(_libdeflate_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES |
| 17 | + ${CMAKE_FIND_LIBRARY_SUFFIXES} |
| 18 | + ) |
| 19 | + if(WIN32) |
| 20 | + list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .lib .a) |
| 21 | + else() |
| 22 | + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) |
| 23 | + endif() |
| 24 | +endif() |
| 25 | + |
| 26 | +find_path(LIBDEFLATE_INCLUDE_DIR NAMES libdeflate.h) |
| 27 | +find_library(LIBDEFLATE_LIBRARY NAMES deflate libdeflate) |
| 28 | + |
| 29 | +include(FindPackageHandleStandardArgs) |
| 30 | +find_package_handle_standard_args(LIBDEFLATE |
| 31 | + REQUIRED_VARS LIBDEFLATE_LIBRARY LIBDEFLATE_INCLUDE_DIR |
| 32 | + VERSION_VAR LIBDEFLATE_VERSION |
| 33 | +) |
| 34 | + |
| 35 | +if(LIBDEFLATE_FOUND AND NOT TARGET LIBDEFLATE::LIBDEFLATE) |
| 36 | + add_library(LIBDEFLATE::LIBDEFLATE UNKNOWN IMPORTED) |
| 37 | + set_target_properties(LIBDEFLATE::LIBDEFLATE PROPERTIES |
| 38 | + INTERFACE_INCLUDE_DIRECTORIES "${LIBDEFLATE_INCLUDE_DIR}" |
| 39 | + IMPORTED_LOCATION "${LIBDEFLATE_LIBRARY}" |
| 40 | + ) |
| 41 | +endif() |
| 42 | + |
| 43 | +# Restore the original find library ordering |
| 44 | +# ADS: this is take from the FindBoost.cmake file |
| 45 | +if(LIBDEFLATE_USE_STATIC_LIBS) |
| 46 | + set(CMAKE_FIND_LIBRARY_SUFFIXES |
| 47 | + ${_libdeflate_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES} |
| 48 | + ) |
| 49 | +endif() |
0 commit comments