Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file path resolution to be portable #20

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

wi-re
Copy link
Collaborator

@wi-re wi-re commented Nov 21, 2024

In the previous version of the code resources were loaded from either a hardcoded path (the source directory) or the working directory (if a CMake flag was set). This meant that code compiled with a hardcoded string is not portable to other systems and that the working directory version does not work out of the box for simply launching the executable from its own folder. This PR fixes this.

The fix involves creating a config file that CMake fills with the source and build paths and then adding a path resolver (under src/PathFinder.h) that looks at those two paths, which are not portable, but also looks at the current working directory and the directory where the binary is located, which should cover most cases. The resolve also handles paths in the home directory ('~').

To use the resolver:

#include "PathFinder.h"
//...

std::filesystem::path file = resolveFile("resources/colormaps.txt");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant