[CMake] Sharing configuration files?

Hendrik Sattler post at hendrik-sattler.de
Tue Jun 7 04:02:17 EDT 2011


Zitat von Raymond Wan <r.wan at aist.go.jp>:

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

Did you consider alternatives like giving Y a static function that  
returns a new instance of Y? That makes your problem void.
If this is all within a project that is not going to be separated  
later, just put the common configuration into the parent directory of  
both

HS





More information about the CMake mailing list