Skip to content
Snippets Groups Projects
Commit 552861d3 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Load correct runtime library in linux

parent 711447d7
No related branches found
No related tags found
No related merge requests found
Pipeline #33793 passed
...@@ -11,6 +11,24 @@ add_library(voltu SHARED ...@@ -11,6 +11,24 @@ add_library(voltu SHARED
private/property_impl.cpp private/property_impl.cpp
) )
file(READ "public/include/voltu/voltu.hpp" VOLVER)
string(REGEX MATCH "VOLTU_VERSION_MAJOR ([0-9]*)" _ ${VOLVER})
set(VOLTU_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "VOLTU_VERSION_MINOR ([0-9]*)" _ ${VOLVER})
set(VOLTU_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "VOLTU_VERSION_PATCH ([0-9]*)" _ ${VOLVER})
set(VOLTU_PATCH ${CMAKE_MATCH_1})
message("VolTu SDK version: ${VOLTU_MAJOR}.${VOLTU_MINOR}.${VOLTU_PATCH}")
set_target_properties( voltu PROPERTIES
VERSION "${VOLTU_MAJOR}.${VOLTU_MINOR}"
SOVERSION "${VOLTU_MAJOR}.${VOLTU_MINOR}"
)
target_include_directories(voltu target_include_directories(voltu
PUBLIC public/include PUBLIC public/include
PRIVATE src) PRIVATE src)
......
...@@ -10,10 +10,16 @@ ...@@ -10,10 +10,16 @@
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
#pragma comment(lib, "User32.lib")
#else #else
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif #endif
#include <iostream>
static bool g_init = false; static bool g_init = false;
typedef void* Library; typedef void* Library;
...@@ -48,13 +54,39 @@ static void unloadLibrary(Library lib) ...@@ -48,13 +54,39 @@ static void unloadLibrary(Library lib)
#endif #endif
} }
static bool is_file(const std::string &path) {
#ifdef WIN32
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(path.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) return false;
FindClose(hFind);
return true;
#else
struct stat s;
if (::stat(path.c_str(), &s) == 0) {
return true;
} else {
return false;
}
#endif
}
static std::string locateLibrary() static std::string locateLibrary()
{ {
// TODO: Use full paths and find correct versions // TODO: Use full paths and find correct versions
#if defined(WIN32) #if defined(WIN32)
return "voltu.dll"; return "voltu.dll";
#else #else
return "libvoltu.so"; std::string name = "libvoltu.so";
std::string vname = name + std::string(".") + std::to_string(VOLTU_VERSION_MAJOR) + std::string(".") + std::to_string(VOLTU_VERSION_MINOR);
if (is_file(std::string("./") + vname)) return std::string("./") + vname;
else if (is_file(std::string("./") + name)) return std::string("./") + name;
else if (is_file(std::string("../") + vname)) return std::string("../") + vname;
else if (is_file(std::string("../") + name)) return std::string("../") + name;
else if (is_file(std::string("/usr/local/lib/") + vname)) return std::string("/usr/local/lib/") + vname;
else if (is_file(std::string("/usr/local/lib/") + name)) return std::string("/usr/local/lib/") + name;
return name;
#endif #endif
} }
...@@ -63,6 +95,7 @@ std::shared_ptr<voltu::System> voltu::instance() ...@@ -63,6 +95,7 @@ std::shared_ptr<voltu::System> voltu::instance()
if (g_init) return nullptr; if (g_init) return nullptr;
std::string name = locateLibrary(); std::string name = locateLibrary();
std::cout << "Loading VolTu Runtime: " << name << std::endl;
Library handle = loadLibrary(name.c_str()); Library handle = loadLibrary(name.c_str());
if (handle) if (handle)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment