4

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

3
  • Possible duplicate of SO: Finding current executable's path without /proc/self/exe. I found this (and a lot of other hits) by google "C++ get application path". Commented Nov 6, 2017 at 6: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. Commented Nov 6, 2017 at 7:12
  • Your question is basically the same as 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. Commented Nov 7, 2017 at 19:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.