[CMake] out of source command line flag
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Mon Sep 7 11:46:12 EDT 2009
On 2009-09-07 08:43-0400 Brad King wrote:
>> I know however that my proposal does not solve the other problem
>> regarding ignoring "<path-to-existing-build>" raised in this thread.
>
> That use case will not be dropped. I think the two-path auto-magic
> command line interpretation approach will work well if implemented
> correctly, and will happily review a patch. However, see my other
> suggestion below.
>
>> In the current one arg cmake invocation we should have a way to
>> detect/avoid an unvoluntary in-source build.
>> Currently we cannot.
>
> This is the key idea. I've thought about possible solutions to this
> in the past but never found time to implement any. My idea is to
> have an optional "InSource.cmake" file written by the project in the
> source tree. If CMake sees an attempt to build in-source, it can
> load this file before touching the source tree at all. The file
> could do one of the following:
>
> 1.) Simply error-out and tell the user to build out-of-source.
> The source tree will remain clean.
> 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.
> 3.) Other ideas?
>
> One gotcha with action #2 is that CMake knows nothing about the
> target platform at the point the file is loaded, so projects
> would be unable to compute a path like "build-x86_64".
Projects can obviously do (1) already by the appropriate IF(CMAKE_BINARY_DIR
STREQUAL "${CMAKE_SOURCE_DIR}") logic. However, I suspect most projects
prefer to give their users the flexibility to choose in-source builds.
Instead of (2) which requires users of a particular project that adopts it
to never have access to in-source builds, 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.
Alan
That would allow users to use
"cmake ."
or to error out when users
are attempting to follow an in-source build with a possible out-of-source
build.
detect the problematic case
(invocation path != build-tree path AND build-tree path == source-tree path)
where an attempt is made to do an in-source build from some other location
using the <path-to-existing-build> interpretation. It's this problematic
case (which can only occur if there is an in-source build followed by an
out-of-source build attempt) that I believe most projects want to avoid
rather than precluding in-source builds altogether as in (1).
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 libLASi project (unifont.org/lasi); 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