Debian Codegraph @

meson.build

raw
1 project('libdex', 'c',
2 version: '1.2.beta',
3 meson_version: '>= 1.0.0',
4 default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu11', ],
5 )
6
7 api_version = '1'
8
9 cc = meson.get_compiler('c')
10 gnome = import('gnome')
11 pkg = import('pkgconfig')
12
13 config_h = configuration_data()
14 config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
15
16 prefix = get_option('prefix')
17 datadir = join_paths(prefix, get_option('datadir'))
18 libdir = join_paths(prefix, get_option('libdir'))
19 girdir = join_paths(datadir, 'gir-1.0')
20 vapidir = join_paths(datadir, 'vala', 'vapi')
21 typelibdir = join_paths(libdir, 'girepository-1.0')
22
23 package_name = meson.project_name()
24 package_string = '@0@-@1@'.format(package_name, api_version)
25
26 glib_req_version = '2.87'
27 glib_req = '>= @0@'.format(glib_req_version)
28
29 if host_machine.system() == 'windows'
30 glib_dep = dependency('gio-2.0', version: glib_req)
31 else
32 glib_dep = dependency('gio-unix-2.0', version: glib_req)
33 endif
34
35 have_gdbus_codegen = get_option('gdbus').enabled()
36
37 if host_machine.system() == 'linux' and not get_option('liburing').disabled()
38 liburing_req_version = '0.7'
39 liburing_req = '>= @0@'.format(liburing_req_version)
40 liburing_dep = dependency('liburing', version: liburing_req, required: get_option('liburing').enabled())
41
42 if liburing_dep.found()
43 config_h.set10('HAVE_LIBURING', true)
44 endif
45 else
46 liburing_dep = disabler()
47 endif
48
49 if get_option('sysprof')
50 libsysprof_capture_dep = dependency('sysprof-capture-4')
51 config_h.set10('HAVE_SYSPROF', true)
52 endif
53
54 if cc.has_header('ucontext.h')
55 if not cc.has_function('makecontext', prefix : '#include <ucontext.h>')
56 libucontext_dep = dependency('libucontext', required: false)
57 else
58 libucontext_dep = disabler()
59 endif
60 config_h.set('HAVE_UCONTEXT_H', 1)
61 endif
62
63 if host_machine.system() == 'darwin'
64 # known alignment for darwin where we're using helpers
65 if host_machine.cpu_family() == 'aarch64'
66 config_h.set('ALIGN_OF_UCONTEXT', 16)
67 else
68 config_h.set('ALIGN_OF_UCONTEXT', 8)
69 endif
70 elif host_machine.system() == 'openbsd'
71 config_h.set('ALIGN_OF_UCONTEXT', 8)
72 elif host_machine.system() == 'windows'
73 # Unset
74 else
75 # Check alignment of ucontext_t
76 config_h.set('ALIGN_OF_UCONTEXT', cc.alignment('ucontext_t', prefix: '#include <ucontext.h>'))
77 endif
78
79 project_c_args = []
80 test_c_args = [
81 '-Watomic-alignment',
82 '-Wcast-align',
83 '-Wdeclaration-after-statement',
84 '-Werror=address',
85 '-Werror=array-bounds',
86 '-Werror=empty-body',
87 '-Werror=implicit',
88 '-Werror=implicit-function-declaration',
89 '-Werror=incompatible-pointer-types',
90 '-Werror=init-self',
91 '-Werror=int-conversion',
92 '-Werror=int-to-pointer-cast',
93 '-Werror=main',
94 '-Werror=misleading-indentation',
95 '-Werror=missing-braces',
96 '-Werror=missing-include-dirs',
97 '-Werror=nonnull',
98 '-Werror=overflow',
99 '-Werror=parenthesis',
100 '-Werror=pointer-arith',
101 '-Werror=pointer-to-int-cast',
102 '-Werror=redundant-decls',
103 '-Werror=return-type',
104 '-Werror=sequence-point',
105 '-Werror=shadow',
106 '-Werror=strict-prototypes',
107 '-Werror=trigraphs',
108 '-Werror=undef',
109 '-Werror=write-strings',
110 '-Wformat-nonliteral',
111 '-Wignored-qualifiers',
112 '-Wimplicit-function-declaration',
113 '-Wlogical-op',
114 '-Wmissing-declarations',
115 '-Wmissing-format-attribute',
116 '-Wmissing-include-dirs',
117 '-Wmissing-noreturn',
118 '-Wnested-externs',
119 '-Wno-cast-function-type',
120 '-Wno-dangling-pointer',
121 '-Wno-missing-field-initializers',
122 '-Wno-sign-compare',
123 '-Wno-unused-parameter',
124 '-Wold-style-definition',
125 '-Wpointer-arith',
126 '-Wredundant-decls',
127 '-Wstrict-prototypes',
128 '-Wswitch-default',
129 '-Wswitch-enum',
130 '-Wtrampolines',
131 '-Wundef',
132 '-Wuninitialized',
133 '-Wunused',
134 '-fstrict-flex-arrays=3',
135 '-fno-strict-aliasing',
136 ['-Werror=format-security', '-Werror=format=2'],
137 '-FImsvc_recommended_pragmas.h',
138 ]
139 if get_option('buildtype') != 'plain' and get_option('stack-protector')
140 if host_machine.system() != 'windows'
141 test_c_args += '-fstack-protector-strong'
142 endif
143 endif
144
145 # Currently required for Visual Studio builds (VS2022 and 2026), for C11 _Atomic
146 if cc.get_id() == 'msvc'
147 test_c_args += '-experimental:c11atomics'
148 endif
149 foreach arg: test_c_args
150 if cc.has_multi_arguments(arg)
151 project_c_args += arg
152 endif
153 endforeach
154 add_project_arguments(project_c_args, language: 'c')
155
156 # Detect and set symbol visibility
157 if get_option('default_library') != 'static'
158 if host_machine.system() == 'windows'
159 config_h.set('DLL_EXPORT', true)
160 if cc.get_id() == 'msvc'
161 config_h.set('_DEX_EXTERN', '__declspec(dllexport) extern')
162 elif cc.has_argument('-fvisibility=hidden')
163 config_h.set('_DEX_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
164 endif
165 elif cc.has_argument('-fvisibility=hidden')
166 config_h.set('_DEX_EXTERN', '__attribute__((visibility("default"))) extern')
167 endif
168 endif
169
170 release_args = []
171 global_link_args = []
172 test_link_args = [
173 '-Wl,-z,relro',
174 '-Wl,-z,now',
175 '-Wl,-z,noexecstack',
176 ]
177 if not get_option('buildtype').startswith('debug')
178 release_args += [
179 '-DG_DISABLE_CAST_CHECKS',
180 '-DG_DISABLE_ASSERT',
181 ]
182 test_link_args += [
183 '-Wl,-Bsymbolic',
184 '-fno-plt',
185 ]
186 endif
187 foreach link_arg: test_link_args
188 if cc.has_link_argument(link_arg)
189 global_link_args += link_arg
190 endif
191 endforeach
192 add_project_link_arguments(global_link_args, language: 'c')
193
194 glib_major_version = glib_req_version.split('.')[0].to_int()
195 glib_minor_version = glib_req_version.split('.')[1].to_int()
196 if glib_minor_version % 2 == 1
197 glib_minor_version = glib_minor_version + 1
198 endif
199 deprecated_c_args = [
200 '-DG_DISABLE_DEPRECATED',
201 '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_@0@_@1@'.format(glib_major_version, glib_minor_version),
202 ]
203
204 add_project_arguments('-I' + meson.project_build_root(), language: 'c')
205
206 functions = [
207 'posix_fadvise',
208 'madvise',
209 'mprotect',
210 ]
211
212 headers = [
213 'unistd.h',
214 ]
215
216 if not get_option('eventfd').disabled()
217 functions += ['eventfd']
218 endif
219
220 foreach f : functions
221 if cc.has_function(f)
222 define = 'HAVE_' + f.underscorify().to_upper()
223 config_h.set10(define, true)
224 endif
225 endforeach
226
227 foreach h : headers
228 if cc.has_header(h)
229 define = 'HAVE_' + h.underscorify().to_upper()
230 config_h.set10(define, true)
231 endif
232 endforeach
233
234 if get_option('eventfd').enabled() and config_h.get('HAVE_EVENTFD') == 0
235 error('eventfd function is required for -Deventfd=enabled')
236 endif
237
238 configure_file(output: 'config.h', configuration: config_h)
239
240 subdir('src')
241 if get_option('tests')
242 subdir('testsuite')
243 endif
244 # Don't build the examples for now on Visual Studio, due to g_autofoo
245 if get_option('examples') and cc.get_id() != 'msvc'
246 subdir('examples')
247 endif
248 if get_option('docs')
249 subdir('docs')
250 endif