[CMake] Qt4 moc and uic macros

William A. Hoffman billlist at nycap.rr.com
Thu Jun 8 21:25:07 EDT 2006


At 09:15 PM 6/8/2006, Patrick Noffke wrote:
>> Do you have problems using QT4_WRAP_CPP() ? If so, I'd 
>> suggest to fix them instead of adding yet another moc macro.
>> 
>
>I didn't realize QT4_WRAP_CPP was a moc macro.  It seems to work as well as the macro I gave.  Thanks.
>
>> > 
>> > The QT4_AUTOUIC macro allows you to automatically run uic 
>> on .ui files and
>> > creates a dependency of the ui_xxxx.h by xxxx.cpp (since this is the
>> > file that #include's ui_xxxx.h).  An example usage would be 
>> as follows:
>> 
>> In which way does this differ from the QT4_WRAP_UI() macro 
>> coming with cmake 2.4.2 ? It should do the same. Doesn't it 
>> work for you ?
>> 
>> Do you have problems with the include dirs ?
>> Then try adding CMAKE_CURRENT_SOURCE_DIR and 
>> CMAKE_CURRENT_BINARY_DIR to the include dirs. (you can do 
>> this also using SET(CMAKE_INCLUDE_CURRENT_DIR ON) )
>
>On Windows, it's not generating a rule to generate the ui_xxx.h files, unless I add a dependency to the xxx.cpp file by the ui_xxx.h file.
>
>I started over with the QT4_WRAP_UI macro, and this is what works for me:
>
>MACRO (QT4_WRAP_UI2 outfiles )
>
>    FOREACH (it ${ARGN})
>      GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
>      GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
>      SET(source ${outfile}.cpp)
>      SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
>      ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
>        COMMAND ${QT_UIC_EXECUTABLE}
>        ARGS -o ${outfile} ${infile}
>#        DEPENDS ${infile}
>        MAIN_DEPENDENCY ${infile})
>      SET(${outfiles} ${${outfiles}} ${outfile})
>      ADD_FILE_DEPENDENCIES(${source} ${outfile})
>    ENDFOREACH (it)
>
>ENDMACRO (QT4_WRAP_UI2)
>
>
>The only changes are the SET(source ${outfile}.cpp) and ADD_FILE_DEPENDENCIES(${source} ${outfile}) lines.  (I tried the DEPENDS line, but that didn't work.)  Without the ADD_FILE_DEPENDENCIES line, it doesn't produce the rules  to build the ui_xxx.h files (for VS 2005 Express Edition).  However, not everyone uses the cpp extension, so this solution is not ideal.  If noone has a better suggestion, then I should be able to call QT4_WRAP_UI, then iterate over the outfiles and ADD_FILE_DEPENDENCY for each xxx.cpp file to the corresponding ui_xxx.h file.  That seems messy though.
>
>Any other suggestions?

You have the ui_xxx.h files to the list of sources for the target that they are part
of and it should work. 

-Bill



More information about the CMake mailing list