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