source: pacpussensors/trunk/Vislab/20150310_lib3dv-1.2.0/cmake/FindLibArchive.cmake

Last change on this file was 136, checked in by ldecherf, 8 years ago

Doc

File size: 3.7 KB
Line 
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
22find_path(LibArchive_INCLUDE_DIR
23 NAMES archive.h
24 PATHS ${LibArchive_INCLUDEDIR} ${LibArchive_ROOT} "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]")
25
26set(LibArchive_LIB_PREFIX "")
27if(WIN32 AND LibArchive_USE_STATIC_LIBS AND NOT CYGWIN)
28 set(LibArchive_LIB_PREFIX "lib")
29endif()
30
31# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
32if(LibArchive_USE_STATIC_LIBS)
33 set(_libarchive_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
34 if(WIN32)
35 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
36 else()
37 set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
38 endif()
39endif()
40
41find_library(LibArchive_LIBRARY
42 NAMES archive libarchive
43 PATHS ${LibArchive_LIBRARYDIR} ${LibArchive_ROOT} "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]")
44
45# Restore the original find library ordering
46if(LibArchive_USE_STATIC_LIBS)
47 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_libarchive_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
48
49 if(LibArchive_LIBRARY)
50 add_definitions(-DLIBARCHIVE_STATIC)
51 endif()
52endif()
53
54mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY)
55
56# Extract the version number from the header.
57if(LibArchive_INCLUDE_DIR AND EXISTS "${LibArchive_INCLUDE_DIR}/archive.h")
58 # The version string appears in one of two known formats in the header:
59 # #define ARCHIVE_LIBRARY_VERSION "libarchive 2.4.12"
60 # #define ARCHIVE_VERSION_STRING "libarchive 2.8.4"
61 # Match either format.
62 set(_LibArchive_VERSION_REGEX "^#define[ \t]+ARCHIVE[_A-Z]+VERSION[_A-Z]*[ \t]+\"libarchive +([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\"]*\".*$")
63 file(STRINGS "${LibArchive_INCLUDE_DIR}/archive.h" _LibArchive_VERSION_STRING LIMIT_COUNT 1 REGEX "${_LibArchive_VERSION_REGEX}")
64 if(_LibArchive_VERSION_STRING)
65 string(REGEX REPLACE "${_LibArchive_VERSION_REGEX}" "\\1.\\2.\\3" LibArchive_VERSION "${_LibArchive_VERSION_STRING}")
66 endif()
67 unset(_LibArchive_VERSION_REGEX)
68 unset(_LibArchive_VERSION_STRING)
69endif()
70
71# Handle the QUIETLY and REQUIRED arguments and set LIBARCHIVE_FOUND
72# to TRUE if all listed variables are TRUE.
73# (Use ${CMAKE_ROOT}/Modules instead of ${CMAKE_CURRENT_LIST_DIR} because CMake
74# itself includes this FindLibArchive when built with an older CMake that does
75# not provide it. The older CMake also does not have CMAKE_CURRENT_LIST_DIR.)
76include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
77find_package_handle_standard_args(LibArchive
78 REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
79 VERSION_VAR LibArchive_VERSION
80 )
81set(LibArchive_FOUND ${LIBARCHIVE_FOUND})
82unset(LIBARCHIVE_FOUND)
83
84if(LibArchive_FOUND)
85 set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR})
86 set(LibArchive_LIBRARIES ${LibArchive_LIBRARY})
87endif()
Note: See TracBrowser for help on using the repository browser.