Generate the gresource xml file based on a list of resources

This inverts the logic from
- having an xml file and extracting dependencies
  from it to
- having a list of dependencies and generating
  an xml file from it

In the original configuration adding or removing a
resource to/from the gresources.xml file would not
be detected by cmake as a change in dependencies.
The user would have to remember to rerun cmake manually.
By explicitly listing the dependencies, cmake will
properly recongifure and regenerate if that list is
updated. The remainder of the dependency configuration
also ensures proper rebuilds of gnucash, libaqbanking
and libofx if any of the resource files change, a new
one is added or an existing one is removed.

For reusability the code to generate the gresource related
files as been extracted into a separate function.
This commit is contained in:
Geert Janssens 2022-12-31 16:31:05 +01:00
parent bdde17115d
commit a543143689
10 changed files with 127 additions and 109 deletions

View File

@ -39,6 +39,7 @@ include (CheckIncludeFiles)
include (GncAddSchemeTargets)
include (GncAddGSchemaTargets)
include (GncAddTest)
include (GncGenerateGResources)
include (MakeDistFiles)
include (GNUInstallDirs)
include (TestBigEndian)

View File

@ -1,9 +1,16 @@
set(cmake_FILES
GncAddGSchemaTargets.cmake GncAddSchemeTargets.cmake
GncAddSwigCommand.cmake GncAddTest.cmake GncFindLibm.cmake
MacroAddSourceFileCompileFlags.cmake MacroAppendForeach.cmake
MakeDist.cmake MakeDistFiles.cmake MakeDistCheck.cmake
)
GncAddGSchemaTargets.cmake
GncAddSchemeTargets.cmake
GncAddSwigCommand.cmake
GncAddTest.cmake
GncFindLibm.cmake
GncGenerateGResources.cmake
MacroAddSourceFileCompileFlags.cmake
MacroAppendForeach.cmake
MakeDist.cmake
MakeDistFiles.cmake
MakeDistCheck.cmake
)
set_dist_list(cmake_modules_DIST CMakeLists.txt COPYING-CMAKE-SCRIPTS.txt ${cmake_FILES})

View File

