-
Notifications
You must be signed in to change notification settings - Fork 5
/
meson.build
244 lines (223 loc) · 9.24 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Project
project('gnome-nibbles',
['c', 'vala'],
license: 'GPL3+',
meson_version: '>=1.1')
# note, the version number is in meson.options and follows this sequence:
# 4.2.rc1
# 4.2.rc2 (if needed)
# 4.2.0 (next full release)
# 4.2.1 (bugfix release)
gnome = import('gnome') # used to install help
i18n = import('i18n') # used for internationalization
prefix = get_option('prefix') # base install directory
datadir = join_paths(prefix, get_option('datadir'))
pkgdatadir = join_paths(datadir, meson.project_name())
sounddir = join_paths(pkgdatadir, 'sounds')
localedir = join_paths(prefix, get_option('localedir'))
podir = join_paths(meson.project_source_root(), 'po')
bindir = join_paths(prefix, get_option ('bindir'))
# Dependencies
vala_minimum_version = '0.55.1' # for sub-functions; https://gitlab.gnome.org/GNOME/vala/-/commit/048aaba0cd88b784fe9fa421dbad494019abd42e
glib_minimum_version = '2.66.0' # minimum version for GTK 4
glib_target_version = '2.80.0' # tested with versions 2.74 & 2.80
target_glib = '--target-glib=' + '@0@'.format(glib_target_version)
valac = meson.get_compiler('vala')
if valac.version().version_compare('< ' + vala_minimum_version)
error('Vala does not meet minimum required version of ' + vala_minimum_version)
endif
c = meson.get_compiler('c')
gee_dep = dependency('gee-0.8')
gio_dep = dependency('gio-2.0', version: '>= @0@'.format(glib_minimum_version))
glib_dep = dependency('glib-2.0', version: '>= @0@'.format(glib_minimum_version))
gsound_dep = dependency('gsound', version: '>= 1.0.2')
libgnome_games_support_dep = dependency('libgnome-games-support-2', version: '>= 2.0.0') # requires GTK 4.2
gtk_dep = dependency('gtk4') # this code works on 4.8.3 (debian 12 with updates), it hasn't been tried on anything earlier
libadwaita_dep = dependency('libadwaita-1', version: '>= 1.5.0', required : false) # requires GTK 4.13.4
pangocairo_dep = dependency('pangocairo')
gtk5_dep = dependency('gtk5', required : false)
if gtk5_dep.found()
message('GTK5 version', gtk5_dep.version() ,'is available on this system.')
endif
# Set use_libadwaita to false to stop libadwaita from being used.
use_libadwaita = libadwaita_dep.found() # = false
posix_dep = valac.find_library('posix')
# C compiler options
c_compiler_options = [
# Suppress all the C compiler warnings.
'-w',
# Define VALA_STRICT_C so we can compile with the proper C code fixes not the workaround.
# see https://gitlab.gnome.org/GNOME/vala/-/commit/ae2cbcd0011081581bef406fcbfcd1e86b7dacd3
'-DVALA_STRICT_C'
]
# convert C compiler options to vala compiler options
vala_compiler_options = []
foreach i : range(0, c_compiler_options.length(), 1)
vala_compiler_options += '--Xcc=' + c_compiler_options[i]
endforeach
vala_if_defines = []
# *** Tests ***
# For each test we add a --define= entry to vala_if_defines so the vala code
# can handle any issue or feature.
# This test is to support versions of vala(<0.56.15) that have compile issues
# with versions of gcc(>=14) or clang(>=16).
code0 = '''private const string [] strings = {"a","b"};
private static string test_string (string [] s) {return s[0];}
void main() {stdout.printf ("%s\n",test_string (strings));}'''
if meson.version().version_compare('>= 1.4.1')
# The next line exposes a bug in meson: https://github.com/mesonbuild/meson/issues/12959
code0_links = valac.links(code0,
args : vala_compiler_options,
name : 'an array of strings links without casting?')
if not code0_links
message('Vala has a bug when passing a constant array of strings to a function, workaround applied.')
vala_if_defines += '--define=VALA_NEEDS_ARRAY_STRING_CASTING'
endif
else
# we can't do the test because of the meson bug so be on the safe side
vala_if_defines += '--define=VALA_NEEDS_ARRAY_STRING_CASTING'
endif
# Test if this commit is in vala. It is in 0.56.17 and above.
# https://gitlab.gnome.org/GNOME/vala/-/commit/f3288279b6f74cd4255b52ab78dddb5ee7bcb89c
# This test is to maintain support for vala 0.56 (Stable Long-term Support release).
code1 = '''class Property : Object {public int c;}
void main () {
static bool GetMappingFunction (Value value, Variant variant, void *data) {value.set_int (0); return true;}
static Variant SetMappingFunction (Value value, VariantType type, void *data) {return 0;}
var s = new GLib.Settings ("org.gnome.Nibbles"); var p = new Property ();
s.bind_with_mapping ("c", p, "c", SettingsBindFlags.DEFAULT,GetMappingFunction, SetMappingFunction, null, null); }'''
if meson.version().version_compare('>= 1.5.0')
code1_links = valac.links(code1,
dependencies : [gio_dep], # needs meson version >= 1.5.0
args : vala_compiler_options,
name : 'static local functions can be used without casting?')
if not code1_links
message('Vala static local functions need casting to static delegates.')
vala_if_defines += '--define=VALA_NEEDS_LOCAL_FUCTION_TO_STATIC_DELEGATE_CASTING'
endif
else
# we can't do the test because of the meson bug so be on the safe side
vala_if_defines += '--define=VALA_NEEDS_LOCAL_FUCTION_TO_STATIC_DELEGATE_CASTING'
endif
# Test compiling & linking with Adw.AboutDialog.
# This test makes sure libadwaita is installed and working.
if use_libadwaita
code2 = '''void main () {string[] s = {"a", "b"};
var ad = new Adw.AboutDialog ();
ad.set_developers (s);
ad.set_documenters (s);
ad.set_artists (s);}'''
if meson.version().version_compare('>= 1.5.0')
code2_links = valac.links(code2,
dependencies : [libadwaita_dep], # needs meson version >= 1.5.0
args : vala_compiler_options,
name : 'we can link with libadwaita?')
if code2_links
vala_if_defines += ['--define=USE_LIBADWAITA','--define=USE_PILL_BUTTON']
else
message('Can not link with libadwaita.')
endif
endif
endif
# Test for ApplicationFlags.DEFAULT_FLAGS
code3 = '''using Gtk;
void main () {var t=ApplicationFlags.DEFAULT_FLAGS;}'''
if meson.version().version_compare('>= 1.5.0')
code3_links = valac.links(code3,
dependencies : [gtk_dep], # needs meson version >= 1.5.0
args : vala_compiler_options,
name : 'Is ApplicationFlags.DEFAULT_FLAGS defined?')
if code3_links
vala_if_defines += '--define=CAN_USE_DEFAULT_FLAGS'
else
message('We will use ApplicationFlags.FLAGS_NONE.')
endif
else
# we can't do the test because of the meson bug so be on the safe side
message('We will use ApplicationFlags.FLAGS_NONE.')
endif
# Test for show_uri function
# We use show_uri in preference to UriLauncher because of
# https://gitlab.gnome.org/GNOME/gtk/-/issues/6135
code4 = '''using Gtk;
void main () {show_uri (null, "help:gnome-nibbles", Gdk.CURRENT_TIME);}'''
if meson.version().version_compare('>= 1.5.0')
code4_links = valac.links(code4,
dependencies : [gtk_dep], # needs meson version >= 1.5.0
args : vala_compiler_options,
name : 'we can call show_uri?')
if code4_links
vala_if_defines += '--define=CAN_USE_SHOW_URI'
else
message('We will use UriLauncher instead of show_uri.')
endif
else
# we can't do the test because of the meson bug so be on the safe side
vala_if_defines += '--define=CAN_USE_SHOW_URI'
endif
# Test for 128 bit integer (__int128)
# If available __int128 allows us to do better nibbles tests.
code5 = '''
typedef unsigned long long uint64;
struct _int128
{
uint64 hi;
uint64 lo;
int negative;
uint64 remainder;
};
void divide_by(struct _int128 *i128, long long i64, struct _int128 *r)
{
unsigned __int128 n,a;
n = ((__int128)i128->hi) << 64 | i128->lo;
if(i64 < 0)
{
a = n / -(__int128)i64;
r->remainder = n % -(__int128)i64;
}
else
{
a = n / i64;
r->remainder = n % i64;
}
r->hi = a >> 64;
r->lo = (uint64)a;
r->negative = (i128->negative && i64 > 0) || (!i128->negative && i64 < 0);
//return r;
}'''
code5_compiles = c.compiles(code5,
args : c_compiler_options,
name : 'we can use 128 bit integers?')
if code5_compiles
vala_if_defines += '--define=CAN_USE__INT128'
conditional_sources = ['divide_by.c']
else
conditional_sources = []
endif
message('valac #defines:',vala_if_defines)
# Configuration
conf = configuration_data()
conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())
conf.set_quoted('PKGDATADIR', pkgdatadir)
conf.set_quoted('SOUND_DIRECTORY', sounddir)
conf.set_quoted('LOCALEDIR', join_paths(prefix, localedir))
conf.set_quoted('VERSION', get_option('version') + get_option('append_to_version'))
conf.set_quoted('WEBSITE', get_option('website'))
configure_file(output: 'config.h', configuration: conf)
config_h_dir = include_directories('.')
add_project_arguments([
'-include', 'config.h'
],
language: 'c'
)
# Postinstall
gnome.post_install(
glib_compile_schemas: true,
gtk_update_icon_cache: true,
update_desktop_database: true,
)
# Subdirs
subdir('data')
subdir('help')
subdir('po')
subdir('src')