[Qt-interest] qt4 .moc .cpp

Stephen Bryant steve at bawue.de
Mon Dec 13 08:31:54 CET 2010


Hi,

On 12/12/2010 02:27, sibu xolo wrote:
> I am  learning to  build a Qt4 application using cmake.  I have a machine with 
> qt-4.6.2 and cmake-2.8.0.  The project has these:- fileZ.cpp, fileZ.h
> 
> There is a macro QT4_WRAP_CPP() that runs the MOC and transform fileZ.h into   
> a .cpp source file. However FileZ.cpp  is compiled into a  file with the .moc 
> extension.
> 
> There does not appear to be a ready made macro in cmake for this and I tried 
> using   the add_custom_command() function of cmake like so:- 
> 
> [...]

Your cmake config looked horribly complex!

Try this:

qt4_wrap_cpp(MOC_SOURCES_fileZ PATH/to/fileZ.h)
add_executable(fileZ
               PATH/to/fileZ.cc
               ${MOC_SOURCES_fileZ})


You can list multiple header files in qt4_wrap_cpp() if you need to.
I've assumed you're building an executable called 'fileZ'.  If you're
building a library instead of an executable, use add_library() instead.

You don't need to worry about fileZ2.h, as cmake will figure that
dependency out on its own.

Steve



More information about the Qt-interest-old mailing list