[Qt-interest] qt4 .moc .cpp

sibu xolo sibxol at btconnect.com
Sun Dec 12 02:27:33 CET 2010


Greetings,

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:- 


configure_file(PATH/to/fileZ.cpp PATH/to/fileZ2.h @COPYONLY)
set(MOC_cmd "/opt/qt4/bin/moc") 
set(PRePRCESSOR_STIRNG "xxxx yyy zzz")

 ADD_CUSTOM_COMMAND(
   OUTPUT -o ${CMAKE_BINARY_DIR}/path/to/fileZ.moc
   COMMAND  ${MOC_cmd} 
-I${QT_INCLUDES}
-I${CMAKE_SOURCE_DIR}/path/to
-E${PRePRCESSOR_STIRNG}
${CMAKE_BINARY_DIR}/path/to/fileZ2.h
   DEPENDS ${CMAKE_SOURCE_DIR}/path/to/fileZ.cpp )

but (apart from the first line)  it did not work.

I know this is a qt list but  many qt-ers are competent with cmake so 
suggestions 
(including if and how cmake handles .moc files etc) would be appreciated.

sincerely
SX



More information about the Qt-interest-old mailing list