File: AppStreamHelper.cmake

package info (click to toggle)
calamares 3.3.14-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,448 kB
  • sloc: cpp: 71,554; python: 4,328; xml: 1,379; sh: 866; ansic: 105; makefile: 7
file content (86 lines) | stat: -rw-r--r-- 2,803 bytes parent folder | download | duplicates (3)
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
# === This file is part of Calamares - <https://calamares.io> ===
#
#   SPDX-FileCopyrightText: 2023 Adriaan de Groot <groot@kde.org>
#   SPDX-License-Identifier: BSD-2-Clause
#
###
#
# Finds AppStream-Qt suitable for the Qt version that is in use.
# Creates target calamares::appstreamqt to alias whatever is found.
# Sets AppStreamQt_FOUND appropriately, regardless of the underlying
# variables (e.g. might be AppStreamQt6_FOUND).
#

option(BUILD_APPSTREAM "Support appstream: items in PackageChooser (requires libappstream-qt)" OFF)

if(TARGET calaappstream)
    if(TARGET calamares::appstreamqt)
        message(STATUS "AppStreamQt has already been found")
        set(AppStreamQt_FOUND TRUE)
    else()
        message(STATUS "AppStreamQt has been searched-for and not found")
        set(AppStreamQt_FOUND FALSE)
    endif()
    return()
endif()
if(NOT BUILD_APPSTREAM)
    return()
endif()

### FIND APPSTREAM
#
# First, look for a Qt-versioned variety of the package.
# If that is not found, look for an unversioned one.
set(HAVE_APPSTREAM OFF)
find_package(AppStream${qtname})
# Not everyone renames the variables consistently
if(AppStream${qtname}_FOUND OR AppStreamQt_FOUND)
    set(_appstream_name AppStream${qtname})
    set(HAVE_APPSTREAM ON)
else()
    find_package(AppStreamQt)
    if(AppStreamQt_FOUND)
        set(_appstream_name AppStreamQt)
        # TODO: how to check underlying Qt version?
        set(HAVE_APPSTREAM ON)
    endif()
endif()

if(HAVE_APPSTREAM)
    # Look for the directory name containing the headers
    find_file(_appstream_header NAMES ${_appstream_name}/pool.h AppStreamQt/pool.h)
    if(NOT _appstream_header)
        set(HAVE_APPSTREAM OFF)
    else()
        if(_appstream_header MATCHES /${_appstream_name}/)
            set(_appstream_header_directory ${_appstream_name})
        else()
            set(_appstream_header_directory AppStreamQt)
        endif()
    endif()
else()
    # Placeholder name
    set(_appstream_name AppStreamQt)
endif()

set(_appstream_dependency_type OPTIONAL)
if(BUILD_APPSTREAM)
    set(_appstream_dependency_type REQUIRED)
endif()

set_package_properties(
    ${_appstream_name}
    PROPERTIES
    DESCRIPTION "Support for AppStream (cache) data"
    URL "https://github.com/ximion/appstream"
    PURPOSE "AppStream provides package data"
    TYPE ${_appstream_dependency_type}
)

add_library(calaappstream INTERFACE) # Always, but might not be populated
if(HAVE_APPSTREAM)
    target_compile_definitions(calaappstream INTERFACE HAVE_APPSTREAM_VERSION=${${_appstream_name}_VERSION_MAJOR} HAVE_APPSTREAM_HEADERS=${_appstream_header_directory})
    target_link_libraries(calaappstream INTERFACE ${_appstream_name})
    add_library(calamares::appstreamqt ALIAS calaappstream)
endif()
set(AppStreamQt_FOUND ${HAVE_APPSTREAM})