[CMake] opening files relative to cmake build directory

Owen Alanzo Hogarth gurenchan at gmail.com
Sun Jul 12 08:14:27 EDT 2015


I have a little project that's setup like this

project
main.c
build
resources
source
.../module1
.../module2
.../etc

main.c loads dynamic libs from under the source folder.

I am trying to open up a file using c fopen


I create a function to get the base resource path
which returns: /Users/me/projectresources/

I call get resource with test.txt
it'll return a string like this: /Users/me/project/resources/test.txt

but with my fopen command I get null error
Error while opening the file.
: No such file or directory

When I use the c command to find current working directory
it returns:
Current Directory = /Users/me/project/build/

how can I set up cmake to allow me to either use the full file path as in
Users/me/project/resources/[filename]

or a relative filename so that I can open my files?

Best,
Owen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150712/54e6a7d9/attachment.html>


More information about the CMake mailing list