| 1 |
# a sort-of realistic example that combines the sourceset and keyval |
| 2 |
# modules, inspired by QEMU's build system |
| 3 |
|
| 4 |
project('sourceset-example', 'cpp', default_options: ['cpp_std=c++11']) |
| 5 |
|
| 6 |
cppid = meson.get_compiler('cpp').get_id() |
| 7 |
if cppid == 'pgi' |
| 8 |
error('MESON_SKIP_TEST: Even PGI 19.4 that claims C++17 full support, cannot handle auto x = y syntax used in this test.') |
| 9 |
endif |
| 10 |
|
| 11 |
ss = import('sourceset') |
| 12 |
keyval = import('keyval') |
| 13 |
|
| 14 |
zlib = declare_dependency(compile_args: '-DZLIB=1') |
| 15 |
another = declare_dependency(compile_args: '-DANOTHER=1') |
| 16 |
not_found = dependency('not-found', required: false, method : 'pkg-config') |
| 17 |
|
| 18 |
common = ss.source_set() |
| 19 |
specific = ss.source_set() |
| 20 |
|
| 21 |
common.add(files('main.cc')) |
| 22 |
common.add(when: [zlib, another], if_true: files('zlib.cc')) |
| 23 |
common.add(when: not_found, |
| 24 |
if_true: files('was-found.cc'), |
| 25 |
if_false: files('not-found.cc')) |
| 26 |
|
| 27 |
subdir('boards') |
| 28 |
subdir('devices') |
| 29 |
|
| 30 |
if meson.is_unity() |
| 31 |
specific.add_all(common) |
| 32 |
common = ss.source_set() |
| 33 |
common.add(files('dummy.cpp')) |
| 34 |
endif |
| 35 |
|
| 36 |
common_lib = static_library('common', common.all_sources(), |
| 37 |
dependencies: common.all_dependencies()) |
| 38 |
|
| 39 |
targets = [ 'arm', 'aarch64', 'x86' ] |
| 40 |
target_dirs = { 'arm' : 'arm', 'aarch64' : 'arm', 'x86': 'x86' } |
| 41 |
|
| 42 |
foreach x : targets |
| 43 |
config = keyval.load('config' / x) |
| 44 |
target_specific = specific.apply(config, strict: false) |
| 45 |
target_common = common.apply(config, strict: false) |
| 46 |
target_deps = target_specific.dependencies() + target_common.dependencies() |
| 47 |
executable(x, |
| 48 |
objects: common_lib.extract_objects(target_common.sources()), |
| 49 |
sources: target_specific.sources(), |
| 50 |
dependencies: target_deps, |
| 51 |
include_directories: 'boards' / target_dirs[x], |
| 52 |
cpp_args: '-DTHE_TARGET="' + x + '"') |
| 53 |
endforeach |