What I remember is that when we started adding 'prevent in-source build'
macros a couple years ago, we had this exact complaint.  The problem is
that the test happens at a particular point in the configuration process
that makes it difficult to clean up after.

I suspect the CMakeCache.txt is written after configuration completed,
even if it completes with an error.  This is as it should be. And there's
no way to have Cmake do something AFTER a fatal error.

The only way (that I know) for this to work is to implement a
PREVENT_IN_SOURCE_BUILD command in Cmake itself; there's no way from a
Cmake Source file to grab control and keep Cmake from writing out the
cache and CMakeFiles directory.


From:  Ben Phillips <[email protected]>
Date:  Wednesday, January 15, 2014 5:08 PM
To:  CMake Users <[email protected]>
Subject:  [CMake] What is the best way to clean up CMakeFiles and
CMakeCache.txt if aborting build completely?


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?


Thank you for your time.

Ben



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the 
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and 
may be legally privileged.  If you are not the intended recipient, you are 
hereby notified that any retention, dissemination, distribution, or copying of 
this communication is strictly prohibited.  Please reply to the sender that you 
have received the message in error, then delete it.  Thank you.
________________________________
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to