@ -0,0 +1,62 @@
# gnc_generate_gresources (BASE filename
# RESOURCE_FILES resource1 resource2 ...)
#
# Function to generate two files in CMAKE_CURRENT_BINARY_DIR:
# - a gresource xml file that serves as an input to the glib_resource_compiler
# - a c source file to be compiled and linked with a library or executable
# to include the resources listed in RESOURCE_FILES in that library or
# executable
#
# To link the resources, add
#
# ${CMAKE_CURRENT_BINARY_DIR}/<filename>.c
#
# as additional source to the relevant "add_library" or "add_executable" call.
#
#
# BASE filename
# the base filename without extension for all output files to generate
#
# RESOURCE_FILES
# a list of files that you want compiled into a gresource
#
# The XML file will be generated in the current cmake binary directory
function(gnc_generate_gresources)
set(singleValues BASE)
set(multiValues RESOURCE_FILES)
cmake_parse_arguments(GR "" "${singleValues}" "${multiValues}" ${ARGN})
string(STRIP GR_BASE "${GR_BASE}")
set(XML_FILE "${GR_BASE}.xml")
set(TMP_FILE "${CMAKE_CURRENT_BINARY_DIR}/${XML_FILE}-tmp")
set(XML_PATH "${CMAKE_CURRENT_BINARY_DIR}/${XML_FILE}")
file(WRITE ${TMP_FILE} "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
file(APPEND ${TMP_FILE} "<gresources>\n")
file(APPEND ${TMP_FILE} " <gresource prefix=\"/org/gnucash\">\n")
foreach(res_file ${GR_RESOURCE_FILES})
file(APPEND ${TMP_FILE} " <file>${res_file}</file>\n")
endforeach()
file(APPEND ${TMP_FILE} " </gresource>\n")
file(APPEND ${TMP_FILE} "</gresources>\n")
# Regenerate target file only if something changed
configure_file(${TMP_FILE} ${XML_PATH} COPYONLY)
file(REMOVE ${TMP_FILE})
set(C_FILE "${GR_BASE}.c")
add_custom_command(
OUTPUT ${C_FILE}
COMMAND
"${GLIB_COMPILE_RESOURCES_EXECUTABLE}"
--target=${C_FILE}
--sourcedir=${CMAKE_CURRENT_SOURCE_DIR}
--generate-source
${XML_PATH}
DEPENDS
${XML_PATH} ${GR_RESOURCE_FILES}
)
endfunction()

View File

@ -5,6 +5,18 @@ set(SCHEMADIR_BUILD ${DATADIR_BUILD}/glib-2.0/schemas)
file(MAKE_DIRECTORY ${SCHEMADIR_BUILD})
unset(gschema_depends CACHE)
unset(gschema_preftrans_files CACHE)
# Get glib executable for generating the gresource file
execute_process(
COMMAND
${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_resources
OUTPUT_VARIABLE
GLIB_COMPILE_RESOURCES_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_program(GLIB_COMPILE_RESOURCES_EXECUTABLE ${GLIB_COMPILE_RESOURCES_NAME})
# The subdirectories
add_subdirectory (gnome)
add_subdirectory (gnome-utils)
@ -40,13 +52,44 @@ set(gnucash_noinst_HEADERS
gnucash-locale-platform.h
)
set(gnucash_GRESOURCES
gnucash.css
gnucash-fallback.css
ui/gnc-embedded-register-window.ui
ui/gnc-main-window.ui
ui/gnc-plugin-account-tree.ui
ui/gnc-plugin-basic-commands.ui
ui/gnc-plugin-bi-import.ui
ui/gnc-plugin-budget.ui
ui/gnc-plugin-business.ui
ui/gnc-plugin-csv-export.ui
ui/gnc-plugin-csv-import.ui
ui/gnc-plugin-customer-import.ui
ui/gnc-plugin-file-history.ui
ui/gnc-plugin-log-replay.ui
ui/gnc-plugin-register.ui
ui/gnc-plugin-report-system.ui
ui/gnc-plugin-page-account-tree.ui
ui/gnc-plugin-page-budget.ui
ui/gnc-plugin-page-invoice.ui
ui/gnc-plugin-page-owner-tree.ui
ui/gnc-plugin-page-register.ui
ui/gnc-plugin-page-report.ui
ui/gnc-plugin-page-sx-list.ui
ui/gnc-plugin-qif-import.ui
ui/gnc-reconcile-window.ui
)
# Generate the gresource file
gnc_generate_gresources(BASE gnucash-gresources RESOURCE_FILES ${gnucash_GRESOURCES})
set (gnucash_SOURCES
gnucash.cpp
gnucash-commands.cpp
gnucash-core-app.cpp
gnucash-gresources.c
${CMAKE_CURRENT_BINARY_DIR}/gnucash-gresources.c
${GNUCASH_RESOURCE_FILE}
)
)
if (MINGW)
list(APPEND gnucash_SOURCES "gnucash-locale-windows.c")
@ -109,43 +152,6 @@ if (BUILDING_FROM_VCS)
target_compile_definitions(gnc-gnome-utils PRIVATE -DGNC_VCS=\"git\")
endif()
# Get glib executable for generating the gresource file
execute_process(
COMMAND
${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_resources
OUTPUT_VARIABLE
GLIB_COMPILE_RESOURCES_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_program(GLIB_COMPILE_RESOURCES_EXECUTABLE ${GLIB_COMPILE_RESOURCES_NAME})
# Get the dependencies of the gresource
execute_process(
OUTPUT_VARIABLE
gr_files
COMMAND "${GLIB_COMPILE_RESOURCES_EXECUTABLE}"
--generate-dependencies
${CMAKE_CURRENT_SOURCE_DIR}/gnucash-gresources.xml
)
string (REPLACE "\n" ";" gresource_files ${gr_files})
add_custom_command(
OUTPUT gnucash-gresources.c
COMMAND
"${GLIB_COMPILE_RESOURCES_EXECUTABLE}"
--target=gnucash-gresources.c
--sourcedir=${CMAKE_CURRENT_SOURCE_DIR}
--generate-source
${CMAKE_CURRENT_SOURCE_DIR}/gnucash-gresources.xml
DEPENDS
gnucash-gresources.xml ${gresource_files}
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
if (MAC_INTEGRATION)
target_compile_options(gnucash PRIVATE ${OSX_EXTRA_COMPILE_FLAGS})
target_link_libraries(gnucash ${OSX_EXTRA_LIBRARIES})
@ -261,7 +267,7 @@ install(FILES ${ENVIRONMENT_FILE_DIR}/environment DESTINATION
set_local_dist(gnucash_DIST_local CMakeLists.txt environment.in generate-gnc-script
gnucash.cpp gnucash-commands.cpp gnucash-cli.cpp gnucash-core-app.cpp
gnucash-locale-macos.mm gnucash-locale-windows.c gnucash.rc.in gnucash-valgrind.in
gnucash-gresources.xml ${gresource_files}
${gnucash_GRESOURCES}
${gnucash_noinst_HEADERS} ${gnucash_EXTRA_DIST})
set (gnucash_DIST ${gnucash_DIST_local} ${gnome_DIST} ${gnome_search_DIST} ${gnome_utils_DIST}

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnucash">
<file>gnucash.css</file>
<file>gnucash-fallback.css</file>
<file>ui/gnc-embedded-register-window.ui</file>
<file>ui/gnc-main-window.ui</file>
<file>ui/gnc-plugin-account-tree.ui</file>
<file>ui/gnc-plugin-basic-commands.ui</file>
<file>ui/gnc-plugin-bi-import.ui</file>
<file>ui/gnc-plugin-budget.ui</file>
<file>ui/gnc-plugin-business.ui</file>
<file>ui/gnc-plugin-csv-export.ui</file>
<file>ui/gnc-plugin-csv-import.ui</file>
<file>ui/gnc-plugin-customer-import.ui</file>
<file>ui/gnc-plugin-file-history.ui</file>
<file>ui/gnc-plugin-log-replay.ui</file>
<file>ui/gnc-plugin-register.ui</file>
<file>ui/gnc-plugin-report-system.ui</file>
<file>ui/gnc-plugin-page-account-tree.ui</file>
<file>ui/gnc-plugin-page-budget.ui</file>
<file>ui/gnc-plugin-page-invoice.ui</file>
<file>ui/gnc-plugin-page-owner-tree.ui</file>
<file>ui/gnc-plugin-page-register.ui</file>
<file>ui/gnc-plugin-page-report.ui</file>
<file>ui/gnc-plugin-page-sx-list.ui</file>
<file>ui/gnc-plugin-qif-import.ui</file>
<file>ui/gnc-reconcile-window.ui</file>
</gresource>
</gresources>

View File

@ -41,23 +41,11 @@ set (aqbanking_noinst_HEADERS
set(aqbanking_GLADE assistant-ab-initial.glade dialog-ab.glade dialog-ab-pref.glade)
set(aqbanking_UI gnc-plugin-aqbanking.ui)
set(aqbanking_UI ui/gnc-plugin-aqbanking.ui)
if(WITH_AQBANKING)
add_custom_command(
OUTPUT aqb-gresources.c
COMMAND
"${GLIB_COMPILE_RESOURCES_EXECUTABLE}"
--target=aqb-gresources.c
--sourcedir=${CMAKE_CURRENT_SOURCE_DIR}
--generate-source
${CMAKE_CURRENT_SOURCE_DIR}/aqb-gresources.xml
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/aqb-gresources.xml ${aqbanking_UI}
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
gnc_generate_gresources(BASE aqb-gresources RESOURCE_FILES ${aqbanking_UI})
add_library (gncmod-aqbanking
${aqbanking_SOURCES}

View File

@ -15,23 +15,11 @@ set(ofx_noinst_HEADERS
gnc-plugin-ofx.h
)
set(ofx_UI gnc-plugin-ofx.ui)
set(ofx_UI ui/gnc-plugin-ofx.ui)
if (WITH_OFX)
add_custom_command(
OUTPUT ofx-gresources.c
COMMAND
"${GLIB_COMPILE_RESOURCES_EXECUTABLE}"
--target=ofx-gresources.c
--sourcedir=${CMAKE_CURRENT_SOURCE_DIR}
--generate-source
${CMAKE_CURRENT_SOURCE_DIR}/ofx-gresources.xml
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/ofx-gresources.xml ${ofx_UI}
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
)
gnc_generate_gresources(BASE ofx-gresources RESOURCE_FILES ${ofx_UI})
add_library(gncmod-ofx
${ofx_SOURCES}

View File

@ -315,9 +315,9 @@ gnucash/import-export/aqb/gnc-flicker-gui.c
gnucash/import-export/aqb/gnc-gwen-gui.c
gnucash/import-export/aqb/gncmod-aqbanking.c
gnucash/import-export/aqb/gnc-plugin-aqbanking.c
gnucash/import-export/aqb/gnc-plugin-aqbanking.ui
gnucash/import-export/aqb/gschemas/org.gnucash.GnuCash.dialogs.flicker.gschema.xml.in
gnucash/import-export/aqb/gschemas/org.gnucash.GnuCash.dialogs.import.hbci.gschema.xml.in
gnucash/import-export/aqb/ui/gnc-plugin-aqbanking.ui
gnucash/import-export/bi-import/dialog-bi-import.c
gnucash/import-export/bi-import/dialog-bi-import-gui.c
gnucash/import-export/bi-import/dialog-bi-import-helper.c
@ -362,8 +362,8 @@ gnucash/import-export/log-replay/gnc-plugin-log-replay.c
gnucash/import-export/ofx/gncmod-ofx-import.c
gnucash/import-export/ofx/gnc-ofx-import.c
gnucash/import-export/ofx/gnc-plugin-ofx.c
gnucash/import-export/ofx/gnc-plugin-ofx.ui
gnucash/import-export/ofx/gschemas/org.gnucash.GnuCash.dialogs.import.ofx.gschema.xml.in
gnucash/import-export/ofx/ui/gnc-plugin-ofx.ui
gnucash/import-export/qif-imp/assistant-qif-import.c
gnucash/import-export/qif-imp/dialog-account-picker.c
gnucash/import-export/qif-imp/gnc-plugin-qif-import.c