<div class="gmail_quote">On Fri, Nov 5, 2010 at 5:17 AM, Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de">mhertling@online.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 11/05/2010 05:23 AM, SK wrote:<br>
&gt; On Thu, Nov 4, 2010 at 6:09 PM, Alan W. Irwin &lt;<a href="mailto:irwin@beluga.phys.uvic.ca">irwin@beluga.phys.uvic.ca</a>&gt; wrote:<br>
&gt;&gt; then the custom make command<br>
&gt;&gt; should always be run (since it has no DEPENDS option),<br>
&gt;<br>
&gt; Alan, you are absolutely right!!  I missed this since the external<br>
&gt; makefile I need actually does have a dependency to create the makefile<br>
&gt; itself.  So, the custom command only ran when the single explicit<br>
&gt; dependency was out of date.  I can solve that some other way and I<br>
&gt; appreciate all your effort to straighten this out.  I wish the<br>
&gt; document would have explicitly stated that the command always runs<br>
&gt; without a dependency, though that is the intuitive course of action.<br>
<br>
</div>AFAIK, a custom command without dependencies doesn&#39;t run if its OUTPUT<br>
exists; see the following CMakeLists.txt and the generated Makefiles:<br>
<br>
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)<br>
PROJECT(INDEPENDCUSTOMCOMMAND C)<br>
ADD_CUSTOM_COMMAND(<br>
    OUTPUT ${CMAKE_BINARY_DIR}/main.h<br>
    COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/main.h)<br>
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c &quot;<br>
#include \&quot;main.h\&quot;<br>
int main(void){return 0;}<br>
&quot;)<br>
ADD_EXECUTABLE(main main.c main.h)<br>
<br>
The sole possibility to (re)run the custom command is to delete main.h;<br>
if main.h exists the command never runs. You might even have a foreign<br>
main.h: Try &quot;cmake &lt;path/to/source&gt;&quot; followed by &quot;touch main.h&quot; from<br>
within an empty build directory, and you won&#39;t see the custom command<br>
run. In ${CMAKE_BINARY_DIR}/CMakeFiles/main.dir/build.make, the related<br>
lines are:<br>
<br>
main.h:<br>
        ...<br>
        .../cmake -E touch .../main.h<br>
<br>
So, the commands associated with make&#39;s &quot;main.h&quot; target aren&#39;t executed<br>
if make detects that main.h is already present. Thus, a dependency-less<br>
custom command doesn&#39;t run each time; rather, it runs only if its output<br>
doesn&#39;t exist.<br>
<br>
Regards,<br>
<font color="#888888"><br>
Michael<br>
</font><div><div></div><div class="h5">_______________________________________________<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>In addition to all that has been discussed in this thread already, consider using CMake&#39;s ExternalProject module to drive the external make.<br><br>It should be as simple as something like (or at least very similar to):<br>
include(ExternalProject)<br>ExternalProject_Add(extern_lib<br>  SOURCE_DIR &quot;${dir_of_Makefile}&quot;<br>  BUILD_IN_SOURCE 1<br>
   BUILD_COMMAND $(MAKE)<br>)<br><br>You may also need:<br>  DOWNLOAD_COMMAND &quot;&quot;<br>  UPDATE_COMMAND &quot;&quot;<br>  CONFIGURE_COMMAND &quot;&quot;<br>  INSTALL_COMMAND &quot;&quot;<br>(to avoid built-in defaults for those build steps...)<br>
<br>In the ExternalProject module, we use a technique to run a custom command always:<br>- Name an output for the custom command that never exists on disk, mark that source file with the &quot;SYMBOLIC&quot; property, and then make sure that the custom command never actually produces the named output file...<br>
<br>It&#39;s documented like this in the add_custom_command docs:<br>&quot;If the output of the custom command is not actually created as a file on
 disk it should be marked as SYMBOLIC with SET_SOURCE_FILES_PROPERTIES.&quot;<br><br>See also:<br><a href="http://cmake.org/cmake/help/cmake-2-8-docs.html#command:add_custom_command">http://cmake.org/cmake/help/cmake-2-8-docs.html#command:add_custom_command</a><br>
<a href="http://cmake.org/cmake/help/cmake-2-8-docs.html#prop_sf:SYMBOLIC">http://cmake.org/cmake/help/cmake-2-8-docs.html#prop_sf:SYMBOLIC</a><br><br><br>HTH,<br>David<br><br>