[CMake] Out-of-source build and access to data

Benjamin Kurz benjamin.kurz at bioskill.com
Wed Jan 26 09:54:19 EST 2011


Hello everyone,

Currently I'm using cmake for building my c++/Qt project.
The source directory structure looks like this:
Project
|_ src
|_ include
|_ data


Currently I run cmake from the source directory, having an in-source-build.
Now I want to be able to have a complete seperate build folder.
It compiles fine and it runs ok, unless I need access to a file in the
data folder.
Currently I access files like this: filepath = "./data/file1"
But data is of course not available in the build directory.
So I copied the files during the cmake process, which also works fine.

But when I run the program I get an exception because the file is not found.
I tried a lot of possibilities:
filepath = "../data/file1"
filepath = "data/file1"
filepath = "file1"

but nothing seems to work.

The executable is on the top directory in the build directory.
The filepath is defined and used in a class in ./src directory.

I am not sure how to fix this or which path to use?!

Any advice is appreciated.

Thanks

Benjamin


More information about the CMake mailing list