Hi Michael, <br><br>May be you could have a look at [1], [2] and [3]. It basically illustrates how to moc a header a file and include at the end of cpp file.<br><br>Hth<br>Jc<br><br>[1] <a href="https://github.com/commontk/CTK/blob/master/Libs/Testing/CMake/ctkMacroGenerateMocs.cmake">https://github.com/commontk/CTK/blob/master/Libs/Testing/CMake/ctkMacroGenerateMocs.cmake</a><br>

[2] <a href="https://github.com/commontk/CTK/blob/master/Libs/Widgets/Testing/Cpp/CMakeLists.txt#L120">https://github.com/commontk/CTK/blob/master/Libs/Widgets/Testing/Cpp/CMakeLists.txt#L120</a><br>[3] <a href="https://github.com/commontk/CTK/blob/master/Libs/Widgets/Testing/Cpp/ctkMessageBoxDontShowAgainTest.cpp#L530">https://github.com/commontk/CTK/blob/master/Libs/Widgets/Testing/Cpp/ctkMessageBoxDontShowAgainTest.cpp#L530</a><br>

<br><div class="gmail_quote">On Wed, Mar 7, 2012 at 12:13 PM, Michael Jackson <span dir="ltr">&lt;<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im"><br>
On Mar 7, 2012, at 12:05 PM, Michael Wild wrote:<br>
<br>
&gt; On 03/07/2012 04:10 PM, Michael Jackson wrote:<br>
&gt;&gt; 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 &quot;moc&#39;ed&quot; and feed those to moc with this type of CMake Code:<br>


&gt;&gt;<br>
&gt;&gt; QT4_WRAP_CPP( FilterWidgets_Generated_MOC_SRCS ${QFilterWidget_HDRS} ${FilterWidget_GEN_HDRS})<br>
&gt;&gt;<br>
&gt;&gt; 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&#39;ed. That gives me an additional 60 compiled files. So I tried the idea of #include &quot;moc_[some_file.cxx]&quot; 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&#39;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.<br>


&gt;&gt;<br>
&gt;&gt; So for that version of the cmake code I have something like this:<br>
&gt;&gt;<br>
&gt;&gt; QT4_WRAP_CPP( FilterWidgets_Generated_MOC_SRCS ${FilterWidget_GEN_HDRS})<br>
&gt;&gt; QT4_WRAP_CPP( FilterWidgets_MOC_SRCS ${QFilterWidget_HDRS} )<br>
&gt;&gt;<br>
&gt;&gt; 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?<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;<br>
&gt; You could still add them to the add_executable() call, but set their<br>
&gt; HEADER_FILE_ONLY source file property to TRUE to prevent them from being<br>
&gt; compiled. This way they would still show up in the proper place in<br>
&gt; IDE&#39;s, and no need for fiddling around with add_custom_target() and<br>
&gt; add_dependencies(). Of course, you might still want to introduce the<br>
&gt; custom target for convenience so you can trigger moc&#39;ing manually (e.g.<br>
&gt; &quot;make moc&quot;)...<br>
&gt;<br>
&gt; Michael<br>
&gt;<br>
&gt; --<br>
<br>
<br>
</div>Thanks to everyone (Michael and Andreas) for the suggestions. Both suggestions have their pros and cons. I am leaning towards the &quot;Use the new automoc function in CMake 2.8.7&quot; that Andreas suggested. I don&#39;t have to worry about the CMake version since there are only 2 developers. We can upgrade to the latest CMake without a problem.<br>


  Actually NOT having them listed in the IDE is BETTER for me since I tread those files as &quot;black boxes&quot;, ie, I don&#39;t really want to know what is in them. Or at least on a very rare occasion at which point I can just search for the file in the build directory.<br>


<br>
Thanks again Everyone. I&#39;ll post in the next few days what I ended up doing.<br>
--<br>
Mike J.<br>
<div class="HOEnZb"><div class="h5">--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>+1 919 869 8849<br><br>