Skip to content

Commit

Permalink
sdl: use versioned library, cleanup ffi/util helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre authored and Frenzie committed Sep 22, 2024
1 parent e65c7dd commit 2f73ca9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 95 deletions.
8 changes: 1 addition & 7 deletions ffi/SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ require("ffi/linux_input_h")

-----------------------------------------------------------------

local SDL = util.ffiLoadCandidates{
"SDL2",
-- this unfortunately needs to be written in full due to the . in the name
"libSDL2-2.0.so",
"libSDL2-2.0.so.0",
util.KO_DYLD_PREFIX .. "/lib/libSDL2.dylib",
}
local SDL = util.loadSDL2()

-- Some features (like SDL_GameControllerRumble) may require a minimum version
-- of SDL. These helper functions allow us to prevent any issues with calling
Expand Down
6 changes: 2 additions & 4 deletions ffi/input.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local util = require("ffi/util")

if util.isSDL() then
if util.haveSDL2() then
return require("ffi/input_SDL2_0")
end
if util.haveSDL2() then
return require("ffi/input_SDL2_0")
elseif util.isAndroid() then
return require("ffi/input_android")
elseif util.isPocketbook() then
Expand Down
47 changes: 13 additions & 34 deletions ffi/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -646,17 +646,14 @@ end

function util.ffiLoadCandidates(candidates)
local lib_loaded, lib

for _, candidate in ipairs(candidates) do
lib_loaded, lib = pcall(ffi.load, candidate)

if lib_loaded then
return lib
end
end

-- we failed, lib is the error message
return lib_loaded, lib
return false, lib
end

local isAndroid = nil
Expand All @@ -673,40 +670,22 @@ function util.isPocketbook()
return lfs.attributes("/ebrmain/pocketbook")
end

local haveSDL2 = nil
--- Returns true if SDL2
function util.haveSDL2()
local err

if haveSDL2 == nil then
local candidates
local libSDL2 = nil
--- Returns SDL2 library
function util.loadSDL2()
if libSDL2 == nil then
local candidates, err
if ffi.os == "OSX" then
candidates = {"libs/libSDL2.dylib", "SDL2", util.KO_DYLD_PREFIX .. "/lib/libSDL2.dylib"}
candidates = {"libs/libSDL2-2.0.dylib", util.KO_DYLD_PREFIX .. "/lib/libSDL2-2.0.0.dylib", "SDL2"}
else
candidates = {"SDL2", "libSDL2-2.0.so", "libSDL2-2.0.so.0"}
candidates = {"libs/libSDL2-2.0.so.0", "libSDL2-2.0.so.0", "SDL2"}
end
libSDL2, err = util.ffiLoadCandidates(candidates)
if not libSDL2 then
print("SDL2 not loaded:", err)
end
haveSDL2, err = util.ffiLoadCandidates(candidates)
end
if not haveSDL2 then
print("SDL2 not loaded:", err)
end

return haveSDL2
end

local isSDL = nil
--- Returns true if SDL
function util.isSDL()
if isSDL == nil then
isSDL = util.haveSDL2()
end
return isSDL
end

--- Silence the SDL checks (solely for front's frontend/device.lua usage!)
function util.noSDL()
haveSDL2 = false
isSDL = false
return libSDL2 or nil
end

--- Division with integer result.
Expand Down
4 changes: 1 addition & 3 deletions thirdparty/sdl2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ list(APPEND PATCH_FILES
# Remove workarounds for standalone applications and add
# a couple of actions to be used from the osx main menu.
cocoa.patch
# FIXME: koreader should really be using `libSDL2-2.0.so.0` instead.
no_library_versioning.patch
)

list(APPEND CMAKE_ARGS
Expand All @@ -21,7 +19,7 @@ list(APPEND BUILD_CMD COMMAND ninja)

list(APPEND INSTALL_CMD COMMAND ${CMAKE_COMMAND} --install .)

append_shared_lib_install_commands(INSTALL_CMD SDL2)
append_shared_lib_install_commands(INSTALL_CMD SDL2-2.0 VERSION 0)

external_project(
DOWNLOAD URL a344eb827a03045c9b399e99af4af13d
Expand Down
47 changes: 0 additions & 47 deletions thirdparty/sdl2/no_library_versioning.patch

This file was deleted.

0 comments on commit 2f73ca9

Please sign in to comment.