xref: /dpdk/examples/meson.build (revision 2d0c29a37a9c080c1cccb1ad7941aba2ccf5437e)
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
11allow_skips = true # don't flag an error if we can't build an app
12
13if get_option('examples').to_lower() == 'all'
14	dirs = run_command('sh', '-c',
15		'cd $MESON_SOURCE_ROOT/$MESON_SUBDIR && for d in * ; do if [ -d $d ] ; then echo $d ; fi ; done')
16	examples = dirs.stdout().split()
17else
18	examples = get_option('examples').split(',')
19	allow_skips = false # error out if we can't build a requested app
20endif
21default_cflags = machine_args
22if cc.has_argument('-Wno-format-truncation')
23	default_cflags += '-Wno-format-truncation'
24endif
25
26# specify -D_GNU_SOURCE unconditionally
27default_cflags += '-D_GNU_SOURCE'
28
29foreach example: examples
30	name = example
31	build = true
32	sources = []
33	allow_experimental_apis = false
34	cflags = default_cflags
35
36	ext_deps = [execinfo]
37	includes = [include_directories(example)]
38	deps = ['eal', 'mempool', 'net', 'mbuf', 'ethdev', 'cmdline']
39	if host_machine.system() == 'windows'
40		deps = ['eal'] # only supported lib on Windows currently
41	endif
42	subdir(example)
43
44	if build
45		dep_objs = ext_deps
46		foreach d:deps
47			var_name = get_option('default_library') + '_rte_' + d
48			if not is_variable(var_name)
49				error('Missing dependency "@0@" for example "@1@"'.format(d, name))
50			endif
51			dep_objs += [get_variable(var_name)]
52		endforeach
53		if allow_experimental_apis
54			cflags += '-DALLOW_EXPERIMENTAL_API'
55		endif
56		executable('dpdk-' + name, sources,
57			include_directories: includes,
58			link_whole: driver_libs,
59			link_args: dpdk_extra_ldflags,
60			c_args: cflags,
61			dependencies: dep_objs)
62	elif not allow_skips
63		error('Cannot build requested example "' + name + '"')
64	else
65		message('Skipping example "' + name + '"')
66	endif
67endforeach
68