Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libsdl3 #6225

Draft
wants to merge 32 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4749df9
Add libsdl3
SirLynix Jan 23, 2025
b19efba
Update xmake.lua
SirLynix Jan 23, 2025
0793388
Update xmake.lua
SirLynix Jan 23, 2025
a465c81
Update xmake.lua
SirLynix Jan 24, 2025
b2cdc39
Update xmake.lua
SirLynix Jan 25, 2025
ae93bfd
Update xmake.lua
SirLynix Jan 28, 2025
df875c6
Update xmake.lua
SirLynix Jan 28, 2025
72d2522
Update xmake.lua
SirLynix Jan 28, 2025
a388ff4
Update xmake.lua
SirLynix Jan 31, 2025
91eae42
Update xmake.lua
SirLynix Jan 31, 2025
c791824
Update xmake.lua
SirLynix Feb 1, 2025
d09d5f0
Update xmake.lua
SirLynix Feb 2, 2025
1f789f3
Update xmake.lua
SirLynix Feb 2, 2025
e0de0b0
Update xmake.lua
SirLynix Feb 2, 2025
3676065
Update xmake.lua
SirLynix Feb 2, 2025
89c556b
Update xmake.lua
SirLynix Feb 2, 2025
c8ebd53
Update xmake.lua
SirLynix Feb 2, 2025
d23f3ff
Update xmake.lua
SirLynix Feb 2, 2025
cbeec59
Update xmake.lua
SirLynix Feb 2, 2025
a0855ac
Merge branch 'dev' into SirLynix-patch-2
SirLynix Feb 3, 2025
552a727
Update xmake.lua
SirLynix Feb 3, 2025
a075453
Update xmake.lua
SirLynix Feb 3, 2025
100f785
Update xmake.lua
SirLynix Feb 3, 2025
44425f4
Update xmake.lua
SirLynix Feb 3, 2025
d3cd88d
Update xmake.lua
SirLynix Feb 3, 2025
2a4d4b4
Try to enable x11 on cross
SirLynix Feb 3, 2025
5f7d144
Update xmake.lua
SirLynix Feb 3, 2025
6d2afbc
Update xmake.lua
SirLynix Feb 3, 2025
02eda2c
Update xmake.lua
SirLynix Feb 3, 2025
3c05207
Update xmake.lua
SirLynix Feb 3, 2025
9437af4
Update xmake.lua
SirLynix Feb 3, 2025
79218fc
Update xmake.lua
SirLynix Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions packages/l/libsdl3/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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.0", "abe7114fa42edcc8097856787fa5d37f256d97e365b71368b60764fe7c10e4f8")
add_versions("github:3.2.0", "release-3.2.0")

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

if is_plat("linux", "bsd") then
add_configs("x11", {description = "Enables X11 support (requires it on the system)", default = true, type = "boolean"})
add_configs("wayland", {description = "Enables Wayland support", default = true, type = "boolean"})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't do linux development, but is there a reason why these are enabled by default on that platform? I thought you could develop a libsdl3 application without these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the main feature of SDL (and reason people use it) is input and window management, which need x11/wayland to work.
It's very rare to use libsdl without these

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always wary about defaults being enabled because you can't really take it back later. Even if it's rare, minimal dependencies by default should still be a consideration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but libsdl is a bit special, it only requires headers to build as it doesn't link x11 nor wayland, it loads them manually (dlopen/dlsym) at runtime only if they're available.

A good default for libsdl is to build it with as many deps as possible for this reason

end

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

on_load(function (package)
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("!cross", 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") 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 the sdl 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/w/wayland/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package("wayland")
add_deps("epoll-shim")
end

on_install("linux", "bsd", function (package)
on_install("linux", "bsd", "cross", function (package)
-- imports
import("package.tools.meson")
import("lib.detect.find_file")
Expand All @@ -36,7 +36,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 Down Expand Up @@ -67,6 +68,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)
Loading