I am using CMake to compile and test a C++ project. Let's say I have a structure like this:
inc/
..
src/
..
data/
dataFile
File dataFile
is accessed from code, and will be installed under <prefix>/share
or similar. In my code, I do something like:
std::ifstream dataFile(DATAFILE_PATH);
I get that I can configure DATAFILE_PATH
with CMake (with header template, or compiling options, or anything) so I don't have to hardcode the file path in my code directly. Also, I know how to install files to the install tree, and that it is possible to copy files to copy files to build tree, for example for running tests o simply running the executable from build tree.
My question is, how should I configure CMake, or maybe my C++ code, so I can compile my program and run and test it from build tree (accessing a dataFile
copy within build tree) and from install tree (accessing the dataFile
installed copy under <prefix>/share
)? Is there any pattern or technique implemented in CMake that I am missing?
Thanks.