<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"><<a href="mailto:andreas.stahl@tu-dresden.de" target="_blank">andreas.stahl@tu-dresden.de</a>></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>
><br>
> On Thu, Apr 4, 2013 at 6:01 AM, Daniele E. Domenichelli <<a href="mailto:daniele.domenichelli@gmail.com">daniele.domenichelli@gmail.com</a>> wrote:<br>
> One benefit is that it would allow to easily remove all cmake files when<br>
> you wrongly run cmake in the source directory instead of in the build one.<br>
><br>
><br>
> A while ago I found the attached macro online[1]. It stops the build process early on preventing an in source build.<br>
> 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>
><br>
> 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>
><br>
> # Appends the path where you are keeping this Macro<br>
> set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})<br>
><br>
> #Forces out of source builds just in case.<br>
> include(MacroOutOfSourceBuild)<br>
> macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build.")<br>
><br>
> -Brian<br>
><br>
> [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>> <MacroOutOfSourceBuild.cmake>--<br>
<div class="im">><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>Hi all,<br>
<br>
What about just doing a string comparison on the <ProjectName>_SOURCE_DIR and <ProjectName>_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 "Only out-of source builds allowed at the moment.")<br>
endif()<br>
<br>
Or are there some traps I'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>