[CMake] What is the best way to clean up CMakeFiles and CMakeCache.txt if aborting build completely?

Nicholas Yue yue.nicholas at gmail.com
Wed Jan 15 18:15:11 EST 2014


On 16/01/14 7:08 AM, Ben Phillips wrote:
> Hello list,
>
> 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:
>
> string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" 
> _is_in_src)
> if(_is_in_src)
> file(REMOVE_RECURSE ${CMAKE_SOURCE_DIR}/CMakeFiles 
> ${CMAKE_SOURCE_DIR}/CMakeCache.txt)
> message(FATAL_ERROR "Aborting...in-source builds are forbidden")
> endif(_is_in_src)
>
> 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).
>
> 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?
Hi Ben,

     I have found that doing an "out-of-source" build makes it much 
easier to do clean up.

     For example :

         $cd /tmp/<some-dev-dir>
         $cmake <cmake-flags-you-want> /home/ben/project/myawesomeproject

     Hope that helps.

Cheers

-- 
Nicholas Yue
Graphics - RenderMan, Visualization, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140116/8e63e37e/attachment.html>


More information about the CMake mailing list