examples: fix install with empty meson parameter
[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') == ''
23         subdir_done()
24 endif
25
26 if get_option('examples').to_lower() == 'all'
27         examples = all_examples
28         allow_skips = true # don't flag an error if we can't build an app
29 else
30         examples = get_option('examples').split(',')
31         allow_skips = false # error out if we can't build a requested app
32 endif
33 default_cflags = machine_args
34 if cc.has_argument('-Wno-format-truncation')
35         default_cflags += '-Wno-format-truncation'
36 endif
37
38 # specify -D_GNU_SOURCE unconditionally
39 default_cflags += '-D_GNU_SOURCE'
40
41 foreach example: examples
42         name = example
43         build = true
44         sources = []
45         allow_experimental_apis = false
46         cflags = default_cflags
47
48         ext_deps = [execinfo]
49         includes = [include_directories(example)]
50         deps = ['eal', 'mempool', 'net', 'mbuf', 'ethdev', 'cmdline']
51         if is_windows
52                 deps = ['eal'] # only supported lib on Windows currently
53         endif
54         subdir(example)
55
56         if build
57                 dep_objs = ext_deps
58                 foreach d:deps
59                         var_name = get_option('default_library') + '_rte_' + d
60                         if not is_variable(var_name)
61                                 error('Missing dependency "@0@" for example "@1@"'.format(d, name))
62                         endif
63                         dep_objs += [get_variable(var_name)]
64                 endforeach
65                 if allow_experimental_apis
66                         cflags += '-DALLOW_EXPERIMENTAL_API'
67                 endif
68                 executable('dpdk-' + name, sources,
69                         include_directories: includes,
70                         link_whole: driver_libs,
71                         link_args: dpdk_extra_ldflags,
72                         c_args: cflags,
73                         dependencies: dep_objs)
74         elif not allow_skips
75                 error('Cannot build requested example "' + name + '"')
76         else
77                 message('Skipping example "' + name + '"')
78         endif
79 endforeach