Skip to content

Commit

Permalink
Support LIBSDL2_TTF_SHLIB
Browse files Browse the repository at this point in the history
The environment variable avoids the runtime search for the SDL2_ttf shared library and also the Unix-specific fallback to pkg-config.

It allows a debug library (ex. SDL2_ttfd.dll) to be used.
  • Loading branch information
jonahbeckford committed Mar 7, 2024
1 parent edb9b92 commit 8013965
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Pending

* Allow exact location of `libSDL2_ttf-2.0.so.0` to be set in
`LIBSDL2_TTF_SHLIB` for situations where you have a debug shared
library or you don't want `pkg-config` invoked.

# 0.6 2023/08/05 hide startup log

* Use system category to log "Loading Sdl_ttf" message. (We now
Expand Down
7 changes: 6 additions & 1 deletion src/tsdl_ttf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module Ttf = struct
#require "tsdl-ttf"
in the toplevel, see
https://github.com/ocamllabs/ocaml-ctypes/issues/70 *)
let from : Dl.library option =
let from_with_search : Dl.library option =
(if debug then
Sdl.(
log_info Log.category_system "Loading Sdl_ttf, Target = %s"
Expand Down Expand Up @@ -116,6 +116,11 @@ module Ttf = struct
("Cannot find " ^ filename ^ ", please set LIBSDL2_PATH");
None)

let from : Dl.library option =
let shlib = try Sys.getenv "LIBSDL2_TTF_SHLIB" with Not_found -> "" in
if shlib = "" then from_with_search
else Some Dl.(dlopen ~filename:shlib ~flags:[ RTLD_NOW ])

let foreign = foreign ?from
let init = foreign "TTF_Init" (void @-> returning zero_to_ok)

Expand Down

0 comments on commit 8013965

Please sign in to comment.