From 7f9ebd2ee59bf03ff1b7c2281931cd0017aa46df Mon Sep 17 00:00:00 2001 From: Mats Engstrom Date: Mon, 16 Mar 2026 21:01:30 +0100 Subject: build: autodetect Homebrew SDL3 on macOS (#15108) --- scripts/src/osd/sdl3.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/src/osd/sdl3.lua b/scripts/src/osd/sdl3.lua index f6ce6db8221..b68ee0c2771 100644 --- a/scripts/src/osd/sdl3.lua +++ b/scripts/src/osd/sdl3.lua @@ -114,6 +114,24 @@ function sdlconfigcmd() end end +local function sdlpkgconfigcmd() + if _OPTIONS["SDL_PKGCONFIG_PATH"] then + return path.join(_OPTIONS["SDL_PKGCONFIG_PATH"],"pkg-config") + else + return pkgconfigcmd() + end +end + +local function macosx_uses_libsdl_by_default() + if _OPTIONS["targetos"]~="macosx" then + return false + elseif _OPTIONS["SDL_INSTALL_ROOT"] then + return true + else + return os.execute(sdlpkgconfigcmd() .. " --exists sdl3") + end +end + newoption { trigger = "MESA_INSTALL_ROOT", @@ -179,7 +197,7 @@ newoption { newoption { trigger = "SDL_PKGCONFIG_PATH", - description = "Location of pkg-config command that knows about SDL. Useful for non-root Homebrew installs on Linux.", + description = "Location of pkg-config command that knows about SDL. Useful for non-default Homebrew installs.", } newoption { @@ -187,6 +205,8 @@ newoption { description = "Location of SDL framework for custom OS X installations", } +local framework_path_default = (_OPTIONS["SDL_FRAMEWORK_PATH"] == nil) + -- SDL 3's framework now contains all Apple platforms in a single framework, so we need to -- specifically ask for the macOS version. if not _OPTIONS["SDL_FRAMEWORK_PATH"] then @@ -202,10 +222,18 @@ newoption { }, } +local use_libsdl_default = (_OPTIONS["USE_LIBSDL"] == nil) + if not _OPTIONS["USE_LIBSDL"] then _OPTIONS["USE_LIBSDL"] = "0" end +-- Prefer pkg-config/library installs on macOS when available, as that is the +-- common Homebrew layout. Preserve explicit framework and USE_LIBSDL choices. +if use_libsdl_default and framework_path_default and macosx_uses_libsdl_by_default() then + _OPTIONS["USE_LIBSDL"] = "1" +end + BASE_TARGETOS = "unix" SDLOS_TARGETOS = "unix" @@ -227,7 +255,6 @@ if BASE_TARGETOS=="unix" then "-framework QuartzCore", "-framework OpenGL", "-framework IOKit", - "-rpath " .. _OPTIONS["SDL_FRAMEWORK_PATH"], } @@ -238,6 +265,7 @@ if BASE_TARGETOS=="unix" then end if _OPTIONS["USE_LIBSDL"]~="1" then linkoptions { + "-rpath " .. _OPTIONS["SDL_FRAMEWORK_PATH"], "-F" .. _OPTIONS["SDL_FRAMEWORK_PATH"], } links { -- cgit v1.2.3