NOV
1
2011
|
Cool new stuff in CMake 2.8.6: automocStarting with version 2.8.6 CMake supports what is known as automoc, i.e. automatic handling of moc when using Qt4. As you know, when adding signals and slots to a class using Qt, this source code (typically the header) has to be processed by the moc preprocessor. This invocation of moc during the build is what we are talking about. When using plain CMake, you had to use the macro qt4_wrapp_cpp(srcsVar ${filesToBeMocced}).
Several years ago, actually I can't remember when it was, I guess it must have been at KDE 2.x times, we wanted to make life easier for our KDE developers and added automoc to our (back then) autotools-based KDE buildsystem. This behaviour was later on adopted by qmake, so you didn't have to care anymore about running moc when using qmake. When we switched for KDE4 to CMake, this functionality was kept, but it had to be done in a different way. For CMake we, well Matthias Kretz mainly, created a tool called automoc4, which lived in kdesupport (and internally used QtCore). Although automoc4 is completely independent from KDE, many developers told me that they would really like to have automoc-functionality directly in CMake, because automoc4 still is an additional dependency for a Qt-only program. So, now with CMake 2.8.6, automoc is supported directly by CMake. So, how do you use it ? Simple way: set(CMAKE_AUTOMOC TRUE) and then CMake will automoc all targets. If you don't want to have automoc for all targets (while the scanning is fast, it still takes some time), you can also enable it just for some targets by setting the AUTOMOC target property to TRUE for these targets: set_target_properties(Foo PROPERTIES AUTOMOC TRUE) What exactly does it do:
So, this way you don't have to care abotu moc anymore. The only time when you actually have to do something is, as noted above, if the Q_OBJECT is in the cpp-file, then add #include "thisfile.moc" to that file, somewhere after the class declaration. Alex |
![]() |
Comments
#include
> So, this way you don't have to care abotu moc anymore.
It is good that no moc generated files has to be included in the source, developers should not have to take care of qt's internal signal/slot implementation.
Awesome, awesome, awesome!
This is SO nice! I was able to simply CMakeLists.txt files in my huge projects that use Qt considerably!
Well done!