aboutsummaryrefslogtreecommitdiff
path: root/test cases/common/222 source set realistic example/meson.build
blob: d986b991a5658f82e6e9c63f67918f3ac0158b94 (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
# a sort-of realistic example that combines the sourceset and keyval
# modules, inspired by QEMU's build system

project('sourceset-example', 'cpp', default_options: ['cpp_std=c++11'])

cppid = meson.get_compiler('cpp').get_id()
if cppid == 'pgi'
  error('MESON_SKIP_TEST: Even PGI 19.4 that claims C++17 full support, cannot handle auto x = y syntax used in this test.')
endif

ss = import('sourceset')
keyval = import('keyval')

zlib = declare_dependency(compile_args: '-DZLIB=1')
another = declare_dependency(compile_args: '-DANOTHER=1')
not_found = dependency('not-found', required: false)

common = ss.source_set()
specific = ss.source_set()

common.add(files('main.cc'))
common.add(when: [zlib, another], if_true: files('zlib.cc'))
common.add(when: not_found,
           if_true: files('was-found.cc'),
           if_false: files('not-found.cc'))

subdir('boards')
subdir('devices')

if meson.is_unity()
  specific.add_all(common)
  common = ss.source_set()
endif

common_lib = static_library('common', common.all_sources(),
                            dependencies: common.all_dependencies())

targets = [ 'arm', 'aarch64', 'x86' ]
target_dirs = { 'arm' : 'arm', 'aarch64' : 'arm', 'x86': 'x86' }

foreach x : targets
  config = keyval.load('config' / x)
  target_specific = specific.apply(config, strict: false)
  target_common = common.apply(config, strict: false)
  target_deps = target_specific.dependencies() + target_common.dependencies()
  executable(x,
             objects: common_lib.extract_objects(target_common.sources()),
             sources: target_specific.sources(),
             dependencies: target_deps,
             include_directories: 'boards' / target_dirs[x],
             cpp_args: '-DTHE_TARGET="' + x + '"')
endforeach