Skip to content

Commit

Permalink
DynamicLibrary: Add patch to versioned filename
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jul 28, 2024
1 parent 40356fc commit 876f212
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/common/dynamic_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,32 @@ std::string DynamicLibrary::GetUnprefixedFilename(const char* filename)
#endif
}

std::string DynamicLibrary::GetVersionedFilename(const char* libname, int major, int minor)
std::string DynamicLibrary::GetVersionedFilename(const char* libname, int major, int minor, int patch)
{
#if defined(_WIN32)
if (major >= 0 && minor >= 0)
if (major >= 0 && minor >= 0 && patch >= 0)
return fmt::format("{}-{}-{}-{}.dll", libname, major, minor, patch);
else if (major >= 0 && minor >= 0)
return fmt::format("{}-{}-{}.dll", libname, major, minor);
else if (major >= 0)
return fmt::format("{}-{}.dll", libname, major);
else
return fmt::format("{}.dll", libname);
#elif defined(__APPLE__)
const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : "";
if (major >= 0 && minor >= 0)
if (major >= 0 && minor >= 0 && patch >= 0)
return fmt::format("{}{}.{}.{}.{}.dylib", prefix, libname, major, minor, patch);
else if (major >= 0 && minor >= 0)
return fmt::format("{}{}.{}.{}.dylib", prefix, libname, major, minor);
else if (major >= 0)
return fmt::format("{}{}.{}.dylib", prefix, libname, major);
else
return fmt::format("{}{}.dylib", prefix, libname);
#else
const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : "";
if (major >= 0 && minor >= 0)
if (major >= 0 && minor >= 0 && patch >= 0)
return fmt::format("{}{}.so.{}.{}.{}", prefix, libname, major, minor, patch);
else if (major >= 0 && minor >= 0)
return fmt::format("{}{}.so.{}.{}", prefix, libname, major, minor);
else if (major >= 0)
return fmt::format("{}{}.so.{}", prefix, libname, major);
Expand Down
8 changes: 4 additions & 4 deletions src/common/dynamic_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class DynamicLibrary final
/// Returns the specified library name in platform-specific format.
/// Major/minor versions will not be included if set to -1.
/// If libname already contains the "lib" prefix, it will not be added again.
/// Windows: LIBNAME-MAJOR-MINOR.dll
/// Linux: libLIBNAME.so.MAJOR.MINOR
/// Mac: libLIBNAME.MAJOR.MINOR.dylib
static std::string GetVersionedFilename(const char* libname, int major = -1, int minor = -1);
/// Windows: LIBNAME-MAJOR-MINOR-PATCH.dll
/// Linux: libLIBNAME.so.MAJOR.MINOR.PATCH
/// Mac: libLIBNAME.MAJOR.MINOR.PATCH.dylib
static std::string GetVersionedFilename(const char* libname, int major = -1, int minor = -1, int patch = -1);

/// Returns true if a module is loaded, otherwise false.
bool IsOpen() const { return m_handle != nullptr; }
Expand Down

0 comments on commit 876f212

Please sign in to comment.