Skip to content

Fix automoc issues on generated DBus source files

When generating the source files with qt_add_dbus_interfaces(), the respective source file properties are set only in the scope of the "src/dbus" directory, where the macro is called which sets those.

So when using the generated cpp file from the other directories, any properties need to be set explicitly again. By default, SKIP_AUTOMOC is not set, so automoc will be run on those files now in these other directories.

Currently this only results in the waring on the first run in a build dir "No relevant classes found. No output generated." And the generated cpp file will just include the moc files as generated by the qt_add_dbus_interfaces() call in the src/dbus build dir.

Things fail though when cmake is run again on a non-empty build dir, with all the generated files around, including the generated header with the Q_OBJECT macro. Because automoc when run from the other directory on the generated cpp file will now also see the existing generated header relative to it, and adds it to the headers for the magic header automoc. Which then results in the moc-generated code existing 2x, once as included directly from the generated cpp file and once from the automoc header moc files.

Compiling the generated DBus service files into own libraries works around the need to setup properties of the source files once more and trying to match what the generation macros internally do. As well as removes the need for the manual generation dependecy.

No idea what the actual bug is with Qt 6.5 though and how !101 (merged) would have fixed that one exactly? Or did their change just expose the fragile setup with the lost source properties due to the scope? The new cmake code in this patch should be more robust though, and if I understood the intent of QTBUG-103313 correctly, also work with any moc_filename.cpp generated by the macro.

@nicolasfella @vkrause CC teams/frameworks-devs/kf6-workboard#24

Merge request reports