CMake documentation is not that bad, do not neglect reading it. You misunderstood the concept of AUTOMOC:
AUTOMOC is a boolean specifying whether CMake will handle the Qt
moc
preprocessor automatically, i.e. without having to use theQT4_WRAP_CPP()
macro. Currently Qt4 is supported. When this property is set toTRUE
, CMake will scan the source files at build time and invokemoc
accordingly. If an#include
statement like#include "moc_foo.cpp"
is found, theQ_OBJECT
class declaration is expected in the header, andmoc
is run on the header file. If an#include
statement like#include "foo.moc"
is found, then aQ_OBJECT
is expected in the current source file andmoc
is run on the file itself. Additionally, all header files are parsed forQ_OBJECT
macros, and if found,moc
is also executed on those files.
So, first of all, you should not add generated moc
files explicitly to sources and push them into executable compilation. In other words, you only push your sources:
SET(SRC
src/main.cpp
src/video_widget_surface.cpp
src/video_widget.cpp
src/video_player.cpp)
and moc
ones are handled automatically by CMake.
Secondly, as stated in the documentation:
If
Q_OBJECT
is in thefoo.h
(i.e.QObject
is declared in the header file), then in the correspondingfoo.cpp
don't forget to add#include "moc_foo.cpp"
, preferably at the end of the file;If
Q_OBJECT
is in thefoo.cpp
(i.e.QObject
is declared in the source file), then, again, in thefoo.cpp
itself don't forget to add#include "foo.moc"
, preferably at the end of the file.