-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
190 lines (165 loc) · 4.79 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
project(
'itz_particle_manager',
'c',
version : '0.1',
default_options : [
'optimization=3',
],
)
# This code was copied from the meson.build file of the Pygame project, I do not own this code.
itz_pm = 'itz_particle_manager' # This is the name of the module
if host_machine.system() == 'windows'
plat = 'win'
elif host_machine.system() == 'darwin'
plat = 'mac'
elif host_machine.system() == 'linux'
plat = 'linux'
elif host_machine.system() == 'android'
plat = 'android'
error(
'The meson buildconfig of itz_particle_manager does not support android for now.',
'However it may be added in the future',
)
elif host_machine.system() == 'emscripten'
plat = 'emscripten'
error(
'The meson buildconfig of itz_particle_manager does not support emscripten for now. ',
'However it may be added in the future',
)
else
# here it one of: cygwin, dragonfly, freebsd, gnu, haiku, netbsd, openbsd, sunos
plat = 'unix'
warning(
'itz_particle_manager does not actively support building on your platform:',
host_machine.system(),
)
endif
cc = meson.get_compiler('c')
fs = import('fs')
py = import('python').find_installation(pure : false)
py_dep = py.dependency(required : true)
if not cc.has_header('Python.h', dependencies : py_dep)
error(
'Cannot use `Python.h`. Perhaps you need to install python-dev|python-devel',
)
endif
curr_dir = py.get_install_dir()
include_dirs = []
lib_dirs = []
if plat == 'win' and host_machine.cpu_family().startswith('x86')
arch_suffix = 'x' + host_machine.cpu_family().substring(-2)
base_dir = meson.current_source_dir()
prebuilt_dir = base_dir / 'prebuilt-' + arch_suffix
# download prebuilts (uses legacy builconfig code)
if not fs.is_dir(prebuilt_dir)
run_command(
[
find_program('python3', 'python'),
'download_win_prebuilt.py',
],
check : true,
)
endif
sdl_ver = '2.30.9'
dlls = []
# SDL2
sdl_dir = prebuilt_dir / 'SDL2-@0@'.format(sdl_ver)
sdl_lib_dir = sdl_dir / 'lib' / arch_suffix
include_dirs += fs.relative_to(sdl_dir / 'include', base_dir)
lib_dirs += sdl_lib_dir
dlls += sdl_lib_dir / 'SDL2.dll'
# put dlls in root of install
install_data(dlls, install_dir : curr_dir)
else
bases = ['/usr/local', '/usr', '/opt/homebrew', '/opt/local']
foreach inc_dir : bases
foreach sub_inc : [
'',
'/SDL2',
]
full_inc = inc_dir / 'include' + sub_inc
if fs.exists(full_inc)
include_dirs += full_inc
endif
endforeach
endforeach
foreach lib_dir : bases
foreach sub_lib : ['lib', 'lib64']
full_lib = lib_dir / sub_lib
if fs.exists(full_lib)
lib_dirs += full_lib
endif
endforeach
endforeach
endif
sdl_dep = dependency('sdl2', required : false)
if not sdl_dep.found()
sdl_dep = declare_dependency(
include_directories : include_dirs,
dependencies : cc.find_library('SDL2', dirs : lib_dirs),
)
endif
itzpm_base_deps = [sdl_dep, py_dep]
summary(
{
'SDL2' : sdl_dep.found(),
},
section : 'Dependencies',
)
simd_avx2 = false
simd_avx2_flags = []
if host_machine.cpu_family().startswith('x86')
flag = (cc.get_argument_syntax() == 'msvc') ? '/arch:AVX2' : '-mavx2'
if cc.has_argument(flag)
simd_avx2_flags += flag
simd_avx2 = true
endif
endif
# add msvc /GL flag
if cc.get_argument_syntax() == 'msvc'
add_global_arguments('/fp:fast', language : 'c')
endif
simd_sse2_neon = false
simd_sse2_neon_flags = []
if host_machine.cpu_family() == 'arm'
# first check if compiler supports the flag, and use it then. Needed only
# on 32-bit armv7.
flag = '-mfpu=neon'
if cc.has_argument(flag) and host_machine.cpu() == 'armv7l'
simd_sse2_neon_flags += [flag, '-march=armv7-a']
simd_sse2_neon = true
endif
elif host_machine.cpu_family() == 'aarch64'
# no explicit flag needed in this case
simd_sse2_neon = true
endif
if simd_sse2_neon
add_global_arguments('-DENABLE_ARM_NEON=1', language: 'c')
endif
summary(
{
'AVX2': simd_avx2,
'NEON': simd_sse2_neon,
},
section: 'SIMD',
)
# List of source files
src_files = [
'src/module.c',
'src/updaters_simd_avx2.c',
'src/updaters_simd_sse2.c',
'src/data_block.c',
'src/effect_instance.c',
'src/float_array.c',
'src/particle_manager.c',
'src/emitter.c',
'src/particle_effect.c',
]
py.extension_module(
itz_pm,
src_files,
dependencies : itzpm_base_deps,
include_directories : include_dirs,
c_args : simd_avx2_flags + simd_sse2_neon_flags,
install : true,
)