FindLibArchive.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #.rst:
  2. # FindLibArchive
  3. # --------------
  4. #
  5. # Find libarchive library and headers
  6. #
  7. # The module defines the following variables:
  8. #
  9. # ::
  10. #
  11. # LibArchive_FOUND - true if libarchive was found
  12. # LibArchive_INCLUDE_DIRS - include search path
  13. # LibArchive_LIBRARIES - libraries to link
  14. # LibArchive_VERSION - libarchive 3-component version number
  15. #=============================================================================
  16. # Copyright 2010 Kitware, Inc.
  17. #
  18. # Distributed under the OSI-approved BSD License (the "License");
  19. # see accompanying file Copyright.txt for details.
  20. #
  21. # This software is distributed WITHOUT ANY WARRANTY; without even the
  22. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  23. # See the License for more information.
  24. #=============================================================================
  25. # (To distribute this file outside of CMake, substitute the full
  26. # License text for the above reference.)
  27. find_path(LibArchive_INCLUDE_DIR
  28. NAMES archive.h
  29. PATHS
  30. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/include"
  31. )
  32. find_library(LibArchive_LIBRARY
  33. NAMES archive libarchive
  34. PATHS
  35. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/lib"
  36. )
  37. mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY)
  38. # Extract the version number from the header.
  39. if(LibArchive_INCLUDE_DIR AND EXISTS "${LibArchive_INCLUDE_DIR}/archive.h")
  40. # The version string appears in one of three known formats in the header:
  41. # #define ARCHIVE_LIBRARY_VERSION "libarchive 2.4.12"
  42. # #define ARCHIVE_VERSION_STRING "libarchive 2.8.4"
  43. # #define ARCHIVE_VERSION_ONLY_STRING "3.2.0"
  44. # Match any format.
  45. set(_LibArchive_VERSION_REGEX "^#define[ \t]+ARCHIVE[_A-Z]+VERSION[_A-Z]*[ \t]+\"(libarchive +)?([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\"]*\".*$")
  46. file(STRINGS "${LibArchive_INCLUDE_DIR}/archive.h" _LibArchive_VERSION_STRING LIMIT_COUNT 1 REGEX "${_LibArchive_VERSION_REGEX}")
  47. if(_LibArchive_VERSION_STRING)
  48. string(REGEX REPLACE "${_LibArchive_VERSION_REGEX}" "\\2.\\3.\\4" LibArchive_VERSION "${_LibArchive_VERSION_STRING}")
  49. endif()
  50. unset(_LibArchive_VERSION_REGEX)
  51. unset(_LibArchive_VERSION_STRING)
  52. endif()
  53. # Handle the QUIETLY and REQUIRED arguments and set LIBARCHIVE_FOUND
  54. # to TRUE if all listed variables are TRUE.
  55. # (Use ${CMAKE_ROOT}/Modules instead of ${CMAKE_CURRENT_LIST_DIR} because CMake
  56. # itself includes this FindLibArchive when built with an older CMake that does
  57. # not provide it. The older CMake also does not have CMAKE_CURRENT_LIST_DIR.)
  58. include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
  59. find_package_handle_standard_args(LibArchive
  60. REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
  61. VERSION_VAR LibArchive_VERSION
  62. )
  63. set(LibArchive_FOUND ${LIBARCHIVE_FOUND})
  64. unset(LIBARCHIVE_FOUND)
  65. if(LibArchive_FOUND)
  66. set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR})
  67. set(LibArchive_LIBRARIES ${LibArchive_LIBRARY})
  68. endif()