[CMake] Sharing configuration files?

Raymond Wan r.wan at aist.go.jp
Tue Jun 7 03:48:21 EDT 2011


Hi all,

I'm having a problem which I can't quite figure out how to solve.
Basically, I have C++ source code in two directories, each for a
different class.  Let's say:

src/X
src/Y

Each one makes a different class but ultimately X makes use of Y
(i.e., an instance of Y is a variable within X's definition).
Separating them allows me to test Y independently.

So, Y uses CMake to locate the zlib library and whether or not it is
found is passed to Y's source code via a configuration file.  i.e., I
have:

#cmakedefine ZLIB_FOUND 1

in the configuration file which is created like this in CMakeLists.txt:


CONFIGURE_FILE (
  "${PROJECT_SOURCE_DIR}/Config.hpp.in"
  "${PROJECT_BINARY_DIR}/Config.hpp"
  )
INCLUDE_DIRECTORIES ("${PROJECT_BINARY_DIR}")


I think/hope so far things are ok...  I can compile Y and run it with
no problems.  The problem is that X needs access to this generated
configuration file, too.  At the very least, it needs to know the size
of an instance of Y in order to allocate memory for it.  So, some how,
I need to include it in.  If I wanted "Config.hpp.in" (or anything in
its directory) is no problem -- INCLUDE_DIRECTORIES () seems to do the
trick.  But is it possible for me to indicate in X's CMakeLists.txt
where Y's generated configuration file will be?

If my only option is to dump the created configuration files into one
place (i.e., some "global" directory for generated configuration
files), I can accept this.  But even so, I don't know how I can
#include them in...

Does anyone have any ideas?  Thank you!

Ray


More information about the CMake mailing list