[CMake] How to specify default build dir in CMakeLists.txt?

Arjen Markus arjen.markus at wldelft.nl
Tue Sep 19 02:45:58 EDT 2006


> 	Hi,
>
> 	The goal is to have an out-of-source build by default.
> The target is a programmer who compiles my package just
> to get the libraries needed for another project. He would
> have one less option to worry about, especially, if
> he wasn't familiar with CMake.

It is not exactly what you are looking for, but if you worry
about builds in the source directory, why not check if the
source directory and the build directory are different.

If they are the same, issue a fatal error - unless the
programmer has explicitly stated he/she wants to do that.

Something like:

IF ( ${CMAKE_SOURCE_DIR} EQUAL ${CMAKE_BINARY_DIR} AND NOT
${ACCEPT_SOURCE_DIR} ) THEN
   MESSAGE( FATAL "Please choose a different directory for building" )
ENDIF( ${CMAKE_SOURCE_DIR} EQUAL ${CMAKE_BINARY_DIR} AND NOT
${ACCEPT_SOURCE_DIR} )

(modulo syntactical and other mistakes, of course)

Regards,

Arjen





More information about the CMake mailing list