| 1 |
# === This file is part of Calamares - <https://calamares.io> === |
| 2 |
# |
| 3 |
# SPDX-FileCopyrightText: 2023 Adriaan de Groot <[email protected]> |
| 4 |
# SPDX-License-Identifier: BSD-2-Clause |
| 5 |
# |
| 6 |
### |
| 7 |
# |
| 8 |
# Finds AppStream-Qt suitable for the Qt version that is in use. |
| 9 |
# Creates target calamares::appstreamqt to alias whatever is found. |
| 10 |
# Sets AppStreamQt_FOUND appropriately, regardless of the underlying |
| 11 |
# variables (e.g. might be AppStreamQt6_FOUND). |
| 12 |
# |
| 13 |
|
| 14 |
option(BUILD_APPSTREAM "Support appstream: items in PackageChooser (requires libappstream-qt)" OFF) |
| 15 |
|
| 16 |
if(TARGET calaappstream) |
| 17 |
if(TARGET calamares::appstreamqt) |
| 18 |
message(STATUS "AppStreamQt has already been found") |
| 19 |
set(AppStreamQt_FOUND TRUE) |
| 20 |
else() |
| 21 |
message(STATUS "AppStreamQt has been searched-for and not found") |
| 22 |
set(AppStreamQt_FOUND FALSE) |
| 23 |
endif() |
| 24 |
return() |
| 25 |
endif() |
| 26 |
if(NOT BUILD_APPSTREAM) |
| 27 |
return() |
| 28 |
endif() |
| 29 |
|
| 30 |
### FIND APPSTREAM |
| 31 |
# |
| 32 |
# First, look for a Qt-versioned variety of the package. |
| 33 |
# If that is not found, look for an unversioned one. |
| 34 |
set(HAVE_APPSTREAM OFF) |
| 35 |
find_package(AppStream${qtname}) |
| 36 |
# Not everyone renames the variables consistently |
| 37 |
if(AppStream${qtname}_FOUND OR AppStreamQt_FOUND) |
| 38 |
set(_appstream_name AppStream${qtname}) |
| 39 |
set(HAVE_APPSTREAM ON) |
| 40 |
else() |
| 41 |
find_package(AppStreamQt) |
| 42 |
if(AppStreamQt_FOUND) |
| 43 |
set(_appstream_name AppStreamQt) |
| 44 |
# TODO: how to check underlying Qt version? |
| 45 |
set(HAVE_APPSTREAM ON) |
| 46 |
endif() |
| 47 |
endif() |
| 48 |
|
| 49 |
if(HAVE_APPSTREAM) |
| 50 |
# Look for the directory name containing the headers |
| 51 |
find_file(_appstream_header NAMES ${_appstream_name}/pool.h AppStreamQt/pool.h) |
| 52 |
if(NOT _appstream_header) |
| 53 |
set(HAVE_APPSTREAM OFF) |
| 54 |
else() |
| 55 |
if(_appstream_header MATCHES /${_appstream_name}/) |
| 56 |
set(_appstream_header_directory ${_appstream_name}) |
| 57 |
else() |
| 58 |
set(_appstream_header_directory AppStreamQt) |
| 59 |
endif() |
| 60 |
endif() |
| 61 |
else() |
| 62 |
# Placeholder name |
| 63 |
set(_appstream_name AppStreamQt) |
| 64 |
endif() |
| 65 |
|
| 66 |
set(_appstream_dependency_type OPTIONAL) |
| 67 |
if(BUILD_APPSTREAM) |
| 68 |
set(_appstream_dependency_type REQUIRED) |
| 69 |
endif() |
| 70 |
|
| 71 |
set_package_properties( |
| 72 |
${_appstream_name} |
| 73 |
PROPERTIES |
| 74 |
DESCRIPTION "Support for AppStream (cache) data" |
| 75 |
URL "https://github.com/ximion/appstream" |
| 76 |
PURPOSE "AppStream provides package data" |
| 77 |
TYPE ${_appstream_dependency_type} |
| 78 |
) |
| 79 |
|
| 80 |
add_library(calaappstream INTERFACE) # Always, but might not be populated |
| 81 |
if(HAVE_APPSTREAM) |
| 82 |
target_compile_definitions(calaappstream INTERFACE HAVE_APPSTREAM_VERSION=${${_appstream_name}_VERSION_MAJOR} HAVE_APPSTREAM_HEADERS=${_appstream_header_directory}) |
| 83 |
target_link_libraries(calaappstream INTERFACE ${_appstream_name}) |
| 84 |
add_library(calamares::appstreamqt ALIAS calaappstream) |
| 85 |
endif() |
| 86 |
set(AppStreamQt_FOUND ${HAVE_APPSTREAM}) |