Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/sdl3.py
4130 views
1
# Copyright 2025 The Emscripten Authors. All rights reserved.
2
# Emscripten is available under two separate licenses, the MIT license and the
3
# University of Illinois/NCSA Open Source License. Both these licenses can be
4
# found in the LICENSE file.
5
6
import glob
7
import os
8
import shutil
9
10
from tools import diagnostics
11
12
VERSION = '3.2.4'
13
TAG = f'release-{VERSION}'
14
HASH = 'c26a8afeec481e3ae3b435eec405d9f99d78752ebf5118963cd56728ceff23772769f5291df581329488da7489034e835301b08d61a42c811764e24b3542a4c2'
15
SUBDIR = f'SDL-{TAG}'
16
17
variants = {'sdl3-mt': {'PTHREADS': 1}}
18
19
20
def needed(settings):
21
return settings.USE_SDL == 3
22
23
24
def get_lib_name(settings):
25
return 'libSDL3' + ('-mt' if settings.PTHREADS else '') + '.a'
26
27
28
def process_dependencies(settings, cflags_only):
29
if not cflags_only:
30
# SDL3 includes an internal reference to Module['createContext']
31
settings.EXPORTED_RUNTIME_METHODS.append('createContext')
32
33
34
def get(ports, settings, shared):
35
# get the port
36
ports.fetch_project('sdl3', f'https://github.com/libsdl-org/SDL/archive/{TAG}.zip', sha512hash=HASH)
37
38
def create(final):
39
diagnostics.warning('experimental', 'sdl3 port is still experimental')
40
root_dir = ports.get_dir('sdl3', SUBDIR)
41
42
# In addition copy our pre-generated SDL_build_config.h file.
43
sdl_build_config_h = os.path.join(os.path.dirname(__file__), 'sdl3/SDL_build_config.h')
44
shutil.copyfile(sdl_build_config_h, os.path.join(root_dir, 'include/SDL3/SDL_build_config.h'))
45
46
# copy includes to a location so they can be used as 'SDL3/'
47
source_include_path = os.path.join(root_dir, 'include', 'SDL3')
48
ports.install_headers(source_include_path, target='SDL3')
49
ports.make_pkg_config('sdl3', VERSION, '-sUSE_SDL=3')
50
51
# copy sdl3-config.cmake
52
cmake_file = os.path.join(os.path.dirname(__file__), 'sdl3/sdl3-config.cmake')
53
ports.install_file(cmake_file, 'lib/cmake/SDL3/sdl3-config.cmake')
54
55
glob_patterns = [
56
# Generic sources (from SDL3's CMakeLists.txt)
57
'*.c',
58
'atomic/*.c',
59
'audio/*.c',
60
'camera/*.c',
61
'core/*.c',
62
'cpuinfo/*.c',
63
'dynapi/*.c',
64
'events/*.c',
65
'io/*.c',
66
'io/generic/*.c',
67
'filesystem/*.c',
68
'gpu/*.c',
69
'joystick/*.c',
70
'haptic/*.c',
71
'hidapi/*.c',
72
'locale/*.c',
73
'main/*.c',
74
'misc/*.c',
75
'power/*.c',
76
'render/*.c',
77
'render/*/*.c',
78
'sensor/*.c',
79
'stdlib/*.c',
80
'storage/*.c',
81
'thread/*.c',
82
'time/*.c',
83
'timer/*.c',
84
'video/*.c',
85
'video/yuv2rgb/*.c',
86
'tray/*.c',
87
# Platform speecifc sources
88
'storage/generic/*.c',
89
'tray/unix/*.c',
90
'time/unix/*.c',
91
'timer/unix/*.c',
92
'main/emscripten/*.c',
93
'filesystem/posix/*.c',
94
'filesystem/emscripten/*.c',
95
'locale/emscripten/*.c',
96
'camera/emscripten/*.c',
97
'joystick/emscripten/*.c',
98
'joystick/virtual/*.c',
99
'power/emscripten/*.c',
100
'misc/emscripten/*.c',
101
'audio/emscripten/*.c',
102
'video/emscripten/*.c',
103
'video/offscreen/*.c',
104
'audio/disk/*.c',
105
'loadso/dlopen/*.c',
106
# Dummy backends, do we need to support these?
107
'camera/dummy/*.c',
108
'audio/dummy/*.c',
109
'video/dummy/*.c',
110
'haptic/dummy/*.c',
111
'sensor/dummy/*.c',
112
]
113
114
flags = ['-sUSE_SDL=0']
115
if settings.PTHREADS:
116
glob_patterns.append('thread/pthread/*.c')
117
flags += ['-pthread']
118
else:
119
glob_patterns.append('thread/generic/*.c')
120
121
srcs = []
122
for pattern in glob_patterns:
123
matches = glob.glob(os.path.join(root_dir, 'src', pattern))
124
assert matches
125
srcs += matches
126
127
srcs = [os.path.join(root_dir, 'src', s) for s in srcs]
128
includes = [ports.get_include_dir('SDL3'), os.path.join(root_dir, 'src')]
129
ports.build_port(root_dir, final, 'sdl3', srcs=srcs, includes=includes, flags=flags)
130
131
return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]
132
133
134
def clear(ports, settings, shared):
135
shared.cache.erase_lib(get_lib_name(settings))
136
137
138
def show():
139
return 'sdl2 (-sUSE_SDL=3 or --use-port=sdl3; zlib license)'
140
141