[CMake] Developing GResource support in CMake

Damián Nohales damiannohales at gmail.com
Mon Sep 8 13:44:33 EDT 2014


Hello there,

I was trying to develop a CMake module to add GResource (a GLib
component) support for CMake.

For people that doesn't know about GResource, it's a component that
helps to add files bundled to the binary file.

The component provides an utility called "glib-compile-resources" that
generates an .h and .c file with the bundle code, these files are
generated from an XML file that contains the list of files to be
bundled.

This utility also can be used to get the plain list of files that are
going to be bundled, separated by lines.

So, the module needs to works as the following:

 - It has function called gresource_add_file (I'm planning to add
support to add multiple files at once, but for now is fine), this
functions accepts the GResource XML file and returns a variable with
the name of generated .h and .c files to be used to compile an
executable.
 - When the XML file changes or any of the specified files in the XML
file changes, the .h and .c files needs to be regenerated on make.

I attach my current work, it partially works, my problem is that I
generate the files-to-be-bundled list at configure time (the
glib-compile-resources --generate-dependencies call) to get .h and .c
files dependencies, so, for example, let say I do the following:

1) Create my XML with file-a.png and file-b.png specified to be
bundled, add it to my CMakeLists.txt through gresource_add_file
function.
2) If I modify my XML, file-a.png or file-b.png, the GResource .h and
.c are regenerated on make as expected.
3) Let say I want to add file-c.png to my XML, I run make again, the
.h and .c files are regenerated since I modified the XML file.
4) Now I modify only file-c.png, I run make again, but the .h and .c
files are NOT regenerated.

If you see my code, the problem is obvious, as I mentioned, I am
generating the files-to-be-bundled list at configure time... so, when
I add file-c.png, this list is not refreshed since didn't run cmake
again.

Any ideas on how to do it right? It's quite tricky, I can't figure out
the working solution, can I generate dependencies for
add_custom_command dynamically with a shell call that is executed as
is by target buildsystem?

Thanks in advance!
Damián.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GResource.cmake
Type: text/x-cmake
Size: 1911 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140908/37317b49/attachment.bin>


More information about the CMake mailing list