Triggering rebuild after changing a *.json file

Volker Krause vkrause at
Sun Nov 23 08:58:52 GMT 2014

On Sunday 23 November 2014 04:36:30 Milian Wolff wrote:
> in my quest for better *.json support in KF5 based applications, I noticed
> that we currently do not rebuild properly on changes to the *.desktop or
> *.json files.

indeed, turns out I have the same problem in GammaRay.

> For KDevelop, I'm thus playing around with something like this currently:
> ~~~~~~~~~~~~~~~+
> function(kdevplatform_add_plugin plugin)
>     set(options )
>     set(oneValueArgs JSON)
>     set(multiValueArgs SOURCES)
>     cmake_parse_arguments(KDEV_ADD_PLUGIN "${options}" "${oneValueArgs}"
> "${multiValueArgs}" ${ARGN})
>     string(REGEX REPLACE "\\.cmake$" "" json_out ${KDEV_ADD_PLUGIN_JSON})
>     configure_file(${KDEV_ADD_PLUGIN_JSON}
> ${CMAKE_CURRENT_BINARY_DIR}/${json_out})
>     # ensure we recompile the corresponding object files when the json file
> changes
>     set(dependent_sources )
>     foreach(header ${KDEV_ADD_PLUGIN_SOURCES})
>         file(STRINGS "${header}" match REGEX "K_PLUGIN_FACTORY_WITH_JSON")
>         if(match)
>             list(APPEND dependent_sources "${header}")
>         endif()
>     endforeach()
>     if(NOT dependent_sources)
>         # fallback to all sources - better safe than sorry...
>         set(dependent_sources ${KDEV_ADD_PLUGIN_SOURCES})
>     endif()
>     set_property(SOURCE ${dependent_sources} APPEND PROPERTY OBJECT_DEPENDS
> ${CMAKE_CURRENT_BINARY_DIR}/${json_out})
>     add_library(${plugin} MODULE ${KDEV_ADD_PLUGIN_SOURCES})
> ${CMAKE_CURRENT_BINARY_DIR}/${json_out})
> endfunction()
> ~~~~~~~~~~~~~~~+
> To be used like this:
> kdevplatform_add_plugin(kdevgit JSON kdevgit.json.cmake SOURCES
> ${kdevgit_PART_SRCS})
> This does trigger a rebuild, but the strings are still not updated properly.
> I'm quite confused actually, does anyone know where the code comes from
> that is embedded into the *.o that uses Q_PLUGIN_METADATA? I suspect CMake
> AUTOGEN? But where does that put its generated binary JSON representation?
> How can I make sure that it gets updated properly when the source file
> changes?

moc puts it into the .moc file, so adding a dependency from the .o to the 
.json doesn't help, we'd need that on the .moc file. Indeed ideally something 
that CMake's automoc would add already.

> To reproduce this, you can just change any *.desktop file that is piped
> through desktop_to_json. The change will be picked up by CMake and a
> reconfigure is triggered, which is pretty slow as well. But nothing is
> rebuilt. With the macro above, I trigger the build but still, the *.o file
> that uses K_PLUGIN_FACTORY_WITH_JSON is still containing the "old"
> strings... I'm at loss - can someone help me please?

The following little tool might be useful while debugging this, so you can 
check the embedded JSON data without running the host application:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list