Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/FindLibExiv2.cmake
- This file was added.
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 | # Copyright (c) 2018, Christophe Giboudeaux, <christophe@krop.fr> | ||||
34 | # Copyright (c) 2010, Alexander Neundorf, <neundorf@kde.org> | ||||
35 | # Copyright (c) 2008, Gilles Caulier, <caulier.gilles@gmail.com> | ||||
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 | # 1. Redistributions of source code must retain the copyright | ||||
43 | # notice, this list of conditions and the following disclaimer. | ||||
44 | # 2. Redistributions in binary form must reproduce the copyright | ||||
45 | # notice, this list of conditions and the following disclaimer in the | ||||
46 | # documentation and/or other materials provided with the distribution. | ||||
47 | # 3. The name of the author may not be used to endorse or promote products | ||||
48 | # derived from this software without specific prior written permission. | ||||
49 | # | ||||
50 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||||
51 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||||
52 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
53 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
54 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
55 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
56 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
57 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
58 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
59 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
60 | #============================================================================= | ||||
61 | | ||||
62 | find_package(PkgConfig QUIET) | ||||
63 | pkg_check_modules(PC_EXIV2 QUIET exiv2) | ||||
64 | | ||||
65 | find_path(LibExiv2_INCLUDE_DIRS NAMES exiv2/exif.hpp | ||||
66 | HINTS ${PC_EXIV2_INCLUDEDIR} | ||||
67 | ) | ||||
68 | | ||||
69 | find_library(LibExiv2_LIBRARIES NAMES exiv2 libexiv2 | ||||
70 | HINTS ${PC_EXIV2_LIBRARY_DIRS} | ||||
71 | ) | ||||
72 | | ||||
73 | set(LibExiv2_VERSION ${PC_EXIV2_VERSION}) | ||||
74 | | ||||
75 | if(NOT LibExiv2_VERSION AND DEFINED LibExiv2_INCLUDE_DIRS) | ||||
76 | # With exiv >= 0.27, the version #defines are in exv_conf.h instead of version.hpp | ||||
77 | foreach(_exiv2_version_file "version.hpp" "exv_conf.h") | ||||
78 | if(EXISTS "${LibExiv2_INCLUDE_DIRS}/exiv2/${_exiv2_version_file}") | ||||
79 | file(READ "${LibExiv2_INCLUDE_DIRS}/exiv2/${_exiv2_version_file}" _exiv_version_file_content) | ||||
80 | string(REGEX MATCH "#define EXIV2_MAJOR_VERSION[ ]+\\([0-9]+\\)" EXIV2_MAJOR_VERSION_MATCH ${_exiv_version_file_content}) | ||||
81 | string(REGEX MATCH "#define EXIV2_MINOR_VERSION[ ]+\\([0-9]+\\)" EXIV2_MINOR_VERSION_MATCH ${_exiv_version_file_content}) | ||||
82 | string(REGEX MATCH "#define EXIV2_PATCH_VERSION[ ]+\\([0-9]+\\)" EXIV2_PATCH_VERSION_MATCH ${_exiv_version_file_content}) | ||||
83 | if(EXIV2_MAJOR_VERSION_MATCH) | ||||
84 | string(REGEX REPLACE ".*_MAJOR_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_MAJOR_VERSION ${EXIV2_MAJOR_VERSION_MATCH}) | ||||
85 | string(REGEX REPLACE ".*_MINOR_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_MINOR_VERSION ${EXIV2_MINOR_VERSION_MATCH}) | ||||
86 | string(REGEX REPLACE ".*_PATCH_VERSION[ ]+\\((.*)\\)" "\\1" EXIV2_PATCH_VERSION ${EXIV2_PATCH_VERSION_MATCH}) | ||||
87 | endif() | ||||
88 | endif() | ||||
89 | endforeach() | ||||
90 | | ||||
91 | set(LibExiv2_VERSION "${EXIV2_MAJOR_VERSION}.${EXIV2_MINOR_VERSION}.${EXIV2_PATCH_VERSION}") | ||||
92 | endif() | ||||
93 | | ||||
94 | include(FindPackageHandleStandardArgs) | ||||
95 | find_package_handle_standard_args(LibExiv2 | ||||
96 | FOUND_VAR LibExiv2_FOUND | ||||
97 | REQUIRED_VARS LibExiv2_LIBRARIES LibExiv2_INCLUDE_DIRS | ||||
98 | VERSION_VAR LibExiv2_VERSION | ||||
99 | ) | ||||
100 | | ||||
101 | mark_as_advanced(LibExiv2_INCLUDE_DIRS LibExiv2_LIBRARIES) | ||||
102 | | ||||
103 | if(LibExiv2_FOUND AND NOT TARGET LibExiv2::LibExiv2) | ||||
104 | add_library(LibExiv2::LibExiv2 UNKNOWN IMPORTED) | ||||
105 | set_target_properties(LibExiv2::LibExiv2 PROPERTIES | ||||
106 | IMPORTED_LOCATION "${LibExiv2_LIBRARIES}" | ||||
107 | INTERFACE_INCLUDE_DIRECTORIES "${LibExiv2_INCLUDE_DIRS}" | ||||
108 | ) | ||||
109 | endif() | ||||
110 | | ||||
111 | include(FeatureSummary) | ||||
112 | set_package_properties(LibExiv2 PROPERTIES | ||||
113 | URL "http://www.exiv2.org" | ||||
114 | DESCRIPTION "Image metadata support" | ||||
115 | ) |