[CMake] How to forbid in-source build cleanly

Alan W. Irwin irwin at beluga.phys.uvic.ca
Sun Mar 4 13:59:50 EST 2007


On 2007-03-04 19:21+0100 Eric Noulard wrote:

> 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?

I don't know, but out of curiosity have you tried FILE(REMOVE ...) to get
rid of CMakeCache.txt to make the above give a cleaner result or does that
not work?

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list