1project('generated assembly', 'c')
2
3cc = meson.get_compiler('c')
4
5if ['msvc', 'intel-cl'].contains(cc.get_id())
6  error('MESON_SKIP_TEST: assembly files cannot be compiled directly by the compiler')
7endif
8
9if meson.backend() == 'xcode'
10  error('MESON_SKIP_TEST: asm not supported with the Xcode backend. Patches welcome.')
11endif
12
13
14crt_workaround = []
15if cc.get_linker_id() == 'lld-link'
16  # It seems that when building without a .c file, lld-link.exe
17  # misses the fact that it needs to include the c runtime to
18  # make a working .dll. So here we add an empty .c file to easily
19  # pull in crt.
20  crt_workaround += 'empty.c'
21  if host_machine.cpu_family() == 'x86'
22    # x86 assembly needs manual annotation to be compatible with
23    # Safe Exception Handlers (?) This assembly doesn't have such
24    # annotation, so just disable the feature.
25    add_project_link_arguments('/SAFESEH:NO', language : 'c')
26  endif
27endif
28
29cpu = host_machine.cpu_family()
30supported_cpus = ['arm', 'x86', 'x86_64']
31
32if not supported_cpus.contains(cpu)
33  error('MESON_SKIP_TEST: unsupported cpu family: ' + cpu)
34endif
35
36if cc.get_id() == 'clang-cl' and cc.version().version_compare('< 12.0.0') and cpu == 'arm'
37  # https://reviews.llvm.org/D89622
38  error('MESON_SKIP_TEST: arm debug symbols not supported in clang-cl < 12.0.0')
39endif
40
41if cc.symbols_have_underscore_prefix()
42  add_project_arguments('-DMESON_TEST__UNDERSCORE_SYMBOL', language : 'c')
43endif
44
45copy = find_program('copyfile.py')
46output = 'square-@0@.S'.format(cpu)
47input = output + '.in'
48
49copygen = generator(copy,
50  arguments : ['@INPUT@', '@OUTPUT@'],
51  output : '@BASENAME@')
52
53l = library('square-gen', crt_workaround + [copygen.process(input)],
54  vs_module_defs: 'square.def')
55
56test('square-gen-test', executable('square-gen-test', 'main.c', link_with : l))
57
58copyct = custom_target('square',
59  input : input,
60  output : output,
61  command : [copy, '@INPUT@', '@OUTPUT@'])
62
63l = library('square-ct', crt_workaround + [copyct],
64  vs_module_defs: 'square.def')
65
66test('square-ct-test', executable('square-ct-test', 'main.c', link_with : l))
67