[CMake] Copying data files from source tree to binary tree during
the build
Filipe Sousa
filipe at ipb.pt
Wed Jan 11 05:35:20 EST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Asmodehn Shade wrote:
> Hello everyone,
>
> I have recently come across a little problem using CMake for my own C++
> project.
>
> I have a src tree like :
> SOURCE_DIR/CMakeLists.txt
> SOURCE_DIR/src/ (*.cpp)
> SOURCE_DIR/include/ (*.h)
> SOURCE_DIR/data/ (*.*)
> SOURCE_DIR/test/ (*.cpp)
>
> I want to build it into a binary tree organised in a quite similar way, in
> case of users using the same value for SOURCE_DIR and BINARY_DIR to build.
> But it is hard to keep the binary tree consistent with different compilers.
>
> Anyway with visual studio I end up with smoething like
> BINARY_DIR/<Target>.dir/
> BINARY_DIR/CMakeFile/
> BINARY_DIR/CMakeTmp/
> BINARY_DIR/debug/ (Targets outputs)
>
> Then I want to move the files within /data that are needed to be able to run
> and debug my tests, without actually going nto the install part of my
> project yet.
> Therefore I assume that the right way to do it, would be to add a custom
> command for the build of the needed targets with the corresponding datafile.
> But do I really need to do a
>
> IF(WIN32) xcopy ...
> IF (UNIX) cp ...
> etc. ???
>
> Any idea about how should I do that properly ?
My solution is tho have an option in CMakeLists.txt for development mode
OPTION(DEVELOPMENT_MODE "Development" OFF)
IF(DEVELOPMENT_MODE)
SET(DATA_PATH ${PROJECT_SOURCE_DIR}/data)
CONFIGURE(${PROJECT_SOURCE_DIR}/config.h.in
${PROJECT_BINARY_DIR}/config.h)
ENDIF(DEVELOPMENT_MODE)
config.h.in
#cmakedefine DATA_PATH "${DATA_PATH}"
Now you can use DATA_PATH in you code to locate the data files
- --
Filipe Sousa
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFDxN9obQdNYqwwwCwRAhfaAJ9NY9aE55p/3fPot/xLojahbtBfYACfUppP
BGpfMZQp5ejPCgr4kejlI7s=
=67Fj
-----END PGP SIGNATURE-----
More information about the CMake
mailing list