1project('winmain', 'c')
2
3# MinGW windres has a bug due to which it doesn't parse args with space properly:
4# https://github.com/mesonbuild/meson/pull/1346
5# https://sourceware.org/bugzilla/show_bug.cgi?id=4933
6if ['gcc', 'clang'].contains(meson.get_compiler('c').get_id()) and host_machine.system() == 'windows'
7  # Construct build_to_src and skip this test if it has spaces
8  # because then the -I flag to windres will also have spaces
9  # and we know the test will fail
10  src_parts = meson.source_root().split('/')
11  build_parts = meson.build_root().split('/')
12
13  # Get the common path (which might just be '/' or 'C:/')
14  common = []
15  done = false
16  count = 0
17  if src_parts.length() > build_parts.length()
18    parts = build_parts
19    other = src_parts
20  else
21    parts = src_parts
22    other = build_parts
23  endif
24  foreach part : parts
25    if not done and part == other.get(count)
26      common += [part]
27    else
28      done = true
29    endif
30    count += 1
31  endforeach
32
33  # Create path components to go down from the build root to the common path
34  count = 0
35  rel = build_parts
36  foreach build : build_parts
37    if count < build_parts.length() - common.length()
38      rel += ['..']
39    endif
40    count += 1
41  endforeach
42
43  # Create path components to go up from the common path to the build root
44  count = 0
45  foreach src : src_parts
46    if count >= common.length()
47      rel += [src]
48    endif
49    count += 1
50  endforeach
51
52  build_to_src = '/'.join(rel)
53
54  if build_to_src.contains(' ')
55    message('build_to_src is: ' + build_to_src)
56    error('MESON_SKIP_TEST build_to_src has spaces')
57  endif
58  # Welcome to the end of this conditional.
59  # We hope you never have to implement something like this.
60endif
61
62subdir('res')
63
64foreach id : [0, 1, 2]
65  exe = executable('prog_@0@'.format(id), 'prog.c',
66    res[id],
67    gui_app : true)
68
69  test('winmain_@0@'.format(id), exe)
70endforeach
71