CMake/Modules/FindLibArchive.cmake

77 lines
2.8 KiB
CMake
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 19:01:08 +00:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLibArchive
--------------
2019-04-12 14:37:05 +00:00
Find libarchive library and headers.
Libarchive is multi-format archive and compression library.
The module defines the following variables:
::
LibArchive_FOUND - true if libarchive was found
LibArchive_INCLUDE_DIRS - include search path
LibArchive_LIBRARIES - libraries to link
LibArchive_VERSION - libarchive 3-component version number
2019-12-05 18:44:44 +00:00
The module defines the following ``IMPORTED`` targets:
::
LibArchive::LibArchive - target for linking against libarchive
#]=======================================================================]
2010-07-29 13:52:59 +00:00
find_path(LibArchive_INCLUDE_DIR
NAMES archive.h
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/include"
2019-12-05 18:44:44 +00:00
DOC "libarchive include directory"
2010-07-29 13:52:59 +00:00
)
find_library(LibArchive_LIBRARY
NAMES archive libarchive
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/lib"
2019-12-05 18:44:44 +00:00
DOC "libarchive library"
2010-07-29 13:52:59 +00:00
)
mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY)
# Extract the version number from the header.
if(LibArchive_INCLUDE_DIR AND EXISTS "${LibArchive_INCLUDE_DIR}/archive.h")
# The version string appears in one of three known formats in the header:
2010-07-29 13:52:59 +00:00
# #define ARCHIVE_LIBRARY_VERSION "libarchive 2.4.12"
# #define ARCHIVE_VERSION_STRING "libarchive 2.8.4"
# #define ARCHIVE_VERSION_ONLY_STRING "3.2.0"
# Match any format.
set(_LibArchive_VERSION_REGEX "^#define[ \t]+ARCHIVE[_A-Z]+VERSION[_A-Z]*[ \t]+\"(libarchive +)?([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\"]*\".*$")
2010-07-29 13:52:59 +00:00
file(STRINGS "${LibArchive_INCLUDE_DIR}/archive.h" _LibArchive_VERSION_STRING LIMIT_COUNT 1 REGEX "${_LibArchive_VERSION_REGEX}")
if(_LibArchive_VERSION_STRING)
string(REGEX REPLACE "${_LibArchive_VERSION_REGEX}" "\\2.\\3.\\4" LibArchive_VERSION "${_LibArchive_VERSION_STRING}")
2010-07-29 13:52:59 +00:00
endif()
unset(_LibArchive_VERSION_REGEX)
unset(_LibArchive_VERSION_STRING)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(LibArchive
REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR
VERSION_VAR LibArchive_VERSION
2010-07-29 13:52:59 +00:00
)
unset(LIBARCHIVE_FOUND)
if(LibArchive_FOUND)
set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR})
set(LibArchive_LIBRARIES ${LibArchive_LIBRARY})
2019-12-05 18:44:44 +00:00
if (NOT TARGET LibArchive::LibArchive)
add_library(LibArchive::LibArchive UNKNOWN IMPORTED)
set_target_properties(LibArchive::LibArchive PROPERTIES
IMPORTED_LOCATION "${LibArchive_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LibArchive_INCLUDE_DIR}")
endif ()
2010-07-29 13:52:59 +00:00
endif()