a6e12737b9b2e6155f09ef963fa889ed522ecf8b
[platform/upstream/mesa.git] / src / util / meson.build
1 # Copyright © 2017 Intel Corporation
2
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20
21 inc_util = include_directories('.')
22
23 subdir('format')
24
25 files_mesa_util = files(
26   'anon_file.h',
27   'anon_file.c',
28   'bigmath.h',
29   'bitscan.c',
30   'bitscan.h',
31   'bitset.h',
32   'blob.c',
33   'blob.h',
34   'build_id.c',
35   'build_id.h',
36   'cnd_monotonic.h',
37   'compiler.h',
38   'compress.c',
39   'compress.h',
40   'crc32.c',
41   'crc32.h',
42   'dag.c',
43   'disk_cache.c',
44   'disk_cache.h',
45   'disk_cache_os.c',
46   'disk_cache_os.h',
47   'double.c',
48   'double.h',
49   'enum_operators.h',
50   'fast_idiv_by_const.c',
51   'fast_idiv_by_const.h',
52   'format_r11g11b10f.h',
53   'format_rgb9e5.h',
54   'format_srgb.h',
55   'fossilize_db.c',
56   'fossilize_db.h',
57   'futex.c',
58   'futex.h',
59   'half_float.c',
60   'half_float.h',
61   'hash_table.c',
62   'hash_table.h',
63   'u_idalloc.c',
64   'u_idalloc.h',
65   'list.h',
66   'log.c',
67   'macros.h',
68   'memstream.c',
69   'memstream.h',
70   'mesa-sha1.c',
71   'mesa-sha1.h',
72   'os_time.c',
73   'os_time.h',
74   'os_file.c',
75   'os_memory_fd.c',
76   'os_misc.c',
77   'os_misc.h',
78   'os_socket.c',
79   'os_socket.h',
80   'ptralloc.h',
81   'perf/u_trace.h',
82   'perf/u_trace.c',
83   'perf/u_trace_priv.h',
84   'u_process.c',
85   'u_process.h',
86   'u_qsort.cpp',
87   'u_qsort.h',
88   'rwlock.c',
89   'rwlock.h',
90   'sha1/sha1.c',
91   'sha1/sha1.h',
92   'ralloc.c',
93   'ralloc.h',
94   'rand_xor.c',
95   'rand_xor.h',
96   'rb_tree.c',
97   'rb_tree.h',
98   'register_allocate.c',
99   'register_allocate.h',
100   'rgtc.c',
101   'rgtc.h',
102   'rounding.h',
103   'set.c',
104   'set.h',
105   'simple_mtx.c',
106   'simple_mtx.h',
107   'slab.c',
108   'slab.h',
109   'softfloat.c',
110   'softfloat.h',
111   'sparse_array.c',
112   'sparse_array.h',
113   'string_buffer.c',
114   'string_buffer.h',
115   'strndup.h',
116   'strtod.c',
117   'strtod.h',
118   'texcompress_rgtc_tmp.h',
119   'timespec.h',
120   'u_atomic.c',
121   'u_atomic.h',
122   'u_call_once.c',
123   'u_call_once.h',
124   'u_debug_describe.c',
125   'u_debug_describe.h',
126   'u_debug_refcnt.c',
127   'u_debug_refcnt.h',
128   'u_dl.c',
129   'u_dl.h',
130   'u_dynarray.h',
131   'u_endian.h',
132   'u_fifo.h',
133   'u_hash_table.c',
134   'u_hash_table.h',
135   'u_pointer.h',
136   'u_queue.c',
137   'u_queue.h',
138   'u_string.h',
139   'u_thread.c',
140   'u_thread.h',
141   'u_vector.c',
142   'u_vector.h',
143   'u_math.c',
144   'u_math.h',
145   'u_memset.h',
146   'u_mm.c',
147   'u_mm.h',
148   'u_debug.c',
149   'u_debug.h',
150   'u_debug_memory.c',
151   'u_cpu_detect.c',
152   'u_cpu_detect.h',
153   'u_printf.c',
154   'u_printf.h',
155   'u_worklist.c',
156   'u_worklist.h',
157   'vl_vlc.h',
158   'vl_rbsp.h',
159   'vma.c',
160   'vma.h',
161   'xxhash.h',
162   'indices/u_indices.h',
163   'indices/u_indices_priv.h',
164   'indices/u_primconvert.c',
165   'indices/u_primconvert.h',
166   'mesa_cache_db.c',
167   'mesa_cache_db.h',
168 )
169
170 files_drirc = files('00-mesa-defaults.conf')
171
172 install_data(files_drirc, install_dir : join_paths(get_option('datadir'), 'drirc.d'))
173
174 if with_tests
175   prog_xmllint = find_program('xmllint', required : false, native : true)
176   if prog_xmllint.found()
177     test(
178       'drirc xml validation',
179       prog_xmllint,
180       args : ['--noout', '--valid', files_drirc],
181       suite : ['util'],
182     )
183   endif
184 endif
185
186 files_xmlconfig = files(
187   'xmlconfig.c',
188   'xmlconfig.h',
189 )
190
191 files_xmlconfig += custom_target(
192   'driconf_static.h',
193   input: ['driconf_static.py', '00-mesa-defaults.conf'],
194   output: 'driconf_static.h',
195   command: [
196     prog_python, '@INPUT0@', '@INPUT1@', '@OUTPUT@'
197   ],
198 )
199
200 format_srgb = custom_target(
201   'format_srgb',
202   input : ['format_srgb.py'],
203   output : 'format_srgb.c',
204   command : [prog_python, '@INPUT0@'],
205   capture : true,
206 )
207
208 deps_for_libmesa_util = [
209   dep_zlib,
210   dep_clock,
211   dep_thread,
212   dep_atomic,
213   dep_m,
214   dep_valgrind,
215   dep_zstd,
216   dep_dl,
217   dep_unwind,
218   dep_futex,
219   idep_mesautilc11
220 ]
221
222 if with_platform_android
223   deps_for_libmesa_util += dep_android
224   files_debug_stack = files('u_debug_stack_android.cpp')
225  else
226   files_debug_stack = files(
227     'u_debug_stack.c',
228     'u_debug_symbol.c',
229     'u_debug_symbol.h',
230   )
231 endif
232
233 if with_platform_haiku
234   deps_for_libmesa_util += dep_network
235 endif
236
237 if with_perfetto
238   files_mesa_util += files(
239     'perf/u_perfetto.cc',
240     'perf/u_perfetto.h',
241   )
242   deps_for_libmesa_util += dep_perfetto
243 endif
244
245 u_trace_py = files('perf/u_trace.py')
246
247 u_indices_gen_c = custom_target(
248   'u_indices_gen.c',
249   input : 'indices/u_indices_gen.py',
250   output : 'u_indices_gen.c',
251   command : [prog_python, '@INPUT@', '@OUTPUT@'],
252 )
253
254 u_unfilled_gen_c = custom_target(
255   'u_unfilled_gen.c',
256   input : 'indices/u_unfilled_gen.py',
257   output : 'u_unfilled_gen.c',
258   command : [prog_python, '@INPUT@', '@OUTPUT@'],
259 )
260
261 libmesa_util_sse41 = static_library(
262                 'mesa_util_sse41',
263                 files('streaming-load-memcpy.c'),
264                 c_args : [c_msvc_compat_args, sse41_args],
265                 include_directories : [inc_include, inc_src, inc_mesa],
266                 gnu_symbol_visibility : 'hidden',
267 )
268
269 _libmesa_util = static_library(
270   'mesa_util',
271   [files_mesa_util, files_debug_stack, format_srgb, u_indices_gen_c, u_unfilled_gen_c],
272   include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
273   dependencies : deps_for_libmesa_util,
274   link_with: [libmesa_format, libmesa_util_sse41],
275   c_args : [c_msvc_compat_args],
276   gnu_symbol_visibility : 'hidden',
277   build_by_default : false
278 )
279
280 idep_mesautil = declare_dependency(
281   link_with : _libmesa_util,
282   include_directories : [inc_util, inc_gallium],
283   dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic, dep_m, dep_valgrind, dep_futex],
284 )
285
286 xmlconfig_deps = []
287 if not (with_platform_android or with_platform_windows)
288   xmlconfig_deps += dep_expat
289 endif
290 xmlconfig_deps += dep_regex
291
292 _libxmlconfig = static_library(
293   'xmlconfig',
294   files_xmlconfig,
295   include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
296   dependencies : [idep_mesautil, dep_m, xmlconfig_deps],
297   c_args : [
298     c_msvc_compat_args,
299     '-DSYSCONFDIR="@0@"'.format(
300       join_paths(get_option('prefix'), get_option('sysconfdir'))
301     ),
302     '-DDATADIR="@0@"'.format(
303       join_paths(get_option('prefix'), get_option('datadir'))
304     ),
305   ],
306   gnu_symbol_visibility : 'hidden',
307   build_by_default : false,
308 )
309
310 idep_xmlconfig = declare_dependency(
311   dependencies : xmlconfig_deps,
312   link_with : _libxmlconfig,
313 )
314
315 files_xxd = files('xxd.py')
316 glsl2spirv = files('glsl2spirv.py')
317
318 if with_tests
319   # DRI_CONF macros use designated initializers (required for union
320   # initializaiton), so we need c++2a since gtest forces us to use c++
321   if host_machine.system() != 'windows' and cpp.has_argument('-std=c++2a')
322     test('xmlconfig',
323       executable('xmlconfig_test',
324         files('tests/xmlconfig.cpp'),
325         include_directories : [inc_include, inc_src],
326         dependencies : [idep_mesautil, idep_xmlconfig, idep_gtest],
327         override_options : ['cpp_std=c++2a'],
328         cpp_args: ['-Wno-write-strings']
329       ),
330       suite : ['util'],
331       env: ['HOME=' + join_paths(meson.current_source_dir(),
332                                  'tests', 'drirc_home'),
333             'DRIRC_CONFIGDIR=' + join_paths(meson.current_source_dir(),
334                                             'tests', 'drirc_configdir')],
335       protocol : gtest_test_protocol,
336     )
337   endif
338
339   files_util_tests = files(
340     'tests/bitset_test.cpp',
341     'tests/blob_test.cpp',
342     'tests/dag_test.cpp',
343     'tests/fast_idiv_by_const_test.cpp',
344     'tests/fast_urem_by_const_test.cpp',
345     'tests/half_float_test.cpp',
346     'tests/int_min_max.cpp',
347     'tests/mesa-sha1_test.cpp',
348     'tests/rb_tree_test.cpp',
349     'tests/register_allocate_test.cpp',
350     'tests/roundeven_test.cpp',
351     'tests/set_test.cpp',
352     'tests/string_buffer_test.cpp',
353     'tests/timespec_test.cpp',
354     'tests/u_atomic_test.cpp',
355     'tests/u_call_once_test.cpp',
356     'tests/u_debug_stack_test.cpp',
357     'tests/u_debug_test.cpp',
358     'tests/u_printf_test.cpp',
359     'tests/u_qsort_test.cpp',
360     'tests/vector_test.cpp',
361   )
362
363   # FIXME: this test cause a big timeout on MacOS
364   if host_machine.system() != 'darwin'
365     files_util_tests += files(
366       'tests/sparse_array_test.cpp',
367     )
368   endif
369
370   if with_shader_cache
371     files_util_tests += files(
372       'tests/cache_test.cpp',
373     )
374   endif
375
376   test(
377     'util_tests',
378     executable(
379       'util_tests',
380       files_util_tests,
381       include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
382       dependencies : [idep_mesautil, idep_gtest],
383     ),
384     suite : ['util'],
385     protocol : gtest_test_protocol,
386     timeout : 180,
387   )
388
389   process_test_exe = executable(
390     'process_test',
391     files('tests/process_test.c'),
392     include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
393     dependencies : idep_mesautil,
394     c_args : [c_msvc_compat_args],
395   )
396   if (host_machine.system() == 'windows' and build_machine.system() != 'windows')
397     # This conversion is only required on mingw crosscompilers, otherwise we hit at least one of these issues
398     # https://gitlab.freedesktop.org/mesa/mesa/-/issues/2690
399     # https://gitlab.freedesktop.org/mesa/mesa/-/issues/2788
400     prog_winepath = find_program('winepath')
401     process_test_exe_full_path = run_command(
402       prog_winepath, '-w', process_test_exe.full_path(),
403       check : true
404     ).stdout().strip()
405   else
406     process_test_exe_full_path = process_test_exe.full_path()
407   endif
408
409   test(
410     'process',
411     process_test_exe,
412     suite : ['util'],
413     env: ['BUILD_FULL_PATH='+process_test_exe_full_path]
414   )
415
416   subdir('tests/hash_table')
417   subdir('tests/vma')
418   subdir('tests/format')
419 endif