[Cmake] out of source builds

Karr, David David.Karr at titan.com
Wed, 7 Jan 2004 09:07:41 -0500


> I am trying to use the out of source build capability.
> I have a main source tree and then a few others with
> different build options.

By "source tree," do you mean the directory where you=20
keep the actual source?  By definition, if I understand=20
the CMake terminology, there can be only one source tree=20
(so "main" is redundant) unless you are maintaining=20
multiple versions of the source with different lines of=20
code, and an  out-of-source build will not put any=20
binary files in the source tree.

I am guessing that you actually do an in-source build=20
(putting binary files in the same directory tree where=20
the source is) and the you do some out-of-source builds=20
elsewhere.  I have a related issue, I like to do=20
out-of-source builds all the time but must of the=20
developers on my team seem to do in-source builds, so=20
I've taken care to make sure both ways work for the=20
same source and CMake files.

> gentypes is built correctly, but when it tries to
> create the header, it tries running gentypes from
> the main source tree and not from
> the current source folder.  Is this a bug?

> ADD_CUSTOM_COMMAND (
> 	OUTPUT ${CMAKE_HOME_DIRECTORY}/libcommon/include/Types.h
> 	DEPENDS gentypes
> 	COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gentypes
> 	ARGS ${CMAKE_HOME_DIRECTORY}/libcommon/include/Types.h
> ${CMAKE_HOME_DIRECTORY}/data/types.xml
> )

It seems this is doing what it is told to do.
CMAKE_CURRENT_SOURCE_DIR is a directory in your source
tree ... the *source* tree where the original source
files all are, *not* the tree where you perform your
out-of-source build.  This is why I inferred you must be
performing an in-source build before you perform any of
your out-of-source builds, because only the in-source
build would put the binary file "gentypes" in your
source tree; if you hadn't done this, you wouldn't just
get the "wrong" copy of gentypes, you wouldn't find it
at all.

To denote the corresponding directory in your=20
out-of-source build tree, I believe you should write
CMAKE_CURRENT_BINARY_DIR, that is, it's "SOURCE" when it=20
is the unique directory tree where all the source files=20
live, and "BINARY" when it is wherever you are building=20
the binaries.

What interests me is I was just thinking this morning=20
that I might want to add some generated source code to
my current project, and I wonder: shouldn't the generated
code go into the "binary" tree?  I imagine this might
raise some issues about how the workspace or makefile
would find the generated code, since a more "conventional"
(strictly in-source) build procedure would typically end
up with the generated "source" in the same directory as
a bunch of human-written source files.

David