Skip to content

Commit

Permalink
[win32] Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed May 15, 2024
1 parent 8c04bfa commit 7bef967
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ossia-max/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ use_gold(${PROJECT_NAME})
add_linker_warnings_external(${PROJECT_NAME})

target_link_libraries(${PROJECT_NAME} PRIVATE ossia
# ${MAXSDK_API_LIBRARY}
$<LINK_ONLY:$<$<BOOL:${WIN32}>:${MAXSDK_API_LIBRARY}>>
$<LINK_ONLY:re2::re2>
$<LINK_ONLY:websocketpp::websocketpp>
)
Expand Down
2 changes: 1 addition & 1 deletion src/ossia-max/src/ossia-max.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "assert.hpp"
#include "attribute.hpp"
#include "client.hpp"
// #include "ocue.hpp"
#include "ocue.hpp"
#include "device.hpp"
#include "explorer.hpp"
#include "fuzzysearch.hpp"
Expand Down
25 changes: 21 additions & 4 deletions src/ossia/detail/dylib_loader.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#if __has_include(<dlfcn.h>)
#include <ossia/detail/config.hpp>
#include <ossia/detail/fmt.hpp>

#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>

#endif
#include <stdexcept>

namespace ossia
Expand All @@ -14,7 +16,11 @@ class dylib_loader
public:
explicit dylib_loader(const char* const so)
{
#ifdef _WIN32
impl = (void*)LoadLibraryA(so);
#else
impl = dlopen(so, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
#endif
if(!impl)
{
throw std::runtime_error(fmt::format("{}: not found. ", so));
Expand All @@ -28,7 +34,11 @@ class dylib_loader

for(const auto so : sos)
{
#ifdef _WIN32
impl = (void*)LoadLibraryA(so.data());
#else
impl = dlopen(so.data(), RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
#endif
if(impl)
return;
}
Expand All @@ -55,14 +65,22 @@ class dylib_loader
{
if(impl)
{
#ifdef _WIN32
FreeLibrary((HMODULE)impl);
#else
dlclose(impl);
#endif
}
}

template <typename T>
T symbol(const char* const sym) const noexcept
{
#ifdef _WIN32
return (T)GetProcAddress((HMODULE)impl, sym);
#else
return (T)dlsym(impl, sym);
#endif
}

operator bool() const { return bool(impl); }
Expand All @@ -71,4 +89,3 @@ class dylib_loader
void* impl{};
};
}
#endif

0 comments on commit 7bef967

Please sign in to comment.