Qt6 has additional moc behavior which AUTOMOC doesn't handle
Hi,
As some might know, Qt6 is intended to be built with CMake. And we use AUTOMOC for all (99%) of the moc processing required when building Qt.
Qt6 has some new changes in moc, where it can produce not only a .cpp file as output, but also a json file. This happens when an additional --json-output argument is passed to moc, which is easily achieved by specifying AUTOMOC_MOC_OPTIONS. These json files have various Qt metatype information.
There is also a necessity to collect all these json files, and perform additional processing on them, in order to create a unified .json file, and then run another tool on that unified .json file, which will produce a .cpp file which ultimately needs to be compiled and linked into the final library.
So schematically looks something like:
qtimer.h -> run_moc via AUTOMOC -> moc_qtimer.cpp + moc_qtimer.json
qthread.h -> run_moc via AUTOMOC -> moc_qthread.cpp + moc_qthread.json
custom_command moc --collect-json=moc_qtimer.json,moc_qthread.json -> moc_core_unified.json
custom_command qt_type_registry_compiler.exe --input=moc_core_unified.json, moc_helper_lib1_dep_unified.json, moc_helper_lib2_dep_unified.json -> moc_core_unified.cpp
add_library(QtCore SOURCES qtimer.cpp qthread.cpp moc_core_unified.cpp)
The unified .json file poses the problem. There doesn't seem to be a public CMake api way to run a custom command that has all the generated .json files as its input, especially considering that the .json files might be or not be generated depending on the contents of the header file on which moc was ran.
It looks like such information maybe could be extracted from the AutogenInfo.json file which is generated by CMake, but that's obviously an implementation detail.
I think there are a couple of options:
-
Don't use AUTOMOC, and manually handle all moc-ing. This is obviously not the best option for us.
-
Add any required support into AUTOMOC itself, whatever that will require.
-
Add some custom hook where a custom executable / script could be ran instead of AUTOMOC, thus delegating the automoc logic to Qt itself, and removing the burden of supporting AUTOMOC in upstream CMake.
-
Possibly some other solution that I currently don't see.
I would appreciate hearing some thoughts from people.
Maybe @brad.king and @sebholt .