-
Notifications
You must be signed in to change notification settings - Fork 15
/
meson.build
259 lines (233 loc) · 9.72 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# BSD 3-Clause License
#
# Copyright 2018 Luca Boccassi <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
project('virtio-forwarder', 'C',
version: run_command(['git', 'describe', '--tags', '--long']).stdout().strip(),
license: 'BSD',
default_options: ['buildtype=release'],
meson_version: '>= 0.45.1'
)
# Generate a compiler object
cc = meson.get_compiler('c')
# Attempt to detect the Distro we are building on
vf_install_dir = ''
rhel_family = false
debian_family = false
distro = run_command('cat', '/etc/os-release')
if (distro.stdout().to_lower().contains('fedora') or
distro.stdout().to_lower().contains('centos') or
distro.stdout().to_lower().contains('rhel'))
message('Fedora/CentOS/Rhel detected')
vf_install_dir = join_paths('lib64', 'virtio-forwarder')
rhel_family = true
elif (distro.stdout().to_lower().contains('debian') or
distro.stdout().to_lower().contains('ubuntu'))
message('Debian/Ubuntu detected')
vf_install_dir = join_paths('lib', 'virtio-forwarder')
debian_family = true
else
error('Unknown distro detected!')
endif
# If the project version string is empty it is likley that the git command used
# to grab the version failed. In this situasion meson was probably called from a
# source tree with the git info stripped out (source rpm and debs).
if meson.project_version() == ''
message('Not running in a git tree')
else
# Populate vrelay_version.h with the project versions
vrelay_version = configuration_data()
vrelay_version.set('MAJOR', '@0@'.format(meson.project_version().split('.').get(0)))
vrelay_version.set('MINOR', '@0@'.format(meson.project_version().split('.').get(1)))
vrelay_version.set('PATCH', '@0@'.format(meson.project_version().split('.').get(2).split('-').get(0)))
vrelay_version.set('BUILD', '@0@'.format(meson.project_version().split('-').get(-2)))
vrelay_version.set('SHASH', '@0@'.format(meson.project_version().split('-').get(-1)))
vrelay = configure_file(input: 'vrelay_version.h.in',
output: 'vrelay_version.h',
configuration: vrelay_version)
endif
vrelay_file_root = join_paths(meson.current_source_dir(), 'vrelay_version.h')
vrelay_file_build = join_paths(meson.current_build_dir(), 'vrelay_version.h')
if (run_command('[', '-e', vrelay_file_build, ']').returncode() == 0)
vrelay = vrelay_file_build
elif (run_command('[', '-e', vrelay_file_root, ']').returncode() == 0)
vrelay = vrelay_file_root
else
# This shouldn't happen ordinarily. Either vrelay_version.h was generated
# from the git tree or it was included in the root source directory by the
# packaging logic
error('vrelay_version.h not found! Exiting...')
endif
# Hook to call the packaging meson scripts from the virtio-forwarder-dist repo
if get_option('rpm') or get_option('srpm') or get_option('deb') or get_option('dsc')
# clone packaging repo and include as subdir
dist_repo = 'https://github.com/Netronome/virtio-forwarder-dist'
git_clone = run_command('git', 'clone', dist_repo, 'packaging')
subdir('packaging')
# The copr build system will typically call this meson file with the option
# "srpm". This is done in a mock chroot, usually of the latest Fedora. In
# order to avoid any unnecessary installs in the chroot meson will stop here
#
# For PPA uploads a signed .dsc file (among other things) needs to be generated
# The scripts in the virtio-forwarder-dist repo will do this for us.
if get_option('srpm') or get_option('dsc')
subdir_done()
endif
endif
# Upstream dpdk-devel (RHEL/CentOS) does not yet ship a libdpdk.pc
# file or static versions of the DPDK libraries. Use this script
# to attempt to detect what libraries are installed and generate a
# custom libdpdk.pc.
if rhel_family
found_libdpdk_pc = ''
libdpdk_pc_paths = ['/usr/lib64/pkgconfig/libdpdk.pc',
'/usr/local/lib64/pkgconfig/libdpdk.pc']
# Search for a libdpdk.pc file in both /usr/local/lib64 and /usr/lib64
# to cover the case where DPDK was installed either as a shared library
# from source or by means of a upstream package
foreach libdpdk_pc : libdpdk_pc_paths
if (run_command('[', '-e', libdpdk_pc, ']').returncode() != 0)
continue
else
found_libdpdk_pc = libdpdk_pc
break
endif
endforeach
# Attempt to generate a libdpdk.pc file if one was not found
if found_libdpdk_pc == ''
message('Creating libdpdk.pc file')
pkgconfig_builder = find_program('pkg_config_builder.py')
r = run_command(pkgconfig_builder)
if r.returncode() != 0
error(r.stderr().strip())
else
message(r.stdout().strip())
endif
else
# Use the libdpdk.pc found on the system
message('Using libdpdk.pc located at: ' + found_libdpdk_pc)
endif
endif
protoc_c = find_program('protoc-c')
protoc = find_program('protoc')
touch = find_program('touch')
custom_target('proto-py',
input: 'virtioforwarder.proto',
output: 'virtioforwarder_pb2.py',
command: [protoc, '--proto_path=@CURRENT_SOURCE_DIR@', '--python_out=@OUTDIR@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: join_paths(vf_install_dir, 'protobuf', 'virtioforwarder'))
custom_target('init',
output: '__init__.py',
command: [touch, '@OUTPUT@'],
build_by_default: true,
install: true,
install_dir: join_paths(vf_install_dir, 'protobuf', 'virtioforwarder'))
# non-portable hack - cannot currently install same file in multiple directories
if rhel_family
meson.add_install_script('sh', '-c',
'install -m0644 $MESON_BUILD_ROOT/__init__.py $MESON_INSTALL_DESTDIR_PREFIX/lib64/virtio-forwarder/protobuf/__init__.py')
elif debian_family
meson.add_install_script('sh', '-c',
'install -m0644 $MESON_BUILD_ROOT/__init__.py $MESON_INSTALL_DESTDIR_PREFIX/lib/virtio-forwarder/protobuf/__init__.py')
endif
subdir('scripts')
pb_c = generator(protoc_c,
output: ['@[email protected]', '@[email protected]'],
arguments : ['--proto_path=@CURRENT_SOURCE_DIR@', '--c_out=@BUILD_DIR@', '@INPUT@'])
generated_c = pb_c.process('virtioforwarder.proto')
if get_option('static')
dpdk = dependency('libdpdk', static : true)
else
dpdk = dependency('libdpdk')
endif
cflags = ['-Wno-error=cpp']
cflags += '-std=gnu11'
cflags += '-D_GNU_SOURCE'
cflags += '-mavx'
# older versions of the dpdk pc file did not include the baseline architecture
# set it to corei7. This can be dropped once support for DPDK < 18.11
# is no longer necessary
dpdk_cflags = dpdk.get_pkgconfig_variable('cflags')
if host_machine.cpu_family().startswith('x86') and not dpdk_cflags.contains('-march')
cflags += '-march=corei7'
endif
sources = files('argv.c',
'cmdline.c',
'cpuinfo.c',
'dpdk_eal.c',
'file_mon.c',
'log.c',
'ovsdb_mon.c',
'sriov.c',
'ugid.c',
'virtio_forwarder_main.c',
'virtio_vhostuser.c',
'virtio_worker.c',
'zmq_config.c',
'zmq_port_control.c',
'zmq_server.c',
'zmq_service.c',
'zmq_stats.c',
'zmq_core_sched.c',)
# Explicitly link to the bond PMD here but only if it is actually available
if not get_option('static')
if cc.has_header('rte_eth_bond.h') or cc.has_header('dpdk/rte_eth_bond.h')
message('Explicitly linking to rte_net_bond')
if debian_family
dpdk = declare_dependency(dependencies : dpdk,
link_args : '-lrte_pmd_bond')
elif rhel_family
librte_pc_paths = ['/usr/lib64/', '/usr/local/lib64/']
foreach librte_pc : librte_pc_paths
if (run_command('[', '-e', librte_pc + 'librte_pmd_bond.so', ']').returncode() == 0)
dpdk = declare_dependency(dependencies : dpdk, link_args : '-lrte_pmd_bond')
break
elif (run_command('[', '-e', librte_pc + 'librte_net_bond.so', ']').returncode() == 0)
dpdk = declare_dependency(dependencies : dpdk, link_args : '-lrte_net_bond')
break
else
continue
endif
endforeach
endif
endif
endif
deps = [
dpdk,
dependency('libprotobuf-c'),
dependency('libzmq'),
dependency('libbsd'),
dependency('threads')]
executable('virtio-forwarder',
[vrelay, generated_c, sources],
c_args: cflags,
dependencies: deps,
install: true)
subdir('startup')
subdir('doc')