File: FindGpgme.cmake

package info (click to toggle)
gpgmepp 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,172 kB
  • sloc: cpp: 12,050; sh: 148; makefile: 5
file content (122 lines) | stat: -rw-r--r-- 4,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright 2025 g10 Code GmbH
# Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# SPDX-License-Identifier: BSD-2-Clause

#[=======================================================================[.rst:
FindGpgme
---------------

Try to find the GpgME library.

This will define the following variables:

``Gpgme_FOUND``
    True if (the requested version of) GpgME was found
``Gpgme_VERSION``
    The version of the GpgME library which was found
``Gpgme_LIBRARIES``
    Libraries you need to link when using GpgME This can be passed to
    target_link_libraries() instead of the ``Gpgme::Gpgme`` target.
``Gpgme_INCLUDE_DIRS``
    Include directories needed to use GpgME This should be passed to
    target_include_directories() if the target is not used for linking.
``Gpgme_DEFINITIONS``
    Compile definitions to use when compiling code that uses GpgME
    This should be passed to target_compile_options() if the target is not
    used for linking.

If ``Gpgme_FOUND`` is TRUE, it will also define the following imported target:

``Gpgme::Gpgme``
    The GpgME library

#]=======================================================================]

find_package(PkgConfig QUIET)
pkg_check_modules(PC_Gpgme QUIET gpgme)

set(Gpgme_VERSION ${PC_Gpgme_VERSION})
set(Gpgme_DEFINITIONS ${PC_Gpgme_CFLAGS_OTHER})

find_path(Gpgme_INCLUDE_DIR
    NAMES
        gpgme.h
    HINTS
        ${PC_Gpgme_INCLUDE_DIRS}
)
find_library(Gpgme_LIBRARY
    NAMES
        gpgme
    HINTS
        ${PC_Gpgme_LIBRARY_DIRS}
)

if(Gpgme_INCLUDE_DIR AND NOT Gpgme_VERSION)
    # The version is given in the format MAJOR.MINOR.PATCH optionally followed
    # by an intermediate "beta" version given as -betaNUM, e.g. "1.24.2-beta7".
    file(STRINGS "${Gpgme_INCLUDE_DIR}/gpgme.h" Gpgme_VERSION_STR
         REGEX "^#[\t ]*define[\t ]+GPGME_VERSION[\t ]+\"([0-9])+\\.([0-9])+\\.([0-9])+(-[a-z0-9]*)?\".*")
    string(REGEX REPLACE "^.*GPGME_VERSION[\t ]+\"([0-9]+\\.[0-9]+\\.[0-9]+(-[a-z0-9]*)?)\".*$"
           "\\1" Gpgme_VERSION_STR "${Gpgme_VERSION_STR}")

    set(Gpgme_VERSION "${Gpgme_VERSION_STR}")

    unset(Gpgme_VERSION_STR)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Gpgme
    REQUIRED_VARS
        Gpgme_LIBRARY
        Gpgme_INCLUDE_DIR
        Gpgme_VERSION
    VERSION_VAR
        Gpgme_VERSION
)

if(Gpgme_FOUND AND NOT TARGET Gpgme::Gpgme)
    add_library(Gpgme::Gpgme UNKNOWN IMPORTED)
    set_target_properties(Gpgme::Gpgme PROPERTIES
        IMPORTED_LOCATION "${Gpgme_LIBRARY}"
        INTERFACE_COMPILE_OPTIONS "${Gpgme_DEFINITIONS}"
        INTERFACE_INCLUDE_DIRECTORIES "${Gpgme_INCLUDE_DIR}"
    )
endif()

mark_as_advanced(
    Gpgme_INCLUDE_DIR
    Gpgme_LIBRARY
)

if(Gpgme_FOUND)
    set(Gpgme_LIBRARIES ${Gpgme_LIBRARY})
    set(Gpgme_INCLUDE_DIRS ${Gpgme_INCLUDE_DIR})
endif()

include(FeatureSummary)
set_package_properties(Gpgme PROPERTIES
    DESCRIPTION "Interface library for GnuPG"
    URL https://www.gnupg.org/software/gpgme/
)