Skip to content

Commit

Permalink
Add libsdl3 (#6225)
Browse files Browse the repository at this point in the history
* Add libsdl3

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Try to enable x11 on cross

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua
  • Loading branch information
SirLynix authored Feb 4, 2025
1 parent a913ba1 commit fab4640
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/l/libpthread-stubs/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package("libpthread-stubs")

add_deps("pkg-config")

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
import("package.tools.autoconf").install(package)
end)

Expand Down
132 changes: 132 additions & 0 deletions packages/l/libsdl3/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package("libsdl3")
set_homepage("https://www.libsdl.org/")
set_description("Simple DirectMedia Layer")
set_license("zlib")

if is_plat("mingw") and is_subhost("msys") then
add_extsources("pacman::SDL3")
elseif is_plat("linux") then
add_extsources("pacman::sdl3", "apt::libsdl3-dev")
elseif is_plat("macosx") then
add_extsources("brew::sdl3")
end

add_urls("https://www.libsdl.org/release/SDL3-$(version).zip",
"https://github.com/libsdl-org/SDL/releases/download/release-$(version)/SDL3-$(version).zip", { alias = "archive" })
add_urls("https://github.com/libsdl-org/SDL.git", { alias = "github" })

add_versions("archive:3.2.2", "58d8adc7068d38923f918e0bdaa9c4948f93d9ba204fe4de8cc6eaaf77ad6f82")
add_versions("archive:3.2.0", "abe7114fa42edcc8097856787fa5d37f256d97e365b71368b60764fe7c10e4f8")

add_versions("github:3.2.2", "release-3.2.2")
add_versions("github:3.2.0", "release-3.2.0")

add_deps("cmake", "egl-headers", "opengl-headers")

if is_plat("linux", "bsd", "cross") then
add_configs("x11", {description = "Enables X11 support", default = true, type = "boolean"})
add_configs("wayland", {description = "Enables Wayland support", default = nil, type = "boolean"})
end

if is_plat("wasm") then
add_cxflags("-sUSE_SDL=0")
end

on_load(function (package)
if package:is_plat("linux", "android", "cross") then
-- Enable Wayland by default except when cross-compiling (wayland package doesn't support cross-compilation yet)
if package:config("wayland") == nil and not package:is_cross() then
package:config_set("wayland", true)
end
end

if package:is_plat("windows") then
package:add("deps", "ninja")
package:set("policy", "package.cmake_generator.ninja", true)
end
if package:is_plat("linux", "bsd", "cross") and package:config("x11") then
package:add("deps", "libxext", {private = true})
end
if package:is_plat("linux", "bsd", "cross") and package:config("wayland") then
package:add("deps", "wayland", {private = true})
end
local libsuffix = package:is_debug() and "d" or ""
if not package:config("shared") then
if package:is_plat("windows", "mingw") then
package:add("syslinks", "user32", "gdi32", "winmm", "imm32", "ole32", "oleaut32", "version", "uuid", "advapi32", "setupapi", "shell32")
elseif package:is_plat("linux", "bsd") then
package:add("syslinks", "pthread", "dl")
if package:is_plat("bsd") then
package:add("syslinks", "usbhid")
end
elseif package:is_plat("android") then
package:add("syslinks", "dl", "log", "android", "GLESv1_CM", "GLESv2", "OpenSLES")
elseif package:is_plat("iphoneos", "macosx") then
package:add("frameworks", "AudioToolbox", "AVFoundation", "CoreAudio", "CoreHaptics", "CoreMedia", "CoreVideo", "Foundation", "GameController", "Metal", "QuartzCore", "CoreFoundation", "UniformTypeIdentifiers")
package:add("syslinks", "iconv")
if package:is_plat("macosx") then
package:add("frameworks", "Cocoa", "Carbon", "ForceFeedback", "IOKit")
else
package:add("frameworks", "CoreBluetooth", "CoreGraphics", "CoreMotion", "OpenGLES", "UIKit")
end
end
end
end)

on_install(function (package)
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DSDL_TEST_LIBRARY=OFF")
table.insert(configs, "-DSDL_EXAMPLES=OFF")

local cflags
local packagedeps
if not package:is_plat("wasm") then
packagedeps = {"egl-headers", "opengl-headers"}
end

if package:is_plat("linux", "bsd", "cross") then
table.insert(packagedeps, "libxext")
table.insert(packagedeps, "libx11")
table.insert(packagedeps, "xorgproto")
table.insert(packagedeps, "wayland")
elseif package:is_plat("wasm") then
-- emscripten enables USE_SDL by default which will conflict with libsdl headers
cflags = {"-sUSE_SDL=0"}
end

local includedirs = {}
for _, depname in ipairs(packagedeps) do
local dep = package:dep(depname)
if dep then
local depfetch = dep:fetch()
if depfetch then
for _, includedir in ipairs(depfetch.includedirs or depfetch.sysincludedirs) do
table.insert(includedirs, includedir)
end
end
end
end
if #includedirs > 0 then
includedirs = table.unique(includedirs)
table.insert(configs, "-DCMAKE_INCLUDE_PATH=" .. table.concat(includedirs, ";"))
cflags = cflags or {}
for _, includedir in ipairs(includedirs) do
table.insert(cflags, "-I" .. includedir)
end
end

import("package.tools.cmake").install(package, configs, {cflags = cflags})
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <SDL3/SDL.h>
int main(int argc, char** argv) {
SDL_Init(0);
SDL_Quit();
return 0;
}
]]}));
end)
9 changes: 6 additions & 3 deletions packages/l/libx11/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ package("libx11")
add_extsources("brew::libx11")
end

