summaryrefslogtreecommitdiffstats
path: root/test cases/common/212 source set configuration_data/meson.build
blob: 9aacbc4b296411f369abb59de766d0bd490a255f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
project('a', 'c')

good = declare_dependency(link_with: static_library('good', 'g.c'))
bad = declare_dependency(link_args: 'nonexistent.a')
not_found = dependency('invalid', required: false)

source_set = import('sourceset')

sources = source_set.source_set()
sources.add(when: 'YES',  if_false: ['nope.c'])
sources.add(when: 'YES1', if_true: [files('a.c'), not_found])
subdir('subdir')
sources.add(when: 'NO',   if_true: 'nope.c', if_false: ['f.c'])
sources.add(when: 'NO',   if_true: bad,      if_false: ['f.c'])

sources.add(when: 'YES2', if_true: good)

# dependencies as conditions
sources.add(when: not_found, if_true: 'nope.c')

# test add_all
sources2 = source_set.source_set()
sources2.add(when: 'YES1',  if_true: 'nope.c')
sources.add_all(when: 'NO', if_true: sources2)

# test duplicate items
sources.add(when: 'YES1',   if_true: [files('a.c'), not_found])

conf1 = configuration_data()
conf1.set10('YES', true)
conf1.set10('YES1', true)
conf1.set10('YES2', false)
conf1.set10('NO', false)
result1 = sources.apply(conf1)

conf2 = configuration_data()
conf2.set10('YES', true)
conf2.set10('YES1', false)
conf2.set10('YES2', true)
conf2.set10('NO', false)
result2 = sources.apply(conf2)

# Each target will recompile the objects
executable('first', sources: result1.sources(), dependencies: result1.dependencies())
executable('second', sources: result2.sources(), dependencies: result2.dependencies())

# All target will use the same object files
if meson.is_unity()
  message('Skipping extraction test because this is a Unity build.')
else
  all_objs = static_library('all_objs', sources.all_sources())
  executable('first_via_lib', objects: all_objs.extract_objects(result1.sources()), dependencies: result1.dependencies())
  executable('second_via_lib', objects: all_objs.extract_objects(result2.sources()), dependencies: result2.dependencies())
endif