woboq / verdigris

Qt without moc: set of macros to use Qt without needing moc
https://woboq.com/blog/verdigris-qt-without-moc.html
GNU Lesser General Public License v3.0
638 stars 58 forks source link

Add QML_ELEMENT support #99

Open arBmind opened 1 year ago

arBmind commented 1 year ago

After Meeting C++ 2022 I got inspired to start a new experiment to get QML_ELEMENT support for Verdigris. #83

QML_ELEMENT and friends macros were introduced with Qt 5.15 . Why do we need it?

We have two challenges that are solved somewhat with this PR:

  1. Generate a metatypes.json by compiling just C++ code.
    • [x] Generate a string of proper JSON with C++20 code.
    • [x] This string is stored in a special binary section in the object files. (Works with MSVC and GCC/Clang)
  2. Use the build system to call a tool to extract the JSON and use it for qttyperegistrar.
    • [x] Extract the JSON from the object files. (Works for MSVC and GCC on Linux)
    • [x] CMake projects can use an extra object library target as a source for the extractor, and inject into the Qt CMake functions, by providing the right target properties.
    • [x] Qbs projects require a patch to get something similar to object library which is then used as source for the extract tool and generates files tagged similar to those generated by the moc tool.

Extra benefits:

Known Limitations/TODOs:

Side note: This PR merges to the new develop branch. Which is basically what I proposed in #95.