On 03/07/2012 04:10 PM, Michael Jackson wrote:
> In an effort to speed up the build of a project that uses Qt (and moc) I 
> tried an alternate approach with the moc files. Normally I use the basic idea 
> of gathering the headers that need to be "moc'ed" and feed those to moc with 
> this type of CMake Code:
> 
> QT4_WRAP_CPP( FilterWidgets_Generated_MOC_SRCS ${QFilterWidget_HDRS} 
> ${FilterWidget_GEN_HDRS}) 
> 
> The in the Add_Executable(...) call include the 
> ${FilterWidgets_Generated_MOC_SRCS} variable to the list of sources. In my 
> project I have at least 30 auto-generated files which all get moc'ed. That 
> gives me an additional 60 compiled files. So I tried the idea of #include 
> "moc_[some_file.cxx]" in each of the auto-generated .cpp files for each 
> Widget. This would cut the number of files compiled in half. The issue is 
> that since they are being #include'ed in the .cpp files then they do NOT need 
> to be compiled themselves so I took the ${FilterWidgets_Generated_MOC_SRCS} 
> out of the list of sources in the add_executable() call. What happened is 
> that CMake did NOT run moc on those headers because there were now NOT 
> included in the build.
> 
>  So for that version of the cmake code I have something like this:
> 
> QT4_WRAP_CPP( FilterWidgets_Generated_MOC_SRCS ${FilterWidget_GEN_HDRS}) 
> QT4_WRAP_CPP( FilterWidgets_MOC_SRCS ${QFilterWidget_HDRS} )
> 
> Is there a way to forcibly run the moc step even if the resulting source 
> files are NOT directly included in the add_executable? Custom_Command? 
> Add_Depends?

AFAIK, the QT4_WRAP_CPP() macro is essentially a wrapper around ADD_
CUSTOM_COMMAND() which accumulates the latter's OUTPUT files in the
former's first parameter. Thus, you might try

QT4_WRAP_CPP(not2compile ...)
ADD_CUSTOM_TARGET(mocem DEPENDS ${not2compile})
ADD_DEPENDENCIES(... mocem)

but I haven't tested this.

Regards,

Michael
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to