diff --git a/SDK/CPP/CMakeLists.txt b/SDK/CPP/CMakeLists.txt index b64eae3d9a119df248378b8b1e41f2b271187ba1..f66f714b8e21081ada820e703d08807b35d1aeb9 100644 --- a/SDK/CPP/CMakeLists.txt +++ b/SDK/CPP/CMakeLists.txt @@ -11,6 +11,24 @@ add_library(voltu SHARED 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 PUBLIC public/include PRIVATE src) diff --git a/SDK/CPP/public/voltu.cpp b/SDK/CPP/public/voltu.cpp index bf63ed6b4c1f145f1a36547030e97c898359f78f..47ddb40071a6bdf3e44bd4be75ac3e90a32aa2de 100644 --- a/SDK/CPP/public/voltu.cpp +++ b/SDK/CPP/public/voltu.cpp @@ -10,10 +10,16 @@ #if defined(WIN32) #include <windows.h> +#pragma comment(lib, "User32.lib") #else #include <dlfcn.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #endif +#include <iostream> + static bool g_init = false; typedef void* Library; @@ -48,13 +54,39 @@ static void unloadLibrary(Library lib) #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() { // TODO: Use full paths and find correct versions #if defined(WIN32) return "voltu.dll"; #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 } @@ -63,6 +95,7 @@ std::shared_ptr<voltu::System> voltu::instance() if (g_init) return nullptr; std::string name = locateLibrary(); + std::cout << "Loading VolTu Runtime: " << name << std::endl; Library handle = loadLibrary(name.c_str()); if (handle)