diff --git a/source/frontends/common2/config.h.in b/source/frontends/common2/config.h.in index d074ea8d..ffe5c851 100644 --- a/source/frontends/common2/config.h.in +++ b/source/frontends/common2/config.h.in @@ -1,3 +1,6 @@ // relative path from executable to resources #cmakedefine ROOT_PATH "@ROOT_PATH@" #cmakedefine SHARE_PATH "@SHARE_PATH@" + +// this one is a bit of a hack, until resources are embedded in the retro core +#cmakedefine CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@" diff --git a/source/frontends/common2/resources.cpp b/source/frontends/common2/resources.cpp index 012d6870..325a26e8 100644 --- a/source/frontends/common2/resources.cpp +++ b/source/frontends/common2/resources.cpp @@ -27,6 +27,8 @@ namespace std::string getResourcePathImpl() { + std::vector paths; + char self[1024] = {0}; const int ch = readlink("/proc/self/exe", self, sizeof(self)); if (ch != -1) @@ -34,21 +36,24 @@ namespace const char * path = dirname(self); // case 1: run from the build folder - const std::string path1 = std::string(path) + '/'+ ROOT_PATH + "/resource/"; - if (dirExists(path1)) - { - return path1; - } - + paths.emplace_back(std::string(path) + '/'+ ROOT_PATH); // case 2: run from the installation folder - const std::string path2 = std::string(path) + '/'+ SHARE_PATH + "/resource/"; - if (dirExists(path2)) + paths.emplace_back(std::string(path) + '/'+ SHARE_PATH); + } + + // case 3: use the source folder + paths.emplace_back(CMAKE_SOURCE_DIR); + + for (const std::string & path : paths) + { + const std::string resourcePath = path + "/resource/"; + if (dirExists(resourcePath)) { - return path2; + return resourcePath; } } - // else? - return "/home/andrea/projects/cvs/A2E/resource/"; + + throw std::runtime_error("Cannot found the resource path"); } }