[CMake] Fwd: Re: Re: opening files relative to cmake build directory

Micha Hergarden micha.hergarden at gmail.com
Mon Jul 13 13:02:06 EDT 2015




-------- Forwarded Message --------
Subject: 	Re: Re: [CMake] opening files relative to cmake build directory
Date: 	Mon, 13 Jul 2015 17:00:52 +0000
From: 	Owen Alanzo Hogarth <gurenchan at gmail.com>
To: 	Micha Hergarden <micha.hergarden at gmail.com>



Resources.txt is a test but it's mainly going to be used for assets at
runtime. Maybe in the future I might have other directories but this is
the only one for now.


On Tue, Jul 14, 2015, 00:53 Micha Hergarden <micha.hergarden at gmail.com
<mailto:micha.hergarden at gmail.com>> wrote:

    Sorry,

    I forgot to put you on the reply as well.

    Regards,
    Micha



    -------- Forwarded Message --------
    Subject: 	Re: [CMake] opening files relative to cmake build directory
    Date: 	Mon, 13 Jul 2015 18:46:39 +0200
    From: 	Micha Hergarden <micha.hergarden at gmail.com>
    <mailto:micha.hergarden at gmail.com>
    To: 	cmake at cmake.org <mailto:cmake at cmake.org>



    On 07/12/2015 02:14 PM, Owen Alanzo Hogarth wrote:
>     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
>
>
>
>
    Hello Owen,

    Take a look at: http://www.cmake.org/Wiki/CMake_Useful_Variables

    In your case CMAKE_SOURCE_DIR may do what you want. You can create a
    project configuration file and use #cmakedefine and CONFIGURE_FILE()
    to create defines to use in your source file. That would provide you
    with a fixed location, suitable for the build you are running now.

    What is the purpose of the resources.txt. Is this something you need
    during the creation of your executable? Or do you need it during the
    execution of the program?

    Regards,
    Micha




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150713/0bd934fb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150713/0bd934fb/attachment-0001.sig>


More information about the CMake mailing list