<div dir="ltr">Consider looking at the implementation of PreventInSourceBuilds.cmake in ITK<div style>See <a href="https://github.com/Kitware/ITK/blob/master/CMake/PreventInSourceBuilds.cmake">https://github.com/Kitware/ITK/blob/master/CMake/PreventInSourceBuilds.cmake</a></div>

<div style><br></div><div style>May it could be generalized and integrated in CMake itself ?</div><div style><br></div><div style>Jc</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 4, 2013 at 12:49 PM, Andreas Stahl <span dir="ltr">&lt;<a href="mailto:andreas.stahl@tu-dresden.de" target="_blank">andreas.stahl@tu-dresden.de</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Am 04.04.2013 um 17:31 schrieb Brian Milco:<br>
<div><div class="h5"><br>
&gt;<br>
&gt; On Thu, Apr 4, 2013 at 6:01 AM, Daniele E. Domenichelli &lt;<a href="mailto:daniele.domenichelli@gmail.com">daniele.domenichelli@gmail.com</a>&gt; wrote:<br>
&gt; One benefit is that it would allow to easily remove all cmake files when<br>
&gt; you wrongly run cmake in the source directory instead of in the build one.<br>
&gt;<br>
&gt;<br>
&gt; A while ago I found the attached macro online[1]. It stops the build process early on preventing an in source build.<br>
&gt; Since it has to start the process to work you still get a CMakeCache.txt file and CMakeFiles directory but those are easy enough to remove compared to picking through your whole source tree.<br>
&gt;<br>
&gt; To use it place the Macro as close to the top of your master CMakeLists.txt file as you can and call it with something like:<br>
&gt;<br>
&gt; # Appends the path where you are keeping this Macro<br>
&gt; set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})<br>
&gt;<br>
&gt; #Forces out of source builds just in case.<br>
&gt; include(MacroOutOfSourceBuild)<br>
&gt; macro_ensure_out_of_source_build(&quot;${PROJECT_NAME} requires an out of source build.&quot;)<br>
&gt;<br>
&gt; -Brian<br>
&gt;<br>
&gt; [1] <a href="https://github.com/DisCODe/DisCODe/blob/master/cmake/modules/MacroOutOfSourceBuild.cmake" target="_blank">https://github.com/DisCODe/DisCODe/blob/master/cmake/modules/MacroOutOfSourceBuild.cmake</a><br>


</div></div>&gt; &lt;MacroOutOfSourceBuild.cmake&gt;--<br>
<div class="im">&gt;<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div>Hi all,<br>
<br>
What about just doing a string comparison on the &lt;ProjectName&gt;_SOURCE_DIR and  &lt;ProjectName&gt;_BINARY_DIR? No need to include a file for what is effectively three lines:<br>
<br>
if(${MyProj_SOURCE_DIR} STREQUAL ${MyProj_BINARY_DIR})<br>
        message(FATAL_ERROR &quot;Only out-of source builds allowed at the moment.&quot;)<br>
endif()<br>
<br>
Or are there some traps I&#39;m not seeing with this method?<br>
<span class="HOEnZb"><font color="#888888"><br>
Andreas<br>
<br>
<br>
</font></span><br>--<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></blockquote></div><br><br clear="all"><div><br></div>-- <br>+1 919 869 8849<br>
</div>