Use a dynamic relative path to locate resources.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-07-12 10:26:17 +01:00
parent a310d50da4
commit ce0db1f74f
3 changed files with 13 additions and 4 deletions

View file

@ -18,6 +18,7 @@ find_package(Boost REQUIRED
)
target_include_directories(applen PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${NCURSESW_INCLUDE_DIRS}
${LIBEVDEV_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
@ -35,3 +36,5 @@ target_link_libraries(applen PRIVATE
appleii
)
file(RELATIVE_PATH RESOURCE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/resource)
configure_file(config.h.in config.h)

View file

@ -0,0 +1,2 @@
// relative path from executable to resources
#cmakedefine RESOURCE_PATH "@RESOURCE_PATH@"

View file

@ -1,27 +1,31 @@
#include "StdAfx.h"
#include <sstream>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <libgen.h>
#include "Log.h"
#include "config.h"
namespace
{
std::string getResourcePath()
{
std::string resource;
std::ostringstream resource;
char self[1024] = {0};
const int ch = readlink("/proc/self/exe", self, sizeof(self));
if (ch != -1)
{
const char * path = dirname(self);
resource.assign(path);
resource += "/../resource/";
resource << path;
resource << '/';
resource << RESOURCE_PATH;
resource << '/';
}
// else?
return resource;
return resource.str();
}
const std::string resourcePath = getResourcePath();