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