[CMake] Accessing external files in build tree for testing

Javier de la Dehesa javier.dehesa at clowod.com
Tue Oct 30 14:58:29 EDT 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi everybody,

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.

PS: I have posted this same question in stackoverflow
(http://stackoverflow.com/questions/13121428/accessing-external-files-in-build-tree-for-testing);
then I realized maybe this mail list would be a better resource, but
feel free to post your answer there too so maybe I could give you my vote.

- -- 
Javier de la Dehesa (ClowoD Corporation)
gpg key: 0xDC32927E (@ sks.clowod.com)
gpg fingerprint: 5F60C4AEE81DC6239695FE5D036414D6DC32927E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQkCNVAAoJEANkFNbcMpJ+/nYP/3mcXfNg8eA+tUQmJ8x+rzCe
q7qGPVdlbfA8KhSjTLcV9sQ0W0kKD4tiLEOzAWiTRem2SQg+hJDMSGK3dI6REPIB
o7XNAq66YHPfgKpEHfYYpCz/Qrgbf0vQjPpdWZFv8BaTjWTFKGjMfbQR2t1lZ0Ha
Do0aaF6RKgef+GosL5AbrvduGtuX8NVY1w+29X8hkdImC0O8TcUSn43yjUPT7jIz
Kr7cd1lU2rgwnK1dehG+DviapGMpgfdwm8DWP7vOdvXgWQ3fNflQIBzyUUxTRslb
aqgeLCSgsjw1yELIYDLVoGbMruN8djMpVm4dOpn2BYAMPAgqNLaz8QpSpmrqps2r
G3NzQHMxnWG3MffI3T5/DvfuSPkLL/OSGRNVW5NYBZNayUzgMj2g9DbRUzS1MjvT
XtOBs08J3LVHkpGw8wKLTI9HDi9CXm0g+C9RDw+/JvTrs8WHapwWd8JCMAuzwG4x
7T4xSR959i1JILxNZ4SKXhwHnbcrylHzt3kLB7nqLr+/4V3WbMiiO1okidNW9XRo
bk2/uXAHlOwBcnzmFuIZ7REzZshVcCEluFXANGlTFD7ITtLj4H4PGdtILgSo3PyM
vAE+Zl/P2eUyOXEXsqybcZuPkV9qZwpTBvKzEvz0Xc2YGDMnlyhpqyHWeCIcI+wN
P09roriOmLmorqs9cSU4
=CGH7
-----END PGP SIGNATURE-----


More information about the CMake mailing list