[CMake] How to forbid in-source build cleanly

Eric Noulard eric.noulard at gmail.com
Sun Mar 4 13:21:26 EST 2007


Hi all,

I want to forbid in-source build with our CMake build system.
Currently I do this like that:

PROJECT(TSP C)

# We do not accept InSource build anymore
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
IF(insource)
  MESSAGE(FATAL_ERROR "InSource Build is forbidden for ${PROJECT_NAME}")
ENDIF(insource)

The trouble is, if someone tries In-Source build with a "cmake ."
then he got the message but trying to do out-source build aftrewards
fails since CMake did create
CMakeCache.txt (and CMakeFiles dir)  in the source tree

You'll have to "manually" remove CMakeCache.txt in order to get it work.
This is annoying non CMakers...

Is there a way to cleanly forbid in-source build?

-- 
Erk


More information about the CMake mailing list