<div class="gmail_quote">On Wed, Feb 25, 2009 at 8:54 AM, Brad King <span dir="ltr">&lt;<a href="mailto:brad.king@kitware.com">brad.king@kitware.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
What works for me (CMake-CVS, Mac OS X 10.5, Makefile generator) is the following:<br>
- add an empty custom target &quot;untar&quot; with no dependencies to CMakeLists.txt BEFORE any of the add_subdirectory calls<br>
- in the test/CMakeLists.txt add a custom target &quot;untarFoo&quot; which depends on the output of the custom command<br>
- in the test/CMakeLists.txt add a dependency of the top-level &quot;untar&quot; target on the &quot;untarFoo&quot; helper target<br>
</blockquote>
<br></div>
This approach is correct, but could unfortunately create too many extra<br>
targets that the user will see in IDE generators like VS and Xcode.  I<br>
suggest instead doing all the untar rules in a single target defined in<br>
one directory.  One can use the WORKING_DIRECTORY option to make each<br>
rule execute in the proper directory.</blockquote><div><br>This is the approach I&#39;ll probably use for now.  Thanks for the advice.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Meanwhile, there are a few potential problems with the untar-in-source<br>
approach in the first place:<br>
<br>
  1.) The source tree might be read-only.  You can untar into the<br>
      build tree and refer to things there.<br>
<br>
  2.) Your example specifies a directory as the output of the custom<br>
      command.  Since the directory timestamp gets updated by a<br>
      variety of operations, the untar rule may not rerun reliably<br>
      when the tarball changes.  I suggest making the extraction<br>
      rule generate a stamp file with &quot;cmake -E touch ...&quot;.</blockquote><div><br><br>Thanks for pointing out those two problems.  Not too worried about either of them at the moment given what this is intended for.  Another thing did concern me which was the removal of the untar&#39;d directory on a &quot;make clean&quot;.  Is there any easy way to disable this?<br>
<br>The ultimate goal here would be<br>1.) User types &quot;make&quot;<br>1a.) CMake untars several source tarballs each in different directories<br>1b.) CMake patches several source trees in different directories<br>1c.) CMake automatically detects those directories now exist, recurses into them with add_subdirectory() and builds stuff<br>
2.) User types &quot;make clean&quot; and only compiled code gets cleaned, not generated directories.<br><br>I&#39;m pretty sure I can get something working with several independent custom targets and an additional running of cmake at step 1c. at the worst case (i.e. &quot;make untar&quot; &amp;&amp; &quot;make patch&quot; &amp;&amp; &quot;cmake ..&quot; &amp;&amp; &quot;make&quot;).  Not sure I&#39;ll be able to figure out how to chain it all together to be kicked of via just by running &quot;make&quot;.  Still kinda new to add_custom_target/add_custom_command and learning so any advice would be appreciated.<br>
<br></div></div><br>-- <br>Philip Lowman<br>