My project folder looks as follows:
foo/ --> Project name
CMakeLists.txt
build/ --> Run cmake.. and make.
src/
app.h
app.cc
main.cc
share/
foo/
config.txt
I want my C++ code to be able to find config.txt
when I do a make build
and also when I do a make install
.
I tried using a relative path to read config.txt
as follows:
const std::string CONFIG_FILE_PATH = "../share/foo/config.txt";
But I realize this runs relative to the folder from where I run the binary, not relative to where the binary is currently located.
What I want is the path to be as follows:
// make build
const std::string CONFIG_FILE_PATH = "/home/myuser/foo/share/foo/config.txt";
// make install
const std::string CONFIG_FILE_PATH = "/usr/share/foo/config.txt";
Is there some sorcery I can do to achieve this? I'm certain this has been done before, but I don't know what to search for.