if is_plat("linux", "bsd") then
if is_plat("linux", "bsd", "cross") then
add_syslinks("dl")
end

add_configs("shared", {description = "Build shared library.", default = true, type = "boolean"})

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "util-macros", "xtrans", "libxcb", "xorgproto")
end
if is_plat("macosx") then
-- fix sed: RE error: illegal byte sequence
add_deps("gnu-sed")
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand All @@ -46,6 +46,9 @@ package("libx11")
if package:config("pic") then
table.insert(configs, "--with-pic")
end
if package:is_plat("cross") then
table.insert(configs, "--disable-malloc0returnsnull")
end
import("package.tools.autoconf").install(package, configs)
end)

Expand Down
4 changes: 2 additions & 2 deletions packages/l/libxau/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ package("libxau")
add_extsources("apt::libxau-dev", "pacman::libxau")
end

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "util-macros", "xorgproto")
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand Down
4 changes: 2 additions & 2 deletions packages/l/libxcb/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ package("libxcb")
add_extsources("apt::libxcb1-dev", "pacman::libxcb")
end

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "python 3.x", {kind = "binary"})
add_deps("xcb-proto", "libpthread-stubs", "libxau", "libxdmcp")
end
Expand All @@ -59,7 +59,7 @@ package("libxcb")
end
end)

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand Down
4 changes: 2 additions & 2 deletions packages/l/libxdmcp/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package("libxdmcp")
add_extsources("apt::libxdmcp-dev", "pacman::libxmdcp")
end

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "xorgproto")
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand Down
7 changes: 5 additions & 2 deletions packages/l/libxext/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package("libxext")
add_extsources("apt::libxext-dev")
end

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "libx11", "xorgproto")
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand All @@ -25,6 +25,9 @@ package("libxext")
if package:config("pic") then
table.insert(configs, "--with-pic")
end
if package:is_plat("cross") then
table.insert(configs, "--disable-malloc0returnsnull")
end
import("package.tools.autoconf").install(package, configs)
end)

Expand Down
2 changes: 1 addition & 1 deletion packages/u/util-macros/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package("util-macros")

add_deps("pkg-config")

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var")}
import("package.tools.autoconf").install(package, configs)
Expand Down
7 changes: 5 additions & 2 deletions packages/w/wayland/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ package("wayland")
os.mkdir(package:installdir("share", "aclocal"))

-- build wayland
local configs = {"-Ddocumentation=false", "-Dc_link_args=-lm"}
local configs = {"-Ddtd_validation=false", "-Ddocumentation=false", "-Dtests=false", "-Dc_link_args=-lm"}
table.insert(configs, "-Dscanner=" .. (package:is_cross() and "false" or "true"))
table.insert(configs, "--libdir=lib")
local envs = meson.buildenvs(package)
envs.LD_LIBRARY_PATH = path.joinenv(table.join(LD_LIBRARY_PATH, envs.LD_LIBRARY_PATH))
Expand All @@ -42,6 +43,8 @@ package("wayland")
end)

on_test(function (package)
os.vrun("wayland-scanner --version")
if not package:is_cross() then
os.vrun("wayland-scanner --version")
end
assert(package:has_cfuncs("wl_list_init", {includes = "wayland-util.h"}))
end)
4 changes: 2 additions & 2 deletions packages/x/xcb-proto/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ package("xcb-proto")
add_versions("1.14.1", "85cd21e9d9fbc341d0dbf11eace98d55d7db89fda724b0e598855fcddf0944fd")
add_versions("1.16.0", "d9c7f010b1105fc3858bf07b5169b2dd8e7493c6652b1fe45f3321d874f291d7")

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "python 3.x", {kind = "binary"})
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-silent-rules",
Expand Down
4 changes: 2 additions & 2 deletions packages/x/xorgproto/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ package("xorgproto")
add_extsources("apt::x11proto-dev", "pkgconfig::xproto")
end

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "util-macros")
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand Down
4 changes: 2 additions & 2 deletions packages/x/xtrans/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package("xtrans")
add_extsources("apt::xtrans-dev", "pacman::xtrans")
end

if is_plat("macosx", "linux", "bsd") then
if is_plat("macosx", "linux", "bsd", "cross") then
add_deps("pkg-config", "util-macros", "xorgproto")
end

on_install("macosx", "linux", "bsd", function (package)
on_install("macosx", "linux", "bsd", "cross", function (package)
local configs = {"--sysconfdir=" .. package:installdir("etc"),
"--localstatedir=" .. package:installdir("var"),
"--disable-dependency-tracking",
Expand Down

0 comments on commit fab4640

Please sign in to comment.