[CMake] Copying data files from source tree to binary tree during the build

David Cole david.cole at kitware.com
Wed Jan 11 05:27:46 EST 2006


Typing "cmake -E" on the command line yields:

C:\>cmake -E
CMake Error: cmake version 2.2-patch 3
Usage: cmake -E [command] [arguments ...]
Available commands:
  chdir dir cmd [args]... - run command in a given directory
  copy file destination   - copy file to destination (either file or 
directory)
  copy_if_different in-file out-file   - copy file if input has changed
  copy_directory source destination    - copy directory 'source' content 
to directory 'destination'
  echo [string]...        - displays arguments as text
  remove file1 file2 ...  - remove the file(s)
  time command [args] ... - run command and return elapsed time
  write_regv key value    - write registry value
  delete_regv key         - delete registry value
  comspec                 - on windows 9x use this for RunCommand

You can use "cmake -E copy" or "cmake -E copy_directory" to add custom 
commands that copy files at build time. Or you can use CONFIGURE_FILE 
with COPYONLY to copy files at CMake configure time...

Hope this helps,
David


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 ?
>
> Thanks a lot !
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>CMake mailing list
>CMake at cmake.org
>http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list