feat(plugin): support generic addon plugins and build Flatpak by default
The Plugins page replaces the Providers tab and lists every plugin alike: package-manager providers and generic C++ addons, which can be any extension (UI tweak, helper, ...) via IPlugin (onLoad/onUnload/onUiReady) exported with the new FWS_ADDON_PLUGIN macro. Flatpak now ships as a plugin built by default (FWS_BUILD_FLATPAK_PLUGIN=ON), so a plain build is Flatpak-enabled. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
12 files changed
+535
-250
No files matched your search
+78
-37
@@ -72,31 +72,41 @@ add_executable(package-utils-test tests/package-utils.test.cpp)
|
||||
target_include_directories(package-utils-test PRIVATE include)
|
||||
add_test(NAME package-utils-test COMMAND package-utils-test)
|
||||
|
||||
# Plugin manager test: needs Qt (QSettings/QLibrary) and the example plugin
|
||||
# built next to the test binary, so it is only enabled with the plugin option.
|
||||
if(FWS_BUILD_EXAMPLE_PLUGIN)
|
||||
add_executable(plugin-manager-test tests/plugin-manager.test.cpp
|
||||
src/plugin-manager.cpp src/pacman-manager.cpp
|
||||
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||
target_include_directories(plugin-manager-test PRIVATE include plugins/flatpak-provider)
|
||||
target_link_libraries(plugin-manager-test PRIVATE Qt6::Core)
|
||||
add_dependencies(plugin-manager-test example-provider-plugin)
|
||||
add_custom_command(TARGET plugin-manager-test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:example-provider-plugin>
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:flatpak-provider-plugin>
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/)
|
||||
add_test(NAME plugin-manager-test COMMAND plugin-manager-test)
|
||||
endif()
|
||||
# ---- Plugins ----
|
||||
#
|
||||
# Flatpak ships as an external provider plugin (not compiled into the binary):
|
||||
# the produced .so is copied next to the executable and discovered at runtime
|
||||
# by PluginManager, so it can be updated or removed independently of the core
|
||||
# app. It is built by default, so a plain `cmake -B build` yields a
|
||||
# Flatpak-enabled app; disable with -DFWS_BUILD_FLATPAK_PLUGIN=OFF.
|
||||
option(FWS_BUILD_FLATPAK_PLUGIN "Build the Flatpak provider plugin" ON)
|
||||
|
||||
# Optional example external provider plugin. Demonstrates the plugin mechanism:
|
||||
# the produced library is copied next to the executable and discovered at
|
||||
# runtime by PluginManager (see the Providers page).
|
||||
# runtime by PluginManager (see the Plugins page).
|
||||
option(FWS_BUILD_EXAMPLE_PLUGIN "Build the example external provider plugin" OFF)
|
||||
|
||||
# Optional example addon plugin: a non-provider extension (see
|
||||
# plugins/example-addon) proving that plugins can be anything written in C++,
|
||||
# not just package managers. Built next to the executable like any external
|
||||
# plugin.
|
||||
option(FWS_BUILD_EXAMPLE_ADDON "Build the example addon plugin" OFF)
|
||||
|
||||
if(FWS_BUILD_FLATPAK_PLUGIN)
|
||||
add_library(flatpak-provider-plugin MODULE
|
||||
plugins/flatpak-provider/flatpak-provider.cpp
|
||||
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||
target_include_directories(flatpak-provider-plugin PRIVATE include plugins/flatpak-provider)
|
||||
set_target_properties(flatpak-provider-plugin PROPERTIES
|
||||
OUTPUT_NAME "flatpak-provider"
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
add_custom_command(TARGET flatpak-provider-plugin POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:PacManager>/plugins
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:flatpak-provider-plugin>
|
||||
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||
endif()
|
||||
|
||||
if(FWS_BUILD_EXAMPLE_PLUGIN)
|
||||
add_library(example-provider-plugin MODULE plugins/example-provider/example-provider.cpp)
|
||||
target_include_directories(example-provider-plugin PRIVATE include)
|
||||
@@ -110,19 +120,50 @@ if(FWS_BUILD_EXAMPLE_PLUGIN)
|
||||
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||
endif()
|
||||
|
||||
# Flatpak provider plugin. Flatpak ships as an external plugin (not compiled
|
||||
# into the binary): the produced .so is copied next to the executable and
|
||||
# discovered at runtime by PluginManager, so it can be updated or removed
|
||||
# independently of the core app.
|
||||
add_library(flatpak-provider-plugin MODULE
|
||||
plugins/flatpak-provider/flatpak-provider.cpp
|
||||
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||
target_include_directories(flatpak-provider-plugin PRIVATE include plugins/flatpak-provider)
|
||||
set_target_properties(flatpak-provider-plugin PROPERTIES
|
||||
OUTPUT_NAME "flatpak-provider"
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
add_custom_command(TARGET flatpak-provider-plugin POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:PacManager>/plugins
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:flatpak-provider-plugin>
|
||||
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||
if(FWS_BUILD_EXAMPLE_ADDON)
|
||||
add_library(example-addon-plugin MODULE plugins/example-addon/example-addon.cpp)
|
||||
target_include_directories(example-addon-plugin PRIVATE include)
|
||||
# The demo addon attaches Qt widgets, so it links the widget module like
|
||||
# the host application.
|
||||
target_link_libraries(example-addon-plugin PRIVATE Qt6::Widgets)
|
||||
set_target_properties(example-addon-plugin PROPERTIES
|
||||
OUTPUT_NAME "sample-addon"
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
add_custom_command(TARGET example-addon-plugin POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:PacManager>/plugins
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:example-addon-plugin>
|
||||
$<TARGET_FILE_DIR:PacManager>/plugins/)
|
||||
endif()
|
||||
|
||||
# Plugin manager test: needs Qt (QSettings/QLibrary) and the example plugins
|
||||
# built next to the test binary, so it is only enabled with both plugin
|
||||
# options.
|
||||
if(FWS_BUILD_EXAMPLE_PLUGIN AND FWS_BUILD_EXAMPLE_ADDON)
|
||||
add_executable(plugin-manager-test tests/plugin-manager.test.cpp
|
||||
src/plugin-manager.cpp src/pacman-manager.cpp
|
||||
plugins/flatpak-provider/flatpak-manager.cpp)
|
||||
target_include_directories(plugin-manager-test PRIVATE include plugins/flatpak-provider)
|
||||
# Qt6::Widgets is linked so the process can load the example addon, which
|
||||
# itself links the widget module.
|
||||
target_link_libraries(plugin-manager-test PRIVATE Qt6::Core Qt6::Widgets)
|
||||
add_dependencies(plugin-manager-test example-provider-plugin example-addon-plugin)
|
||||
add_custom_command(TARGET plugin-manager-test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:example-provider-plugin>
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:example-addon-plugin>
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/)
|
||||
if(FWS_BUILD_FLATPAK_PLUGIN)
|
||||
target_compile_definitions(plugin-manager-test PRIVATE FWS_FLATPAK_PLUGIN_BUILT)
|
||||
add_dependencies(plugin-manager-test flatpak-provider-plugin)
|
||||
add_custom_command(TARGET plugin-manager-test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE:flatpak-provider-plugin>
|
||||
$<TARGET_FILE_DIR:plugin-manager-test>/plugins/)
|
||||
endif()
|
||||
add_test(NAME plugin-manager-test COMMAND plugin-manager-test)
|
||||
endif()
|
||||
Reference in new issue
Block a user