Skip to content

Commit 0b5ea9a

Browse files
committed
Add meson flag for compiling with SDL3
1 parent 1a28571 commit 0b5ea9a

File tree

3 files changed

+88
-56
lines changed

3 files changed

+88
-56
lines changed

buildconfig/download_win_prebuilt.py

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def get_urls(x86=True, x64=True):
8282
'9121a66a4bc45d657d0c15300cee6c7f37ade51d',
8383
],
8484
[
85+
'https://github.com/libsdl-org/SDL/releases/download/preview-3.1.3/SDL3-devel-3.1.3-VC.zip',
86+
'8e4d7104193ba976406fe9968301de6f6b57f342'
87+
],
88+
[
8589
'https://github.com/pygame-community/SDL_image/releases/download/2.8.2-pgce/SDL2_image-devel-2.8.2-VCpgce.zip',
8690
'983484dd816abf25cdd5bce88ac69dbca1ea713a'
8791
],
@@ -242,6 +246,17 @@ def copy(src, dst):
242246
'SDL2-2.30.7'
243247
)
244248
)
249+
copy(
250+
os.path.join(
251+
temp_dir,
252+
'SDL3-devel-3.1.3-VC/SDL3-3.1.3'
253+
),
254+
os.path.join(
255+
move_to_dir,
256+
prebuilt_dir,
257+
'SDL3-3.1.3'
258+
)
259+
)
245260

246261
def update(x86=True, x64=True):
247262
move_to_dir = "."

meson.build

+70-56
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ endif
7878

7979
pg_dir = py.get_install_dir() / pg
8080

81+
sdl_api = get_option('sdl_api')
82+
sdl = 'SDL@0@'.format(sdl_api)
83+
sdl_mixer = '@0@_mixer'.format(sdl)
84+
sdl_ttf = '@0@_ttf'.format(sdl)
85+
sdl_image = '@0@_image'.format(sdl)
86+
8187
pg_inc_dirs = []
8288
pg_lib_dirs = []
8389
if plat == 'win' and host_machine.cpu_family().startswith('x86')
@@ -99,60 +105,68 @@ if plat == 'win' and host_machine.cpu_family().startswith('x86')
99105
)
100106
endif
101107

102-
sdl_ver = '2.30.7'
108+
sdl_ver = (sdl_api == 3) ? '3.1.3' : '2.30.7'
103109
sdl_image_ver = '2.8.2'
104110
sdl_mixer_ver = '2.8.0'
105111
sdl_ttf_ver = '2.22.0'
106112

107113
dlls = []
108114

