[CMake] QT4 and MOC

Michael Hertling mhertling at online.de
Sat Oct 2 10:21:32 EDT 2010


On 10/02/2010 09:07 AM, Laszlo Papp wrote:
> Hi,
> 
> I wrote a helloworld class, source and header file for instance which
> is basically moc related class with Q_OBJECT macro. I do not know why
> I must use qt4_wrap_cpp(helloworld.h) beside
> qt4_automoc(helloworld.cpp).

There's no need to use both.

> I always thought that qt4_automoc can recognize it. I would like to
> avoid the moc file include at the end of my source line. I would like
> to link that generated moc at linkage time, mostly.

With QT4_AUTOMOC(), you must include the generated moc files in your
sources, but with QT4_WRAP_CPP(), you can do, e.g., the following:

SET(HEADERS helloworld.h)
SET(SOURCES main.cpp helloworld.cpp)
QT4_WRAP_CPP(SOURCES ${HEADERS})
ADD_EXECUTABLE(main ${SOURCES} ${HEADERS})
TARGET_LINK_LIBRARIES(main ${QT_LIBRARIES})

So, the generated moc files are compiled and linked along with the
usual source files, and it's not necessary to include them anywhere.

Regards,

Michael


More information about the CMake mailing list