FindLibArchive.cmake 2.9 KB

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