[Cmake] out of source builds

Karr, David David.Karr at titan.com
Wed, 7 Jan 2004 14:58:09 -0500


> -----Original Message-----
> From: Doug Henry [mailto:doug_henry at xontech.com]
> Sent: Wednesday, January 07, 2004 10:34 AM
> To: Karr, David
> Cc: cmake list
> Subject: RE: [Cmake] out of source builds
>=20
>=20
> sorry, my wording may have been incorrect.  I am doing an out=20
> of source build.  The in source build works perfectly.

Right, that was my point: the in-source build *will* work
perfectly, because you told CMake to look for gentypes in
the source tree.  When you do an in-source build, CMake
directs all the binaries and other output files, including
gentypes, to be deposited in the source tree (the tree you
call "main"), and so it will find and run this version of=20
gentypes which it just built.

When you do an out-of-source build in "b32", CMake causes=20
the new gentypes to be deposited in the "b32" tree, but since
you explicitly told CMake to look in the "main" tree to
find the version of gentypes to run (because you told it
to look in the directory ${CMAKE_CURRENT_SOURCE_DIR}),=20
it tries to run gentypes from the "main" tree, and does=20
*not* try to run the version of gentypes that you just=20
created in the "b32" tree.

I ran into similar issues when I started doing out-of-source
builds.  When you are doing in-source builds, the "SOURCE"
and "BINARY" directories are the same, so you can get away
with writing MyProject_SOURCE_DIR when you really should have
written MyProject_BINARY_DIR, or CMAKE_CURRENT_SOURCE_DIR
where you should have written CMAKE_CURRENT_BINARY_DIR--two
variables both evaluate to the same path.  But as soon as
you start building out-of-source, any errors you made in
selecting "SOURCE" instead of "BINARY" will cause undesired
results.

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