New porting helper: convert-to-cmake-automoc.pl
Disclaimer
First time I wrote more than a one-liner in Perl, the Swiss Army chainsaw of scripting languages. After quickly skimming the beginner's tutorial, (and no longer just copying Perl one-liners from Stackoverflow and friends), I consider myself ready to write porting helpers for kde-dev-scripts.git! Hey!
If you still don't know those scripts, check them out now. They're tremendously helpful, especially those for porting KDE4-based applications to Qt5/KF5. I wouldn't want to miss them!
Make the most out of CMake's Automoc
Now there's a new porting helper: convert-to-cmake-automoc.pl
, just committed today with https://git.reviewboard.kde.org/r/121991/.
This script tries to remove includes such as #include "<basename>.moc"
from cpp files to make source code suitable for CMake's Automoc feature.
There are some pitfalls, though:
-
In some cases, one still needs to
#include "<basename>.moc"
; for example when the moc-generated code uses classes declared inside the .cpp file (hint:K_PLUGIN_FACTORY
) -- in this case the moc file cannot be compiled in a separate translation unit. -
In some cases, one still needs to
#include "moc_<basename>.cpp"
; for example whenQ_PRIVATE_SLOT
is used in the header file
This script handles these cases.
Example: attica.git
Invoking this script on your source code will fix the annoying "No output generated" warnings from moc:
$ make
...
/home/kfunk/devel/src/kf5/frameworks/attica/tests/projecttest/projecttest.cpp:0: Note: No relevant classes found. No output generated.
...
Now run find -iname "*.cpp" | xargs convert-to-cmake-automoc.pl
and you'll end up with this patch.