[CMake] out of source command line flag

Eric Noulard eric.noulard at gmail.com
Mon Sep 7 13:37:31 EDT 2009


2009/9/7 Alan W. Irwin <irwin at beluga.phys.uvic.ca>:
> On 2009-09-07 08:43-0400 Brad King wrote:
>>
>> 1.) Simply error-out and tell the user to build out-of-source.
>>   The source tree will remain clean.
>>
>
> Projects can obviously do (1) already by the appropriate IF(CMAKE_BINARY_DIR
> STREQUAL "${CMAKE_SOURCE_DIR}") logic.

Yes you can do that but when you reach that point in your CMakeLists.txt
the source tree is **ALREADY** cluttered with unwanted files including
a CMakeCache.txt.

This is precisely the point of bug:
http://public.kitware.com/Bug/view.php?id=6672

> However, I suspect most projects prefer to give their users the
> flexibility to choose in-source builds.

Yes you are right I do support in-source for my CMake-powered project
but I'd rather be able to warn my user about
the evilness of in-source build when they can simply avoid it :-)
I may require  -DFORCE_IN_SOURCE in order to make the
user fully aware of what he is doing.
That way I may be able to avoid the explanation for cleaning
a "use as build tree source tree".

>> 2.) Compute the path to a build tree for CMake to auto-magically
>>  substitute for an in-source build.  Likely it would be just
>>  "<source-tree>/build" or some convention the project prefers.

> Instead of (2) which requires users of a particular project that adopts it
> to never have access to in-source builds,

Agreed,
there should a way for the user to **explicitely** tells that he wants
an in-source
build and authorize it with some -DFORCE_IN_SOURCE.

I just dislike the default behavior which makes me unable to
warn about in-source build efficiently.

> I far prefer the idea of giving
> build systems access to the path where cmake was invoked as a CMake variable
> (say CMAKE_INVOCATION_DIR). That allows projects to demand (if they like) to
> error out IF(NOT CMAKE_BINARY_DIR STREQUAL "${CMAKE_INVOCATION_DIR}" AND
> CMAKE_BINARY_DIR STREQUAL "${CMAKE_SOURCE_DIR}") which would disallow _just_
> the problematic case where users try an in-source build, then attempt to
> invoke cmake from a different location other than the top of the existing
> build == source tree.

Yes that's a good point,
but at that point your user discovers that he has already done an
in-source build
(may be because he overlooked the written build procedure) and ends up asking
on his favorite mailing list how he can clean his source tree.

If he has previously **explicitely** required in-source build he won't
be puzzled
by the latest message. If he has done the first in-source config. by mistake
he will be puzzled by the error message.
However your idea is good I can error out a big explanation
on the in-source vs out-of-source think using your test:
IF(NOT CMAKE_BINARY_DIR STREQUAL "${CMAKE_INVOCATION_DIR}" AND
CMAKE_BINARY_DIR STREQUAL "${CMAKE_SOURCE_DIR}")


-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list