<div class="gmail_quote">On Thu, Oct 7, 2010 at 3:19 AM, Michael Wild <span dir="ltr">&lt;<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</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 6. Oct, 2010, at 20:10 , &lt;<a href="mailto:aaron.meadows@thomsonreuters.com">aaron.meadows@thomsonreuters.com</a>&gt; &lt;<a href="mailto:aaron.meadows@thomsonreuters.com">aaron.meadows@thomsonreuters.com</a>&gt; wrote:<br>

<br>
&gt; Hi all.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Is there a good way to disallow in-source builds?  Ideally, I&#39;d like to<br>
&gt; prevent it before any cruft is written into the source tree.  I<br>
&gt; experimented with writing a function into my CMakelists file and calling<br>
&gt; it.  The function checked if CMAKE_BINARY_DIR was equal to<br>
&gt; CMAKE_SOURCE_DIR and messaged a FATAL_ERROR if that was the case.  This<br>
&gt; works ok, but still generates a CMakeFiles directory and a<br>
&gt; CMakeCache.txt file.<br>
<br>
</div>I don&#39;t think there&#39;s a way to prevent that from happening. The bad thing about this is that if the user doesn&#39;t clean away the in-source CMakeCache.txt file, subsequent out-of-source builds will fail. Perhaps you can do something like this:<br>

<br>
# check for polluted source tree<br>
if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR<br>
    EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)<br>
  message(FATAL_ERROR<br>
    &quot;CMakeCache.txt or CMakeFiles exists in source directory!&quot;)<br>
endif()<br>
# make sure the user doesn&#39;t play dirty with symlinks<br>
get_filename_component(srcdir &quot;${CMAKE_SOURCE_DIR}&quot; REALPATH)<br>
get_filename_component(bindir &quot;${CMAKE_BINARY_DIR}&quot; REALPATH)<br>
# disallow in-source builds<br>
if(${srcdir} STREQUAL ${bindir})<br>
  message(FATAL_ERROR &quot;In-source builds are forbidden!&quot;)<br>
endif()<br>
<div class="im"><br>
&gt;<br>
&gt; The second half of the question is of course, is there an easy way to<br>
&gt; clean out a source tree if an in-source build was accidentally kicked<br>
&gt; off?  (short of dividing the files by their timestamp and removing the<br>
&gt; newer ones, etc..)<br>
<br>
</div>No, simply because CMake cannot. Your build system might have something like the following:<br>
<br>
execute_process(COMMAND echo &quot;BOOM&quot; &gt; ${CMAKE_BINARY_DIR}/boom.txt VERBATIM)<br>
<br>
CMake never knows that the file boom.txt is written, and therefor can&#39;t clean it away. </blockquote><div><br></div><div>I think this is a bit of a red herring.  CMake could be perfectly capable of cleaning up after itself (i.e. its own files).</div>
<div>If the user is doing things like making a bunch of files that CMake isn&#39;t aware of (that aren&#39;t generated), these could be added to ADDITIONAL_MAKE_CLEAN_FILES, or a new property could be added for custom files that are to be deleted on a distclean.</div>
<div><br></div></div>-- <br>Philip Lowman<br>