101e04c3fSmrg# Copyright © 2017 Intel Corporation
201e04c3fSmrg
301e04c3fSmrg# Permission is hereby granted, free of charge, to any person obtaining a copy
401e04c3fSmrg# of this software and associated documentation files (the "Software"), to deal
501e04c3fSmrg# in the Software without restriction, including without limitation the rights
601e04c3fSmrg# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
701e04c3fSmrg# copies of the Software, and to permit persons to whom the Software is
801e04c3fSmrg# furnished to do so, subject to the following conditions:
901e04c3fSmrg
1001e04c3fSmrg# The above copyright notice and this permission notice shall be included in
1101e04c3fSmrg# all copies or substantial portions of the Software.
1201e04c3fSmrg
1301e04c3fSmrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1401e04c3fSmrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1501e04c3fSmrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1601e04c3fSmrg# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1701e04c3fSmrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1801e04c3fSmrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1901e04c3fSmrg# SOFTWARE.
2001e04c3fSmrg
2101e04c3fSmrginc_util = include_directories('.')
2201e04c3fSmrg
237ec681f3Smrgsubdir('format')
2401e04c3fSmrg
2501e04c3fSmrgfiles_mesa_util = files(
267ec681f3Smrg  'anon_file.h',
277ec681f3Smrg  'anon_file.c',
2801e04c3fSmrg  'bigmath.h',
2901e04c3fSmrg  'bitscan.c',
3001e04c3fSmrg  'bitscan.h',
3101e04c3fSmrg  'bitset.h',
327ec681f3Smrg  'blob.c',
337ec681f3Smrg  'blob.h',
3401e04c3fSmrg  'build_id.c',
3501e04c3fSmrg  'build_id.h',
367ec681f3Smrg  'cnd_monotonic.h',
377ec681f3Smrg  'compiler.h',
387ec681f3Smrg  'compress.c',
397ec681f3Smrg  'compress.h',
4001e04c3fSmrg  'crc32.c',
4101e04c3fSmrg  'crc32.h',
428a1362adSmaya  'dag.c',
4301e04c3fSmrg  'debug.c',
4401e04c3fSmrg  'debug.h',
4501e04c3fSmrg  'disk_cache.c',
4601e04c3fSmrg  'disk_cache.h',
477ec681f3Smrg  'disk_cache_os.c',
487ec681f3Smrg  'disk_cache_os.h',
497ec681f3Smrg  'double.c',
507ec681f3Smrg  'double.h',
517ec681f3Smrg  'enum_operators.h',
5201e04c3fSmrg  'fast_idiv_by_const.c',
5301e04c3fSmrg  'fast_idiv_by_const.h',
5401e04c3fSmrg  'format_r11g11b10f.h',
5501e04c3fSmrg  'format_rgb9e5.h',
5601e04c3fSmrg  'format_srgb.h',
577ec681f3Smrg  'fossilize_db.c',
587ec681f3Smrg  'fossilize_db.h',
5901e04c3fSmrg  'futex.h',
6001e04c3fSmrg  'half_float.c',
6101e04c3fSmrg  'half_float.h',
6201e04c3fSmrg  'hash_table.c',
6301e04c3fSmrg  'hash_table.h',
647ec681f3Smrg  'u_idalloc.c',
657ec681f3Smrg  'u_idalloc.h',
6601e04c3fSmrg  'list.h',
677ec681f3Smrg  'log.c',
6801e04c3fSmrg  'macros.h',
697ec681f3Smrg  'memstream.c',
707ec681f3Smrg  'memstream.h',
7101e04c3fSmrg  'mesa-sha1.c',
7201e04c3fSmrg  'mesa-sha1.h',
7301e04c3fSmrg  'os_time.c',
7401e04c3fSmrg  'os_time.h',
758a1362adSmaya  'os_file.c',
767ec681f3Smrg  'os_memory_fd.c',
7701e04c3fSmrg  'os_misc.c',
7801e04c3fSmrg  'os_misc.h',
797ec681f3Smrg  'os_socket.c',
807ec681f3Smrg  'os_socket.h',
817ec681f3Smrg  'perf/u_trace.h',
827ec681f3Smrg  'perf/u_trace.c',
837ec681f3Smrg  'perf/u_trace_priv.h',
8401e04c3fSmrg  'u_process.c',
8501e04c3fSmrg  'u_process.h',
867ec681f3Smrg  'u_qsort.cpp',
877ec681f3Smrg  'u_qsort.h',
887ec681f3Smrg  'rwlock.h',
8901e04c3fSmrg  'sha1/sha1.c',
9001e04c3fSmrg  'sha1/sha1.h',
9101e04c3fSmrg  'ralloc.c',
9201e04c3fSmrg  'ralloc.h',
9301e04c3fSmrg  'rand_xor.c',
9401e04c3fSmrg  'rand_xor.h',
9501e04c3fSmrg  'rb_tree.c',
9601e04c3fSmrg  'rb_tree.h',
9701e04c3fSmrg  'register_allocate.c',
9801e04c3fSmrg  'register_allocate.h',
9901e04c3fSmrg  'rgtc.c',
10001e04c3fSmrg  'rgtc.h',
10101e04c3fSmrg  'rounding.h',
10201e04c3fSmrg  'set.c',
10301e04c3fSmrg  'set.h',
10401e04c3fSmrg  'simple_list.h',
10501e04c3fSmrg  'simple_mtx.h',
10601e04c3fSmrg  'slab.c',
10701e04c3fSmrg  'slab.h',
1087ec681f3Smrg  'softfloat.c',
1097ec681f3Smrg  'softfloat.h',
1107ec681f3Smrg  'sparse_array.c',
1117ec681f3Smrg  'sparse_array.h',
11201e04c3fSmrg  'string_buffer.c',
11301e04c3fSmrg  'string_buffer.h',
11401e04c3fSmrg  'strndup.h',
11501e04c3fSmrg  'strtod.c',
11601e04c3fSmrg  'strtod.h',
11701e04c3fSmrg  'texcompress_rgtc_tmp.h',
1187ec681f3Smrg  'timespec.h',
11901e04c3fSmrg  'u_atomic.c',
12001e04c3fSmrg  'u_atomic.h',
1217ec681f3Smrg  'u_debug_describe.c',
1227ec681f3Smrg  'u_debug_describe.h',
1237ec681f3Smrg  'u_debug_refcnt.c',
1247ec681f3Smrg  'u_debug_refcnt.h',
12501e04c3fSmrg  'u_dynarray.h',
12601e04c3fSmrg  'u_endian.h',
1277ec681f3Smrg  'u_fifo.h',
1287ec681f3Smrg  'u_hash_table.c',
1297ec681f3Smrg  'u_hash_table.h',
13001e04c3fSmrg  'u_queue.c',
13101e04c3fSmrg  'u_queue.h',
13201e04c3fSmrg  'u_string.h',
13301e04c3fSmrg  'u_thread.h',
13401e04c3fSmrg  'u_vector.c',
13501e04c3fSmrg  'u_vector.h',
13601e04c3fSmrg  'u_math.c',
13701e04c3fSmrg  'u_math.h',
1387ec681f3Smrg  'u_memset.h',
1397ec681f3Smrg  'u_mm.c',
1407ec681f3Smrg  'u_mm.h',
14101e04c3fSmrg  'u_debug.c',
14201e04c3fSmrg  'u_debug.h',
1437ec681f3Smrg  'u_debug_memory.c',
14401e04c3fSmrg  'u_cpu_detect.c',
14501e04c3fSmrg  'u_cpu_detect.h',
1467ec681f3Smrg  'u_printf.cpp',
1477ec681f3Smrg  'u_printf.h',
14801e04c3fSmrg  'vma.c',
14901e04c3fSmrg  'vma.h',
1507ec681f3Smrg  'xxhash.h',
15101e04c3fSmrg)
15201e04c3fSmrg
1538a1362adSmayafiles_drirc = files('00-mesa-defaults.conf')
1548a1362adSmaya
1558a1362adSmayainstall_data(files_drirc, install_dir : join_paths(get_option('datadir'), 'drirc.d'))
1568a1362adSmaya
1578a1362adSmayaif with_tests
1588a1362adSmaya  prog_xmllint = find_program('xmllint', required : false, native : true)
1598a1362adSmaya  if prog_xmllint.found()
1608a1362adSmaya    test(
1618a1362adSmaya      'drirc xml validation',
1628a1362adSmaya      prog_xmllint,
1638a1362adSmaya      args : ['--noout', '--valid', files_drirc],
1648a1362adSmaya      suite : ['util'],
1658a1362adSmaya    )
1668a1362adSmaya  endif
1678a1362adSmayaendif
16801e04c3fSmrg
16901e04c3fSmrgfiles_xmlconfig = files(
17001e04c3fSmrg  'xmlconfig.c',
17101e04c3fSmrg  'xmlconfig.h',
17201e04c3fSmrg)
17301e04c3fSmrg
1747ec681f3Smrgfiles_xmlconfig += custom_target(
1757ec681f3Smrg  'driconf_static.h',
1767ec681f3Smrg  input: ['driconf_static.py', '00-mesa-defaults.conf'],
1777ec681f3Smrg  output: 'driconf_static.h',
1787ec681f3Smrg  command: [
1797ec681f3Smrg    prog_python, '@INPUT0@', '@INPUT1@', '@OUTPUT@'
1807ec681f3Smrg  ],
1817ec681f3Smrg)
1827ec681f3Smrg
18301e04c3fSmrgformat_srgb = custom_target(
18401e04c3fSmrg  'format_srgb',
18501e04c3fSmrg  input : ['format_srgb.py'],
18601e04c3fSmrg  output : 'format_srgb.c',
18701e04c3fSmrg  command : [prog_python, '@INPUT0@'],
18801e04c3fSmrg  capture : true,
18901e04c3fSmrg)
19001e04c3fSmrg
1917ec681f3Smrgdeps_for_libmesa_util = [
1927ec681f3Smrg  dep_zlib,
1937ec681f3Smrg  dep_clock,
1947ec681f3Smrg  dep_thread,
1957ec681f3Smrg  dep_atomic,
1967ec681f3Smrg  dep_m,
1977ec681f3Smrg  dep_valgrind,
1987ec681f3Smrg  dep_zstd,
1997ec681f3Smrg  dep_dl,
2007ec681f3Smrg  dep_unwind,
2017ec681f3Smrg]
2027ec681f3Smrg
2037ec681f3Smrgif with_platform_android
2047ec681f3Smrg  deps_for_libmesa_util += dep_android
2057ec681f3Smrg  files_debug_stack = files('u_debug_stack_android.cpp')
2067ec681f3Smrg else
2077ec681f3Smrg  files_debug_stack = files(
2087ec681f3Smrg    'u_debug_stack.c',
2097ec681f3Smrg    'u_debug_symbol.c',
2107ec681f3Smrg    'u_debug_symbol.h',
2117ec681f3Smrg  )
2127ec681f3Smrgendif
2137ec681f3Smrg
2147ec681f3Smrgif with_platform_haiku
2157ec681f3Smrg  deps_for_libmesa_util += dep_network
2167ec681f3Smrgendif
2177ec681f3Smrg
2187ec681f3Smrgif with_perfetto
2197ec681f3Smrg  files_mesa_util += files(
2207ec681f3Smrg    'u_perfetto.cc',
2217ec681f3Smrg    'u_perfetto.h',
2227ec681f3Smrg  )
2237ec681f3Smrg  deps_for_libmesa_util += dep_perfetto
2247ec681f3Smrgendif
2257ec681f3Smrg
2267ec681f3Smrgu_trace_py = files('perf/u_trace.py')
2277ec681f3Smrg
2287ec681f3Smrg_libmesa_util = static_library(
22901e04c3fSmrg  'mesa_util',
2307ec681f3Smrg  [files_mesa_util, files_debug_stack, format_srgb],
2317ec681f3Smrg  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
2327ec681f3Smrg  dependencies : deps_for_libmesa_util,
2337ec681f3Smrg  link_with: libmesa_format,
2347ec681f3Smrg  c_args : [c_msvc_compat_args],
2357ec681f3Smrg  gnu_symbol_visibility : 'hidden',
23601e04c3fSmrg  build_by_default : false
23701e04c3fSmrg)
23801e04c3fSmrg
2397ec681f3Smrgidep_mesautil = declare_dependency(
2407ec681f3Smrg  link_with : _libmesa_util,
2417ec681f3Smrg  include_directories : [inc_util, inc_gallium],
2427ec681f3Smrg  dependencies : [dep_zlib, dep_clock, dep_thread, dep_atomic, dep_m, dep_valgrind],
2437ec681f3Smrg)
2447ec681f3Smrg
2457ec681f3Smrgxmlconfig_deps = []
2467ec681f3Smrgif not (with_platform_android or with_platform_windows)
2477ec681f3Smrg  xmlconfig_deps += dep_expat
2487ec681f3Smrgendif
2497ec681f3Smrgxmlconfig_deps += dep_regex
2507ec681f3Smrg
2517ec681f3Smrg_libxmlconfig = static_library(
25201e04c3fSmrg  'xmlconfig',
25301e04c3fSmrg  files_xmlconfig,
2547ec681f3Smrg  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
2557ec681f3Smrg  dependencies : [idep_mesautil, dep_m, xmlconfig_deps],
25601e04c3fSmrg  c_args : [
2577ec681f3Smrg    c_msvc_compat_args,
25801e04c3fSmrg    '-DSYSCONFDIR="@0@"'.format(
25901e04c3fSmrg      join_paths(get_option('prefix'), get_option('sysconfdir'))
26001e04c3fSmrg    ),
26101e04c3fSmrg    '-DDATADIR="@0@"'.format(
26201e04c3fSmrg      join_paths(get_option('prefix'), get_option('datadir'))
26301e04c3fSmrg    ),
26401e04c3fSmrg  ],
2657ec681f3Smrg  gnu_symbol_visibility : 'hidden',
26601e04c3fSmrg  build_by_default : false,
26701e04c3fSmrg)
26801e04c3fSmrg
2697ec681f3Smrgidep_xmlconfig = declare_dependency(
2707ec681f3Smrg  dependencies : xmlconfig_deps,
2717ec681f3Smrg  link_with : _libxmlconfig,
2727ec681f3Smrg)
2737ec681f3Smrg
2747ec681f3Smrgfiles_xxd = files('xxd.py')
2757ec681f3Smrg
27601e04c3fSmrgif with_tests
2777ec681f3Smrg  # DRI_CONF macros use designated initializers (required for union
2787ec681f3Smrg  # initializaiton), so we need c++2a since gtest forces us to use c++
2797ec681f3Smrg  if host_machine.system() != 'windows' and cpp.has_argument('-std=c++2a')
2807ec681f3Smrg    test('xmlconfig',
2817ec681f3Smrg      executable('xmlconfig_test',
2827ec681f3Smrg        files('tests/xmlconfig.cpp'),
2837ec681f3Smrg        include_directories : [inc_include, inc_src],
2847ec681f3Smrg        dependencies : [idep_mesautil, idep_xmlconfig, idep_gtest],
2857ec681f3Smrg        override_options : ['cpp_std=c++2a'],
2867ec681f3Smrg        cpp_args: ['-Wno-write-strings']
2877ec681f3Smrg      ),
2887ec681f3Smrg      suite : ['util'],
2897ec681f3Smrg      env: ['HOME=' + join_paths(meson.current_source_dir(),
2907ec681f3Smrg                                 'tests', 'drirc_home'),
2917ec681f3Smrg            'DRIRC_CONFIGDIR=' + join_paths(meson.current_source_dir(),
2927ec681f3Smrg                                            'tests', 'drirc_configdir')]
2937ec681f3Smrg        )
2947ec681f3Smrg  endif
2957ec681f3Smrg
29601e04c3fSmrg  test(
29701e04c3fSmrg    'u_atomic',
29801e04c3fSmrg    executable(
29901e04c3fSmrg      'u_atomic_test',
30001e04c3fSmrg      files('u_atomic_test.c'),
3017ec681f3Smrg      include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
3027ec681f3Smrg      dependencies : idep_mesautil,
3037ec681f3Smrg      c_args : [c_msvc_compat_args],
3047ec681f3Smrg    ),
3057ec681f3Smrg    suite : ['util'],
3067ec681f3Smrg  )
3077ec681f3Smrg
3087ec681f3Smrg  test(
3097ec681f3Smrg    'blob',
3107ec681f3Smrg    executable(
3117ec681f3Smrg      'blob_test',
3127ec681f3Smrg      files('blob_test.c'),
3137ec681f3Smrg      include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
3147ec681f3Smrg      dependencies : idep_mesautil,
3157ec681f3Smrg      c_args : [c_msvc_compat_args],
3167ec681f3Smrg    ),
3177ec681f3Smrg    suite : ['util'],
3187ec681f3Smrg  )
3197ec681f3Smrg
3207ec681f3Smrg  test(
3217ec681f3Smrg    'rb_tree',
3227ec681f3Smrg    executable(
3237ec681f3Smrg      'rb_tree_test',
3247ec681f3Smrg      files('rb_tree_test.c'),
3257ec681f3Smrg      include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
3267ec681f3Smrg      dependencies : idep_mesautil,
32701e04c3fSmrg      c_args : [c_msvc_compat_args],
3288a1362adSmaya    ),
3298a1362adSmaya    suite : ['util'],
33001e04c3fSmrg  )
33101e04c3fSmrg
33201e04c3fSmrg  test(
33301e04c3fSmrg    'roundeven',
33401e04c3fSmrg    executable(
33501e04c3fSmrg      'roundeven_test',
33601e04c3fSmrg      files('roundeven_test.c'),
3377ec681f3Smrg      include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
33801e04c3fSmrg      c_args : [c_msvc_compat_args],
33901e04c3fSmrg      dependencies : [dep_m],
3408a1362adSmaya    ),
3418a1362adSmaya    suite : ['util'],
3427ec681f3Smrg    should_fail : meson.get_cross_property('xfail', '').contains('roundeven'),
34301e04c3fSmrg  )
34401e04c3fSmrg
3457ec681f3Smrg  # FIXME: this test crashes on windows
3467ec681f3Smrg  if host_machine.system() != 'windows'
3477ec681f3Smrg    test(
3487ec681f3Smrg      'mesa-sha1',
3497ec681f3Smrg      executable(
3507ec681f3Smrg        'mesa-sha1_test',
3517ec681f3Smrg        files('mesa-sha1_test.c'),
3527ec681f3Smrg        include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
3537ec681f3Smrg        link_with : _libmesa_util,
3547ec681f3Smrg        c_args : [c_msvc_compat_args],
3557ec681f3Smrg      ),
3567ec681f3Smrg      suite : ['util'],
3577ec681f3Smrg    )
3587ec681f3Smrg  endif
3597ec681f3Smrg
3607ec681f3Smrg  foreach t: ['bitset', 'register_allocate', 'u_debug_stack', 'u_qsort']
3617ec681f3Smrg    test(
3627ec681f3Smrg      t,
3637ec681f3Smrg      executable(
3647ec681f3Smrg        t + '_test',
3657ec681f3Smrg        files(t + '_test.cpp'),
3667ec681f3Smrg        include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
3677ec681f3Smrg        dependencies : [idep_mesautil, idep_gtest],
3687ec681f3Smrg      ),
3697ec681f3Smrg      suite : ['util'],
3707ec681f3Smrg    )
3717ec681f3Smrg  endforeach
3727ec681f3Smrg
3737ec681f3Smrg  process_test_exe = executable(
3747ec681f3Smrg    'process_test',
3757ec681f3Smrg    files('process_test.c'),
3767ec681f3Smrg    include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
3777ec681f3Smrg    dependencies : idep_mesautil,
3787ec681f3Smrg    c_args : [c_msvc_compat_args],
3797ec681f3Smrg  )
3807ec681f3Smrg  if (host_machine.system() == 'windows' and build_machine.system() != 'windows')
3817ec681f3Smrg    # This conversion is only required on mingw crosscompilers, otherwise we hit at least one of these issues
3827ec681f3Smrg    # https://gitlab.freedesktop.org/mesa/mesa/-/issues/2690
3837ec681f3Smrg    # https://gitlab.freedesktop.org/mesa/mesa/-/issues/2788
3847ec681f3Smrg    prog_winepath = find_program('winepath')
3857ec681f3Smrg    process_test_exe_full_path = run_command(
3867ec681f3Smrg      prog_winepath, '-w', process_test_exe.full_path()
3877ec681f3Smrg    ).stdout().strip()
3887ec681f3Smrg  else
3897ec681f3Smrg    process_test_exe_full_path = process_test_exe.full_path()
3907ec681f3Smrg  endif
3917ec681f3Smrg
39201e04c3fSmrg  test(
3937ec681f3Smrg    'process',
3947ec681f3Smrg    process_test_exe,
3957ec681f3Smrg    suite : ['util'],
3967ec681f3Smrg    env: ['BUILD_FULL_PATH='+process_test_exe_full_path]
3977ec681f3Smrg  )
3987ec681f3Smrg
3997ec681f3Smrg  test('int_min_max',
4007ec681f3Smrg    executable('int_min_max_test',
4017ec681f3Smrg    files('tests/int_min_max.cpp'),
4027ec681f3Smrg      include_directories : [inc_include, inc_src],
4037ec681f3Smrg      dependencies : [idep_mesautil, idep_gtest],
4048a1362adSmaya    ),
4058a1362adSmaya    suite : ['util'],
4068a1362adSmaya  )
4078a1362adSmaya
4088a1362adSmaya  test(
4097ec681f3Smrg    'dag',
4108a1362adSmaya    executable(
4117ec681f3Smrg      'dag_test',
4127ec681f3Smrg      'tests/dag_test.cpp',
4137ec681f3Smrg      dependencies : [idep_mesautil, idep_gtest],
4147ec681f3Smrg      include_directories : [inc_include, inc_src],
4157ec681f3Smrg    ),
4167ec681f3Smrg    suite : ['util'],
41701e04c3fSmrg  )
41801e04c3fSmrg
4197ec681f3Smrg  subdir('tests/cache')
42001e04c3fSmrg  subdir('tests/fast_idiv_by_const')
4217ec681f3Smrg  subdir('tests/fast_urem_by_const')
42201e04c3fSmrg  subdir('tests/hash_table')
4237ec681f3Smrg  if not (host_machine.system() == 'windows' and cc.get_id() == 'gcc')
4247ec681f3Smrg    # FIXME: These tests fail with mingw, but not with msvc.
4257ec681f3Smrg    subdir('tests/string_buffer')
4267ec681f3Smrg  endif
4277ec681f3Smrg  if cc.has_header('sys/time.h')  # MinGW has this, but Vanilla windows doesn't
4287ec681f3Smrg    subdir('tests/timespec')
4297ec681f3Smrg  endif
43001e04c3fSmrg  subdir('tests/vma')
43101e04c3fSmrg  subdir('tests/set')
4327ec681f3Smrg  subdir('tests/sparse_array')
4337ec681f3Smrg  subdir('tests/format')
4347ec681f3Smrg  subdir('tests/vector')
43501e04c3fSmrgendif
436