<div dir="ltr"><div><div><div><div><div><div><div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">Hello list,<br><br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">I came across this problem when I tried to write a CMakeLists.txt that prevents building in the source tree. So I would try something like this:<br>
<br>string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _is_in_src)<br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">if(_is_in_src)<br>
</span></span></div><div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)"> file(REMOVE_RECURSE $</span></span><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">{CMAKE_SOURCE_DIR}/CMakeFiles </span></span><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)"><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">$</span></span><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">{CMAKE_SOURCE_DIR}/CMakeCache.txt</span></span>)</span></span></div>
<div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)"> message(FATAL_ERROR "Aborting...in-source builds are forbidden")<br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">endif(_is_in_src)<br>
<br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">When running "cmake ." the error is given as expected. However, the source directory is polluted with CMakeFiles and CMakeCache.txt. I expect they can't be removed while the CMakeLists.txt is being interpreted (perhaps they are but are just created before exit again). <br>
<br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">Is there a better way to do this? Perhaps some function/macro that aborts the process abnormally, cleaning up as if nothing ever happened exists?<br>
<br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">Thank you for your time.<br></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">Ben<br>
</span></span><div><div><div><div><div><div><span style="background-color:rgb(255,255,255)"><span style></span></span></div></div></div></div></div></div></div>