[CMake] Accessing data

Eric Noulard eric.noulard at gmail.com
Mon Mar 11 14:22:30 EDT 2013


2013/3/11 Robert Dailey <rcdailey.lists at gmail.com>:
> I have setup all of my compiled binaries to be placed in
> <build_dir>/output. Certain executables need to access data files
> relative to the executable's current position. When I'm debugging
> through visual studio, it cannot access the data unless I setup a
> post-build event to copy the data to the 'output' directory. I don't
> want to do this, since the data could be very large (gigabytes).
>
> Any suggestion on how to setup CMake scripts to allow targets to
> reference data in a relative way?

Instead of copying you could use
cmake -E create_symlink
but this won't work on Windows.

If your build tree is relative to source tree
then giving your executable the relative path to source tree
should be doable:
file(RELATIVE_PATH RELDIR ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
set(RELFILENAME ${RELDIR}/path/to/data/in/source/tree)

if your build tree is NOT relative to source tree (like on another
disk on Windows)
then I think your are out of luck without copying.

> This is a tough problem to solve
> simply because when the program is installed, the data will actually
> be placed next to the executable in that case so no special logic is
> required to get it to find it.

May be you should make the program look for some "basic search path" anyway?
(like with an environment var)
-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list