109-
# SDL2
110-
sdl_dir = prebuilt_dir / 'SDL2-@0@'.format(sdl_ver)
115+
# SDL
116+
sdl_dir = prebuilt_dir / '@0@-@1@'.format(sdl, sdl_ver)
111117
sdl_lib_dir = sdl_dir / 'lib' / arch_suffix
112118
pg_inc_dirs += fs.relative_to(sdl_dir / 'include', base_dir)
113119
pg_lib_dirs += sdl_lib_dir
114-
dlls += sdl_lib_dir / 'SDL2.dll'
115-
116-
# SDL2_image
117-
sdl_image_dir = prebuilt_dir / 'SDL2_image-@0@'.format(sdl_image_ver)
118-
sdl_image_lib_dir = sdl_image_dir / 'lib' / arch_suffix
119-
pg_inc_dirs += fs.relative_to(sdl_image_dir / 'include', base_dir)
120-
pg_lib_dirs += sdl_image_lib_dir
121-
dlls += [
122-
sdl_image_lib_dir / 'SDL2_image.dll',
123-
sdl_image_lib_dir / 'optional' / 'libjpeg-62.dll',
124-
sdl_image_lib_dir / 'optional' / 'libpng16-16.dll',
125-
sdl_image_lib_dir / 'optional' / 'libtiff-5.dll',
126-
sdl_image_lib_dir / 'optional' / 'libwebp-7.dll',
127-
sdl_image_lib_dir / 'optional' / 'libwebpdemux-2.dll',
128-
]
129-
130-
# SDL2_mixer
131-
sdl_mixer_dir = prebuilt_dir / 'SDL2_mixer-@0@'.format(sdl_mixer_ver)
132-
sdl_mixer_lib_dir = sdl_mixer_dir / 'lib' / arch_suffix
133-
pg_inc_dirs += fs.relative_to(sdl_mixer_dir / 'include', base_dir)
134-
pg_lib_dirs += sdl_mixer_lib_dir
135-
dlls += [
136-
sdl_mixer_lib_dir / 'SDL2_mixer.dll',
137-
sdl_mixer_lib_dir / 'optional' / 'libogg-0.dll',
138-
sdl_mixer_lib_dir / 'optional' / 'libopus-0.dll',
139-
sdl_mixer_lib_dir / 'optional' / 'libopusfile-0.dll',
140-
sdl_mixer_lib_dir / 'optional' / 'libwavpack-1.dll',
141-
sdl_mixer_lib_dir / 'optional' / 'libxmp.dll',
142-
]
143-
144-
# SDL2_ttf
145-
sdl_ttf_dir = prebuilt_dir / 'SDL2_ttf-@0@'.format(sdl_ttf_ver)
146-
sdl_ttf_lib_dir = sdl_ttf_dir / 'lib' / arch_suffix
147-
pg_inc_dirs += fs.relative_to(sdl_ttf_dir / 'include', base_dir)
148-
pg_lib_dirs += sdl_ttf_lib_dir
149-
dlls += sdl_ttf_lib_dir / 'SDL2_ttf.dll'
120+
dlls += sdl_lib_dir / '@0@.dll'.format(sdl)
121+
122+
# SDL_image
123+
if get_option('image').enabled()
124+
sdl_image_dir = prebuilt_dir / '@0@-@1@'.format(sdl_image, sdl_image_ver)
125+
sdl_image_lib_dir = sdl_image_dir / 'lib' / arch_suffix
126+
pg_inc_dirs += fs.relative_to(sdl_image_dir / 'include', base_dir)
127+
pg_lib_dirs += sdl_image_lib_dir
128+
dlls += [
129+
sdl_image_lib_dir / '@0@.dll'.format(sdl_image),
130+
sdl_image_lib_dir / 'optional' / 'libjpeg-62.dll',
131+
sdl_image_lib_dir / 'optional' / 'libpng16-16.dll',
132+
sdl_image_lib_dir / 'optional' / 'libtiff-5.dll',
133+
sdl_image_lib_dir / 'optional' / 'libwebp-7.dll',
134+
sdl_image_lib_dir / 'optional' / 'libwebpdemux-2.dll',
135+
]
136+
endif
137+
138+
# SDL_mixer
139+
if get_option('mixer').enabled()
140+
sdl_mixer_dir = prebuilt_dir / '@0@-@1@'.format(sdl_mixer, sdl_mixer_ver)
141+
sdl_mixer_lib_dir = sdl_mixer_dir / 'lib' / arch_suffix
142+
pg_inc_dirs += fs.relative_to(sdl_mixer_dir / 'include', base_dir)
143+
pg_lib_dirs += sdl_mixer_lib_dir
144+
dlls += [
145+
sdl_mixer_lib_dir / '@0@.dll'.format(sdl_mixer),
146+
sdl_mixer_lib_dir / 'optional' / 'libogg-0.dll',
147+
sdl_mixer_lib_dir / 'optional' / 'libopus-0.dll',
148+
sdl_mixer_lib_dir / 'optional' / 'libopusfile-0.dll',
149+
sdl_mixer_lib_dir / 'optional' / 'libwavpack-1.dll',
150+
sdl_mixer_lib_dir / 'optional' / 'libxmp.dll',
151+
]
152+
endif
153+
154+
# SDL_ttf
155+
if get_option('font').enabled()
156+
sdl_ttf_dir = prebuilt_dir / '@0@-@1@'.format(sdl_ttf, sdl_ttf_ver)
157+
sdl_ttf_lib_dir = sdl_ttf_dir / 'lib' / arch_suffix
158+
pg_inc_dirs += fs.relative_to(sdl_ttf_dir / 'include', base_dir)
159+
pg_lib_dirs += sdl_ttf_lib_dir
160+
dlls += sdl_ttf_lib_dir / '@0@.dll'.format(sdl_ttf)
161+
endif
150162

