| 1 |
#.rst: |
| 2 |
# FindLibExiv2 |
| 3 |
# ------------ |
| 4 |
# |
| 5 |
# Try to find the Exiv2 library. |
| 6 |
# |
| 7 |
# This will define the following variables: |
| 8 |
# |
| 9 |
# ``LibExiv2_FOUND`` |
| 10 |
# System has LibExiv2. |
| 11 |
# |
| 12 |
# ``LibExiv2_VERSION`` |
| 13 |
# The version of LibExiv2. |
| 14 |
# |
| 15 |
# ``LibExiv2_INCLUDE_DIRS`` |
| 16 |
# This should be passed to target_include_directories() if |
| 17 |
# the target is not used for linking. |
| 18 |
# |
| 19 |
# ``LibExiv2_LIBRARIES`` |
| 20 |
# The LibExiv2 library. |
| 21 |
# This can be passed to target_link_libraries() instead of |
| 22 |
# the ``LibExiv2::LibExiv2`` target |
| 23 |
# |
| 24 |
# If ``LibExiv2_FOUND`` is TRUE, the following imported target |
| 25 |
# will be available: |
| 26 |
# |
| 27 |
# ``LibExiv2::LibExiv2`` |
| 28 |
# The Exiv2 library |
| 29 |
# |
| 30 |
# Since 5.53.0. |
| 31 |
# |
| 32 |
#============================================================================= |
| 33 |
# SPDX-FileCopyrightText: 2018 Christophe Giboudeaux <[email protected]> |
| 34 |
# SPDX-FileCopyrightText: 2010 Alexander Neundorf <[email protected]> |
| 35 |
# SPDX-FileCopyrightText: 2008 Gilles Caulier <[email protected]> |
| 36 |
# |
| 37 |
# |
| 38 |
# Redistribution and use in source and binary forms, with or without |
| 39 |
# modification, are permitted provided that the following conditions |
| 40 |
# are met: |
| 41 |
# |
| 42 |
# SPDX-License-Identifier: BSD-3-Clause |
| 43 |
#============================================================================= |
| 44 |
|
| 45 |
find_package(PkgConfig QUIET) |
| 46 |
pkg_check_modules(PC_EXIV2 QUIET exiv2) |
| 47 |
|
| 48 |
find_path(LibExiv2_INCLUDE_DIRS NAMES exiv2/exif.hpp |
| 49 |
HINTS ${PC_EXIV2_INCLUDEDIR} |
| 50 |
) |
| 51 |
|
| 52 |
find_library(LibExiv2_LIBRARIES NAMES exiv2 libexiv2 |
| 53 |
HINTS ${PC_EXIV2_LIBRARY_DIRS} |
| 54 |
) |
| 55 |
|
| 56 |
set(LibExiv2_VERSION ${PC_EXIV2_VERSION}) |
| 57 |
|
| 58 |
if(NOT LibExiv2_VERSION AND DEFINED LibExiv2_INCLUDE_DIRS) |
| 59 |
# With exiv >= 0.27, the version #defines are in exv_conf.h instead of version.hpp |
| 60 |
foreach(_exiv2_version_file "version.hpp" "exv_conf.h") |
| 61 |
if(EXISTS "${LibExiv2_INCLUDE_DIRS}/exiv2/${_exiv2_version_file}") |
| 62 |
file(READ "${LibExiv2_INCLUDE_DIRS}/exiv2/${_exiv2_version_file}" _exiv_version_file_content) |
| 63 |
string(REGEX MATCH "#define EXIV2_MAJOR_VERSION[ ]+\\([0-9]+\\)" EXIV2_MAJOR_VERSION_MATCH ${_exiv_version_file_content}) |
| 64 |
string(REGEX MATCH "#define EXIV2_MINOR_VERSION[ ]+\\([0-9]+\\)" EXIV2_MINOR_VERSION_MATCH ${_exiv_version_file_content}) |
| 65 |
string(REGEX MATCH "#define EXIV2_PATCH_VERSION[ ]+\\([0-9]+\\)" EXIV2_PATCH_VERSION_MATCH ${_exiv_version_file_content}) |
| 66 |
if(EXIV2_MAJOR_VERSION_MATCH) |
| 67 |
string(REGEX REPLACE ".*_MAJOR_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_MAJOR_VERSION ${EXIV2_MAJOR_VERSION_MATCH}) |
| 68 |
string(REGEX REPLACE ".*_MINOR_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_MINOR_VERSION ${EXIV2_MINOR_VERSION_MATCH}) |
| 69 |
string(REGEX REPLACE ".*_PATCH_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_PATCH_VERSION ${EXIV2_PATCH_VERSION_MATCH}) |
| 70 |
endif() |
| 71 |
endif() |
| 72 |
endforeach() |
| 73 |
|
| 74 |
set(LibExiv2_VERSION "${EXIV2_MAJOR_VERSION}.${EXIV2_MINOR_VERSION}.${EXIV2_PATCH_VERSION}") |
| 75 |
endif() |
| 76 |
|
| 77 |
include(FindPackageHandleStandardArgs) |
| 78 |
find_package_handle_standard_args(LibExiv2 |
| 79 |
FOUND_VAR LibExiv2_FOUND |
| 80 |
REQUIRED_VARS LibExiv2_LIBRARIES LibExiv2_INCLUDE_DIRS |
| 81 |
VERSION_VAR LibExiv2_VERSION |
| 82 |
) |
| 83 |
|
| 84 |
mark_as_advanced(LibExiv2_INCLUDE_DIRS LibExiv2_LIBRARIES) |
| 85 |
|
| 86 |
if(LibExiv2_FOUND AND NOT TARGET LibExiv2::LibExiv2) |
| 87 |
add_library(LibExiv2::LibExiv2 UNKNOWN IMPORTED) |
| 88 |
set_target_properties(LibExiv2::LibExiv2 PROPERTIES |
| 89 |
IMPORTED_LOCATION "${LibExiv2_LIBRARIES}" |
| 90 |
INTERFACE_INCLUDE_DIRECTORIES "${LibExiv2_INCLUDE_DIRS}" |
| 91 |
) |
| 92 |
# Workaround for using exiv2 with -std=c++!7 |
| 93 |
# FIXME: Remove this when exiv2 has been updated to remove usage of |
| 94 |
# `auto_ptr`. |
| 95 |
if(MSVC) |
| 96 |
target_compile_definitions(LibExiv2::LibExiv2 |
| 97 |
INTERFACE _HAS_AUTO_PTR_ETC=1 |
| 98 |
) |
| 99 |
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR |
| 100 |
CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") # libc++ |
| 101 |
target_compile_definitions(LibExiv2::LibExiv2 |
| 102 |
INTERFACE _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR |
| 103 |
) |
| 104 |
endif() |
| 105 |
endif() |
| 106 |
|
| 107 |
include(FeatureSummary) |
| 108 |
set_package_properties(LibExiv2 PROPERTIES |
| 109 |
URL "http://www.exiv2.org" |
| 110 |
DESCRIPTION "Image metadata support" |
| 111 |
) |