diff --git a/kde-modules/KDECMakeSettings.cmake b/kde-modules/KDECMakeSettings.cmake --- a/kde-modules/KDECMakeSettings.cmake +++ b/kde-modules/KDECMakeSettings.cmake @@ -84,6 +84,17 @@ # should be downloaded when building the project. # # Since 5.34.0 +# +# Flatpak builds +# ~~~~~~~~~~~~~~ +# If there is a ``org.kde.app.json`` flatpak recipe in the git repository, an optional +# ``build-flatpak`` target will be added to automate running ``flatpak-builder`` on it. +# +# Don't forget to run ``flatpak update`` after you run the target. +# +# See https://community.kde.org/Guidelines_and_HOWTOs/Flatpak#Compile_your_application +# +# Since 5.38 #============================================================================= # Copyright 2014 Alex Merry @@ -342,3 +353,26 @@ DEPENDS "${CMAKE_BINARY_DIR}/releaseme" ) endif() + +################################################################### +# Build flatpak recipe + +function(_find_json_recipe json_recipe) + execute_process(COMMAND git ls-files *org.kde.*.json + OUTPUT_VARIABLE json + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") + + set(${json_recipe} ${json}) + set(${json_recipe} ${${json_recipe}} PARENT_SCOPE) +endfunction() + +if(NOT TARGET build-flatpak) + set(_json_recipe "") + _find_json_recipe(_json_recipe) + if(_json_recipe) + string(TIMESTAMP _build_date) + add_custom_target(build-flatpak + COMMENT "Building flatpak recipe: ${_json_recipe}..." + COMMAND flatpak-builder --force-clean --ccache --require-changes --repo=repo --subject="Build of ${PROJECT_NAME}, ${_build_date}" app ${CMAKE_SOURCE_DIR}/${_json_recipe}) + endif() +endif()