FindLibArchive.cmake 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindLibArchive
  5. --------------
  6. Find libarchive library and headers.
  7. Libarchive is multi-format archive and compression library.
  8. The module defines the following variables:
  9. ::
  10. LibArchive_FOUND - true if libarchive was found
  11. LibArchive_INCLUDE_DIRS - include search path
  12. LibArchive_LIBRARIES - libraries to link
  13. LibArchive_VERSION - libarchive 3-component version number
  14. #]=======================================================================]
  15. find_path(LibArchive_INCLUDE_DIR
  16. NAMES archive.h
  17. PATHS
  18. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/include"
  19. )
  20. find_library(LibArchive_LIBRARY
  21. NAMES archive libarchive
  22. PATHS
  23. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/lib"
  24. )
  25. mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY)
  26. # Extract the version number from the header.
  27. if(LibArchive_INCLUDE_DIR AND EXISTS "${LibArchive_INCLUDE_DIR}/archive.h")
  28. # The version string appears in one of three known formats in the header:
  29. # #define ARCHIVE_LIBRARY_VERSION "libarchive 2.4.12"
  30. # #define ARCHIVE_VERSION_STRING "libarchive 2.8.4"
  31. # #define ARCHIVE_VERSION_ONLY_STRING "3.2.0"
  32. # Match any format.
  33. set(_LibArchive_VERSION_REGEX "^#define[ \t]+ARCHIVE[_A-Z]+VERSION[_A-Z]*[ \t]+\"(libarchive +)?([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\"]*\".*$")
  34. file(STRINGS "${LibArchive_INCLUDE_DIR}/archive.h" _LibArchive_VERSION_STRING LIMIT_COUNT 1 REGEX "${_LibArchive_VERSION_REGEX}")
  35. if(_LibArchive_VERSION_STRING)
  36. string(REGEX REPLACE "${_LibArchive_VERSION_REGEX}" "\\2.\\3.\\4" LibArchive_VERSION "${_LibArchive_VERSION_STRING}")
  37. endif()
  38. unset(_LibArchive_VERSION_REGEX)
  39. unset(_LibArchive_VERSION_STRING)
  40. endif()
  41. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  42. find_package_handle_standard_args(LibArchive
  43. REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
  44. VERSION_VAR LibArchive_VERSION
  45. )
  46. unset(LIBARCHIVE_FOUND)
  47. if(LibArchive_FOUND)
  48. set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR})
  49. set(LibArchive_LIBRARIES ${LibArchive_LIBRARY})
  50. endif()