Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/sdl3.py
6175 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.30'
13
TAG = f'release-{VERSION}'
14
HASH = '80ef7b2f257f43fe47c7ea8aa0a64f1c6f23720d91065d5e9b42f0205c62fc98bcf8dd1f1834fe09c66bea2598a18a658b82212cb29810be2d2175dece0aadce'
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 get(ports, settings, shared):
29
# get the port
30
ports.fetch_project('sdl3', f'https://github.com/libsdl-org/SDL/archive/{TAG}.zip', sha512hash=HASH)
31
32
def create(final):
33
diagnostics.warning('experimental', 'sdl3 port is still experimental')
34
root_dir = ports.get_dir('sdl3', SUBDIR)
35
36
# In addition copy our pre-generated SDL_build_config.h file.
37
sdl_build_config_h = os.path.join(os.path.dirname(__file__), 'sdl3/SDL_build_config.h')
38
shutil.copyfile(sdl_build_config_h, os.path.join(root_dir, 'include/SDL3/SDL_build_config.h'))
39
40
# copy includes to a location so they can be used as 'SDL3/'
41
source_include_path = os.path.join(root_dir, 'include', 'SDL3')
42
ports.install_headers(source_include_path, target='SDL3')
43
ports.make_pkg_config('sdl3', VERSION, '-sUSE_SDL=3')
44
45
# copy sdl3-config.cmake
46
cmake_file = os.path.join(os.path.dirname(__file__), 'sdl3/sdl3-config.cmake')
47
ports.install_file(cmake_file, 'lib/cmake/SDL3/sdl3-config.cmake')
48
49
glob_patterns = [
50
# Generic sources (from SDL3's CMakeLists.txt)
51
'*.c',
52
'atomic/*.c',
53
'audio/*.c',
54
'camera/*.c',
55
'core/*.c',
56
'cpuinfo/*.c',
57
'dynapi/*.c',
58
'events/*.c',
59
'io/*.c',
60
'io/generic/*.c',
61
'filesystem/*.c',
62
'gpu/*.c',
63
'joystick/*.c',
64
'haptic/*.c',
65
'hidapi/*.c',
66
'locale/*.c',
67
'main/*.c',
68
'misc/*.c',
69
'power/*.c',
70
'render/*.c',
71
'render/*/*.c',
72
'sensor/*.c',
73
'stdlib/*.c',
74
'storage/*.c',
75
'thread/*.c',
76
'time/*.c',
77
'timer/*.c',
78
'video/*.c',
79
'video/yuv2rgb/*.c',
80
'tray/*.c',
81
# Platform specific sources
82
'storage/generic/*.c',
83
'tray/unix/*.c',
84
'time/unix/*.c',
85
'timer/unix/*.c',
86
'main/emscripten/*.c',
87
'filesystem/posix/*.c',
88
'filesystem/emscripten/*.c',
89
'locale/emscripten/*.c',
90
'camera/emscripten/*.c',
91
'joystick/emscripten/*.c',
92
'joystick/virtual/*.c',
93
'power/emscripten/*.c',
94
'misc/emscripten/*.c',
95
'audio/emscripten/*.c',
96
'video/emscripten/*.c',
97
'video/offscreen/*.c',
98
'audio/disk/*.c',
99
'loadso/dlopen/*.c',
100
# Dummy backends, do we need to support these?
101
'camera/dummy/*.c',
102
'audio/dummy/*.c',
103
'video/dummy/*.c',
104
'haptic/dummy/*.c',
105
'sensor/dummy/*.c',
106
]
107
108
flags = ['-sUSE_SDL=0']
109
if settings.PTHREADS:
110
glob_patterns.append('thread/pthread/*.c')
111
flags += ['-pthread']
112
else:
113
glob_patterns.append('thread/generic/*.c')
114
115
srcs = []
116
for pattern in glob_patterns:
117
matches = glob.glob(os.path.join(root_dir, 'src', pattern))
118
assert matches
119
srcs += matches
120
121
srcs = [os.path.join(root_dir, 'src', s) for s in srcs]
122
includes = [ports.get_include_dir('SDL3'), os.path.join(root_dir, 'src')]
123
ports.build_port(root_dir, final, 'sdl3', srcs=srcs, includes=includes, flags=flags)
124
125
return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]
126
127
128
def clear(ports, settings, shared):
129
shared.cache.erase_lib(get_lib_name(settings))
130
131
132
def show():
133
return 'sdl3 (-sUSE_SDL=3 or --use-port=sdl3; zlib license)'
134
135