[packagechooser] Split out helper for AppStreamQt
- add a CMake helper for finding variations of AppStreamQt - adapt packagechooser and packagechooserq - adopt a slightly more modern CMake style here
This commit is contained in:
parent
02aa49d442
commit
8a199aaaf9
74
CMakeModules/AppStreamHelper.cmake
Normal file
74
CMakeModules/AppStreamHelper.cmake
Normal file
@ -0,0 +1,74 @@
|
||||
# === 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)" ON)
|
||||
|
||||
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(NOT _appstream_name)
|
||||
# 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})
|
||||
target_link_libraries(calaappstream INTERFACE ${_appstream_name})
|
||||
add_library(calamares::appstreamqt ALIAS calaappstream)
|
||||
endif()
|
||||
set(AppStreamQt_FOUND ${HAVE_APPSTREAM})
|
@ -23,23 +23,7 @@ endif()
|
||||
### OPTIONAL AppStream support in PackageModel
|
||||
#
|
||||
#
|
||||
option(BUILD_APPSTREAM "Support appstream: items in PackageChooser (requires libappstream-qt)" ON)
|
||||
if(BUILD_APPSTREAM)
|
||||
find_package(AppStreamQt)
|
||||
set_package_properties(
|
||||
AppStreamQt
|
||||
PROPERTIES
|
||||
DESCRIPTION "Support for AppStream (cache) data"
|
||||
URL "https://github.com/ximion/appstream"
|
||||
PURPOSE "AppStream provides package data"
|
||||
TYPE OPTIONAL
|
||||
)
|
||||
if(AppStreamQt_FOUND)
|
||||
add_definitions(-DHAVE_APPSTREAM_VERSION=${AppStreamQt_VERSION_MAJOR})
|
||||
list(APPEND _extra_libraries AppStreamQt)
|
||||
list(APPEND _extra_src ItemAppStream.cpp)
|
||||
endif()
|
||||
endif()
|
||||
include(AppStreamHelper)
|
||||
|
||||
calamares_add_plugin(packagechooser
|
||||
TYPE viewmodule
|
||||
@ -59,6 +43,11 @@ calamares_add_plugin(packagechooser
|
||||
SHARED_LIB
|
||||
)
|
||||
|
||||
if(AppStreamQt_FOUND)
|
||||
target_link_libraries(calamares_viewmodule_packagechooser PRIVATE calamares::appstreamqt)
|
||||
target_sources(calamares_viewmodule_packagechooser PRIVATE ItemAppStream.cpp)
|
||||
endif()
|
||||
|
||||
calamares_add_test(
|
||||
packagechoosertest
|
||||
GUI
|
||||
|
@ -10,9 +10,8 @@ if(NOT WITH_QML)
|
||||
endif()
|
||||
|
||||
find_package(${qtname} ${QT_VERSION} CONFIG REQUIRED Core)
|
||||
|
||||
# Add optional libraries here
|
||||
set(USER_EXTRA_LIB)
|
||||
set(_extra_libraries "")
|
||||
set(_extra_src "")
|
||||
|
||||
# include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../packagechooser )
|
||||
set(_packagechooser ${CMAKE_CURRENT_SOURCE_DIR}/../packagechooser)
|
||||
@ -34,23 +33,7 @@ endif()
|
||||
### OPTIONAL AppStream support in PackageModel
|
||||
#
|
||||
#
|
||||
option(BUILD_APPSTREAM "Support appstream: items in PackageChooser (requires libappstream-qt)" ON)
|
||||
if(BUILD_APPSTREAM)
|
||||
find_package(AppStreamQt)
|
||||
set_package_properties(
|
||||
AppStreamQt
|
||||
PROPERTIES
|
||||
DESCRIPTION "Support for AppStream (cache) data"
|
||||
URL "https://github.com/ximion/appstream"
|
||||
PURPOSE "AppStream provides package data"
|
||||
TYPE OPTIONAL
|
||||
)
|
||||
if(AppStreamQt_FOUND)
|
||||
add_definitions(-DHAVE_APPSTREAM_VERSION=${AppStreamQt_VERSION_MAJOR})
|
||||
list(APPEND _extra_libraries AppStreamQt)
|
||||
list(APPEND _extra_src ${_packagechooser}/ItemAppStream.cpp)
|
||||
endif()
|
||||
endif()
|
||||
include(AppStreamHelper)
|
||||
|
||||
calamares_add_plugin(packagechooserq
|
||||
TYPE viewmodule
|
||||
@ -67,3 +50,8 @@ calamares_add_plugin(packagechooserq
|
||||
${_extra_libraries}
|
||||
SHARED_LIB
|
||||
)
|
||||
|
||||
if(AppStreamQt_FOUND)
|
||||
target_link_libraries(calamares_viewmodule_packagechooserq PRIVATE calamares::appstreamqt)
|
||||
target_sources(calamares_viewmodule_packagechooserq PRIVATE ${_packagechooser}/ItemAppStream.cpp)
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user