Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindLibArchive.cmake
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 #=============================================================================
10 # Copyright 2010 Kitware, Inc.
11 #
12 # Distributed under the OSI-approved BSD License (the "License");
13 # see accompanying file Copyright.txt for details.
14 #
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.)
21
22 find_path(LibArchive_INCLUDE_DIR
23   NAMES archive.h
24   PATHS
25   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/include"
26   )
27
28 find_library(LibArchive_LIBRARY
29   NAMES archive libarchive
30   PATHS
31   "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/lib"
32   )
33
34 mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY)
35
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}")
46   endif()
47   unset(_LibArchive_VERSION_REGEX)
48   unset(_LibArchive_VERSION_STRING)
49 endif()
50
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
60   )
61 set(LibArchive_FOUND ${LIBARCHIVE_FOUND})
62 unset(LIBARCHIVE_FOUND)
63
64 if(LibArchive_FOUND)
65   set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR})
66   set(LibArchive_LIBRARIES    ${LibArchive_LIBRARY})
67 endif()