xref: /dpdk/examples/meson.build (revision f0897131)
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright(c) 2017-2019 Intel Corporation
3
4driver_libs = []
5if get_option('default_library') == 'static'
6	driver_libs = dpdk_drivers
7endif
8
9execinfo = cc.find_library('execinfo', required: false)
10
11all_examples = run_command('sh', '-c',
12	'cd $MESON_SOURCE_ROOT/$MESON_SUBDIR && for d in * ; do if [ -d $d ] ; then echo $d ; fi ; done'
13	).stdout().split()
14# install all example code on install - irrespective of whether the example in
15# question is to be built as part of this build or not.
16foreach ex:all_examples
17	install_subdir(ex,
18			install_dir: get_option('datadir') + '/dpdk/examples',
19			exclude_files: 'meson.build')
20endforeach
21
22if get_option('examples').to_lower() == 'all'
23	examples = all_examples
24	allow_skips = true # don't flag an error if we can't build an app
25else
26	examples = get_option('examples').split(',')
27	allow_skips = false # error out if we can't build a requested app
28endif
29default_cflags = machine_args
30if cc.has_argument('-Wno-format-truncation')
31	default_cflags += '-Wno-format-truncation'
32endif
33
34# specify -D_GNU_SOURCE unconditionally
35default_cflags += '-D_GNU_SOURCE'
36
37foreach example: examples
38	name = example
39	build = true
40	sources = []
41	allow_experimental_apis = false
42	cflags = default_cflags
43
44	ext_deps = [execinfo]
45	includes = [include_directories(example)]
46	deps = ['eal', 'mempool', 'net', 'mbuf', 'ethdev', 'cmdline']
47	if is_windows
48		deps = ['eal'] # only supported lib on Windows currently
49	endif
50	subdir(example)
51
52	if build
53		dep_objs = ext_deps
54		foreach d:deps
55			var_name = get_option('default_library') + '_rte_' + d
56			if not is_variable(var_name)
57				error('Missing dependency "@0@" for example "@1@"'.format(d, name))
58			endif
59			dep_objs += [get_variable(var_name)]
60		endforeach
61		if allow_experimental_apis
62			cflags += '-DALLOW_EXPERIMENTAL_API'
63		endif
64		executable('dpdk-' + name, sources,
65			include_directories: includes,
66			link_whole: driver_libs,
67			link_args: dpdk_extra_ldflags,
68			c_args: cflags,
69			dependencies: dep_objs)
70	elif not allow_skips
71		error('Cannot build requested example "' + name + '"')
72	else
73		message('Skipping example "' + name + '"')
74	endif
75endforeach
76