3

Here is my folder structure:

├── bin                                                                                                                                                                                                                                       
├── build                                                                                                                                                                                                                                     
├── CMakeLists.txt                                                                                                                                                                                                                            
├── include                                                                                                                                                                                                                                   
│   └── project                                                                                                                                                                                                                               
│        ├── base_socket.h                                                                                                                                                                                                                                                                                                                                                                                                                                          
├── LICENSE.txt                                                                                                                                                                                                                               
├── README.md                                                                                                                                                                                                                                 
└── src                                                                                                                                                                                                                                       
    └── project                                                                                                                                                                                                                               
        ├── base_socket.cpp                                                                                                                                                                                                                   
        ├── CMakeLists.txt                                                                                                                                                                                                                    
        ├── main.cpp  
        |── assets
            ├── imageone.jpg

This is for an OpenGL project where there are several shader (text) files and images.

I have problems because I use relative paths in my .cpp files (for instance, roughly, `./assets/imageone.jpg

The issue is that I want to (and CMake does) have the built binaries go into the top level /bin directory. When I do that, and run the debug and release executable, the binary paths are obviously broken.

One solution to this would be to try to embed all of the resourced "in the executable" but I do not like this approach with large, binary files.

Is there some possible way to store "Assets", and reference them with local paths, and have these local paths work across platforms?

For instance, Visual Studio puts binaries in /bin/Release g++ does not, so I can't even have a parent level "Assets" folder that always works with relative paths.

In short I am guessing how to make a cross platform asset referencing method for a C++ program.

How do the pros do it?

Is this something CMAKE can help with?

Thanks

Startec
  • 12,496
  • 23
  • 93
  • 160
  • Possible duplicate of [SO: Finding current executable's path without /proc/self/exe](https://stackoverflow.com/q/1023306/7478597). I found this (and a lot of other hits) by google "C++ get application path". – Scheff's Cat Nov 06 '17 at 06:58
  • 1
    May be, your question is more specific to CMake: We let the CMake store "assets" in the binary output path (or sub-folders resp.) Hence, the application can always use it's own binary path as base directory. The copying in CMake is done in (our) scripts using the built-in CMake variables and commands. – Scheff's Cat Nov 06 '17 at 07:12
  • Your question is basically the same as [How to copy DLL files into the same folder as the executable using CMake?](https://stackoverflow.com/questions/10671916/how-to-copy-dll-files-into-the-same-folder-as-the-executable-using-cmake), only your dependencies are not DLLs but assets. You can use the same solution. – legalize Nov 07 '17 at 19:09

0 Answers0