examples: install as part of ninja install
[dpdk.git] / examples / meson.build
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2017-2019 Intel Corporation
3
4 driver_libs = []
5 if get_option('default_library') == 'static'
6         driver_libs = dpdk_drivers
7 endif
8
9 execinfo = cc.find_library('execinfo', required: false)
10
11 all_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.
16 foreach ex:all_examples
17         install_subdir(ex,
18                         install_dir: get_option('datadir') + '/dpdk/examples',
19                         exclude_files: 'meson.build')
20 endforeach
21
22 if 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
25 else
26         examples = get_option('examples').split(',')
27         allow_skips = false # error out if we can't build a requested app
28 endif
29 default_cflags = machine_args
30 if cc.has_argument('-Wno-format-truncation')
31         default_cflags += '-Wno-format-truncation'
32 endif
33
34 # specify -D_GNU_SOURCE unconditionally
35 default_cflags += '-D_GNU_SOURCE'
36
37 foreach 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
75 endforeach