151163
# freetype, portmidi and porttime
152-
common_lib_dir = prebuilt_dir / 'lib'
153-
pg_inc_dirs += fs.relative_to(prebuilt_dir / 'include', base_dir)
154-
pg_lib_dirs += common_lib_dir
155-
dlls += [common_lib_dir / 'freetype.dll', common_lib_dir / 'portmidi.dll']
164+
if get_option('freetype').enabled() and get_option('midi').enabled()
165+
common_lib_dir = prebuilt_dir / 'lib'
166+
pg_inc_dirs += fs.relative_to(prebuilt_dir / 'include', base_dir)
167+
pg_lib_dirs += common_lib_dir
168+
dlls += [common_lib_dir / 'freetype.dll', common_lib_dir / 'portmidi.dll']
169+
endif
156170

157171
# clean unneeded file that causes build issues
158172
unneeded_file = common_lib_dir / 'libportmidi.dll.a'
@@ -183,7 +197,7 @@ else
183197
foreach inc_dir : bases
184198
foreach sub_inc : [
185199
'',
186-
'/SDL2',
200+
'/@0@'.format(sdl),
187201
'/freetype2',
188202
]
189203
full_inc = inc_dir / 'include' + sub_inc
@@ -204,45 +218,45 @@ else
204218
endif
205219

206220
# TODO: add version constraints?
207-
sdl_dep = dependency('sdl2', required: false)
221+
sdl_dep = dependency(sdl, required: false)
208222
if not sdl_dep.found()
209223
sdl_dep = declare_dependency(
210224
include_directories: pg_inc_dirs,
211-
dependencies: cc.find_library('SDL2', dirs: pg_lib_dirs),
225+
dependencies: cc.find_library(sdl, dirs: pg_lib_dirs),
212226
)
213227
endif
214228

215229
# optional
216-
sdl_image_dep = dependency('SDL2_image', required: false)
230+
sdl_image_dep = dependency(sdl_image, required: false)
217231
if not sdl_image_dep.found()
218232
sdl_image_dep = declare_dependency(
219233
include_directories: pg_inc_dirs,
220234
dependencies: cc.find_library(
221-
'SDL2_image',
235+
sdl_image,
222236
dirs: pg_lib_dirs,
223237
required: get_option('image'),
224238
),
225239
)
226240
endif
227241

228-
sdl_mixer_dep = dependency('SDL2_mixer', required: false)
242+
sdl_mixer_dep = dependency(sdl_mixer, required: false)
229243
if not sdl_mixer_dep.found()
230244
sdl_mixer_dep = declare_dependency(
231245
include_directories: pg_inc_dirs,
232246
dependencies: cc.find_library(
233-
'SDL2_mixer',
247+
sdl_mixer,
234248
dirs: pg_lib_dirs,
235249
required: get_option('mixer'),
236250
),
237251
)
238252
endif
239253

240-
sdl_ttf_dep = dependency('SDL2_ttf', required: false)
254+
sdl_ttf_dep = dependency(sdl_ttf, required: false)
241255
if not sdl_ttf_dep.found()
242256
sdl_ttf_dep = declare_dependency(
243257
include_directories: pg_inc_dirs,
244258
dependencies: cc.find_library(
245-
'SDL2_ttf',
259+
sdl_ttf,
246260
dirs: pg_lib_dirs,
247261
required: get_option('font'),
248262
),
@@ -296,10 +310,10 @@ pg_base_deps = [sdl_dep, py_dep]
296310

297311
summary(
298312
{
299-
'SDL2': sdl_dep.found(),
300-
'SDL2_image': sdl_image_dep.found(),
301-
'SDL2_mixer': sdl_mixer_dep.found(),
302-
'SDL2_ttf': sdl_ttf_dep.found(),
313+
sdl: sdl_dep.found(),
314+
sdl_image: sdl_image_dep.found(),
315+
sdl_mixer: sdl_mixer_dep.found(),
316+
sdl_ttf: sdl_ttf_dep.found(),
303317
'freetype2': freetype_dep.found(),
304318
'portmidi': portmidi_dep.found(),
305319
'porttime': portmidi_dep.found() ? porttime_dep.found() : false,

meson_options.txt

+3
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ option('error_docs_missing', type: 'boolean', value: 'false')
3737
# Controls whether to do a coverage build.
3838
# This argument must be used together with the editable install.
3939
option('coverage', type: 'boolean', value: false)
40+
41+
# Controls whether to use SDL3 instead of SDL2. The default is to use SDL2
42+
option('sdl_api', type: 'integer', min: 2, max: 3, value: 2)

0 commit comments

Comments
 (0)