-
Notifications
You must be signed in to change notification settings - Fork 709
Expand file tree
/
Copy pathmeson.build
More file actions
716 lines (641 loc) · 20.7 KB
/
meson.build
File metadata and controls
716 lines (641 loc) · 20.7 KB
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# SPDX-License-Identifier: GPL-2.0-or-later
################################################################################
# The "version" must follow this syntax:
# Official releases:
# major.minor[.patch] e.g. 3.0, 3.0.1
# Release Candidates:
# major.minor[.patch]-rc.* e.g. 3.0-rc.1, 3.0.1-rc.1
#
# Development versions:
# alpha: major.minor[.patch]-a.* e.g. 3.0-a.1, 3.0.1-a.1
# beta: major.minor[.patch]-b.* e.g. 3.0-b.1, 3.0.1-b.1
project(
'nvme-cli', ['c'],
meson_version: '>= 0.62.0',
license: [
'GPL-2.0-only', # nvme-cli
'LGPL-2.1-or-later', # libnvme
],
version: '3.0-a.5',
default_options: [
'c_std=gnu99',
'buildtype=debugoptimized',
'prefix=/usr/local',
'warning_level=1',
'sysconfdir=etc',
'wrap_mode=nofallback',
],
)
fs = import('fs')
cc = meson.get_compiler('c')
cxx_available = add_languages('cpp', required: false, native: false)
host_system = host_machine.system()
################################################################################
# Determine which features we need to build: The nvme executable, the libnvme
# library, and/or the python bindings. These are controlled by the following
# meson options (see meson_options.txt)
#
# -Dnvme=[auto|enabled|disabled] Default: enabled
# -Dlibnvme=[auto|enabled|disabled] Default: enabled
# -Dpython=[auto|enabled|disabled] Default: auto
#
# -Dnvme=auto is equivalent to -Dnvme=enabled
# -Dlibnvme=auto is equivalent to -Dlibnvme=enabled
#
# -Dpython=auto means build the python bindings if all the required
# dependencies are present. Also, -Dpython=enabled forces -Dlibnvme=enabled.
want_nvme = get_option('nvme').disabled() == false
want_libnvme = get_option('libnvme').disabled() == false
want_fabrics = get_option('fabrics').disabled() == false and host_system != 'windows'
want_mi = get_option('mi').disabled() == false and host_system != 'windows'
want_json_c = get_option('json-c').disabled() == false and want_fabrics
want_libkmod = get_option('libkmod').disabled() == false and host_system != 'windows'
want_tests = get_option('tests') and host_system != 'windows'
want_examples = get_option('examples') and host_system != 'windows'
want_docs = get_option('docs')
want_docs_build = get_option('docs-build')
is_static = get_option('default_library') == 'static'
feature_python = get_option('python')
if not want_fabrics or feature_python.disabled()
py3_dep = dependency('', required: false) # Needed for muon
want_python = false
else
if feature_python.enabled()
want_libnvme = true
endif
python3 = import('python').find_installation('python3')
py3_dep = python3.dependency(required: feature_python.enabled())
swig = find_program('swig', required: feature_python.enabled())
header_found = cc.has_header('Python.h', dependencies: py3_dep, required: feature_python.enabled())
want_python = want_libnvme and py3_dep.found() and swig.found() and header_found
endif
# Determine the libnvme.so version number from the project version. The version
# for libnvme.so has to be a 3 digit number such as 3.0.1. We expect the project
# version to be composed of 2 or 3 digits after stripping trailing identifiers
# such as "-rc.*". If the project version is composed of only two digits, then
# we append '.0' to it.
ver = meson.project_version()
ver_digits = ver.split('-')[0]
ver_digits = ver_digits.split('.dev')[0]
num_digits = ver_digits.split('.').length()
if num_digits < 2 or num_digits > 3
error('Invalid version: ', meson.project_version())
elif num_digits == 3
libnvme_so_version = ver_digits
else
libnvme_so_version = ver_digits + '.0'
endif
# For PyPI builds, use only the major version (e.g., '3' instead of '3.0.0').
# This avoids the need for symbolic links which pip/wheel doesn't preserve.
if get_option('pypi')
libnvme_so_version = libnvme_so_version.split('.')[0]
endif
################################################################################
prefixdir = get_option('prefix')
datadir = join_paths(prefixdir, get_option('datadir'))
mandir = join_paths(prefixdir, get_option('mandir'))
sbindir = join_paths(prefixdir, get_option('sbindir'))
sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
udevrulesdir = join_paths(prefixdir, get_option('udevrulesdir'))
dracutrulesdir = join_paths(prefixdir, get_option('dracutrulesdir'))
systemddir = join_paths(prefixdir, get_option('systemddir'))
nmdispatchdir = join_paths(prefixdir, get_option('nmdispatchdir'))
rundir = join_paths(prefixdir, get_option('rundir'))
std_prefix = prefixdir == '/usr' or prefixdir == '/usr/local'
###############################################################################
conf = configuration_data()
requires = ''
version_tag = get_option('version-tag')
if version_tag != ''
conf.set('GIT_VERSION', '"@0@"'.format(version_tag))
else
# Find the path to bash and use it so we don't pick up the WSL bash in Windows.
bash_prog = find_program('bash', required: true)
r = run_command(
bash_prog,
files('scripts/meson-vcs-tag.sh'),
meson.current_source_dir(),
meson.project_version(),
check: true,
)
conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip()))
endif
conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir))
conf.set('RUNDIR', '"@0@"'.format(rundir))
conf.set('CONFIG_FABRICS', want_fabrics, description: 'Is fabrics enabled')
conf.set('CONFIG_MI', want_mi, description: 'Is MI enabled')
if host_system == 'windows'
kernel32_dep = cc.find_library('kernel32', required: true)
endif
# Check for libjson-c availability
if not want_json_c
json_c_dep = dependency('', required: false)
else
json_c_dep = dependency(
'json-c',
required: get_option('json-c'),
version: '>=0.13',
fallback : ['json-c', 'json_c_dep'],
)
if json_c_dep.version().version_compare('>=0.14')
conf.set('CONFIG_JSONC_14', true, description: 'Is json-c at least 0.14?')
requires = 'Requires: json-c >= 0.14'
else
requires = 'Requires: json-c >= 0.13'
endif
endif
conf.set('CONFIG_JSONC', json_c_dep.found(), description: 'Is json-c available?')
conf.set('NVME_VERSION', '"@0@"'.format(meson.project_version()))
conf.set('LIBNVME_VERSION', '"@0@"'.format(meson.project_version()))
conf.set10('DEFAULT_PDC_ENABLED', get_option('pdc-enabled'))
# local (cross-compilable) implementations of ccan configure steps
conf.set10(
'HAVE_BUILTIN_TYPES_COMPATIBLE_P',
cc.compiles(
'''int main(void) {
return __builtin_types_compatible_p(int, long);
}
''',
name: '__builtin_type_compatible_p'
),
description: 'Is __builtin_types_compatible_p available?'
)
conf.set10(
'HAVE_TYPEOF',
cc.compiles(
'''int main(void) {
int a = 1;
typeof(a) b;
b = a;
}
''',
name: 'typeof'
),
description: 'Is typeof available?'
)
conf.set10(
'HAVE_BYTESWAP_H',
cc.compiles(
'''#include <byteswap.h>''',
name: 'byteswap.h'
),
description: 'Is byteswap.h include-able?'
)
conf.set10(
'HAVE_BSWAP_64',
cc.links(
'''#include <byteswap.h>
int main(void) {
return bswap_64(0);
}
''',
name: 'bswap64'
),
description: 'Is bswap_64 available?'
)
conf.set10(
'HAVE_LITTLE_ENDIAN',
host_machine.endian() == 'little',
description: 'Building for little-endian'
)
conf.set10(
'HAVE_BIG_ENDIAN',
host_machine.endian() == 'big',
description: 'Building for big-endian'
)
conf.set10(
'HAVE_ISBLANK',
cc.links(
'''#include <ctype.h>
int main(int argc, char **argv) {
return isblank(argv[0][0]);
}
''',
name: 'isblank'
),
description: 'Is isblank() available?'
)
conf.set10(
'HAVE_SYS_RANDOM',
cc.compiles(
'''#include <sys/random.h>''',
name: 'sys/random.h'
),
description: 'Is sys/random.h(getrandom) include-able?'
)
conf.set10(
'HAVE_ATTRIBUTE_UNUSED',
cc.get_id() == 'clang',
description: 'Is compiler warning about unused static line function?'
)
conf.set10(
'HAVE_SED_OPAL',
cc.compiles(
'''#include <linux/sed-opal.h>''',
name: 'linux/sed-opal.h'
),
description: 'Is linux/sed-opal.h include-able?'
)
conf.set10(
'HAVE_KEY_TYPE',
cc.compiles(
'''
#include <linux/sed-opal.h>
int main(void) {
struct opal_key key;
key.key_type = OPAL_INCLUDED;
}
''',
name: 'key_type'
),
description: 'Does struct opal_key have a key_type field?'
)
conf.set(
'HAVE_TM_GMTOFF',
cc.compiles(
'''
#include <time.h>
int main(void) {
struct tm tm;
tm.tm_gmtoff = 1;
}
''',
name: 'tm_gmtoff'
),
description: 'Does struct tm have a tm_gmtoff field?'
)
if cc.has_function_attribute('fallthrough')
conf.set('fallthrough', '__attribute__((__fallthrough__))')
else
conf.set('fallthrough', 'do {} while (0) /* fallthrough */')
endif
if not want_fabrics or get_option('liburing').disabled()
liburing_dep = dependency('', required: false)
else
liburing_dep = dependency('liburing', version: '>=2.2', required: get_option('liburing'))
endif
conf.set('CONFIG_LIBURING', liburing_dep.found(), description: 'Is liburing available?')
if not want_libkmod
libkmod_dep = dependency('', required: false)
else
libkmod_dep = dependency('libkmod', required: get_option('libkmod'))
endif
conf.set('HAVE_LIBKMOD', libkmod_dep.found(), description: 'Is libkmod available?')
if not want_fabrics or get_option('openssl').disabled()
openssl_dep = dependency('', required: false)
else
openssl_dep = dependency(
'openssl',
version: '>=3.0.0',
required: get_option('openssl'),
fallback : ['openssl', 'libssl_dep'],
)
endif
if openssl_dep.found()
# Test for LibreSSL v3.x with incomplete OpenSSL v3 APIs
if openssl_dep.type_name() != 'internal'
is_libressl = cc.has_header_symbol(
'openssl/opensslv.h',
'LIBRESSL_VERSION_NUMBER',
dependencies: openssl_dep,
)
has_header = cc.has_header(
'openssl/core_names.h',
dependencies: openssl_dep,
)
if is_libressl and not has_header
openssl_dep = dependency('', required: false)
endif
endif
endif
conf.set('CONFIG_OPENSSL', openssl_dep.found(), description: 'Is OpenSSL/LibreSSL available?')
if not want_fabrics or get_option('keyutils').disabled()
keyutils_dep = dependency('', required: false)
else
keyutils_dep = dependency('libkeyutils', required : get_option('keyutils'))
endif
conf.set('CONFIG_KEYUTILS', keyutils_dep.found(), description: 'Is libkeyutils available?')
if not want_mi or get_option('libdbus').disabled()
libdbus_dep = dependency('', required: false)
else
# Check for libdbus availability. Optional, only required for MCTP dbus scan
libdbus_dep = dependency(
'dbus-1',
required: get_option('libdbus'),
fallback: ['dbus', 'libdbus_dep'],
default_options: [
'default_library=static',
'embedded_tests=false',
'message_bus=false',
'modular_tests=disabled',
'tools=false',
],
)
endif
conf.set('CONFIG_DBUS', libdbus_dep.found(), description: 'Enable dbus support?')
conf.set10(
'HAVE_STATEMENT_EXPR',
cc.compiles(
'''int main(int argc, char **argv) {
return ({ int x = argc; x == 1; });
}
''',
name: 'statement-expr'
),
description: 'Can we use a statement as an expression?'
)
conf.set10(
'HAVE_LINUX_MCTP_H',
cc.compiles(
'''#include <linux/mctp.h>''',
name: 'linux/mctp.h'
),
description: 'Is linux/mctp.h include-able?'
)
have_netdb = false
if not is_static
have_netdb = cc.links(
'''#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main(int argc, char **argv) {
struct addrinfo hints, *result;
return getaddrinfo(argv[1], argv[2], &hints, &result);
}
''',
name: 'netdb',
)
endif
conf.set(
'HAVE_NETDB',
have_netdb,
description: 'Is network address and service translation available'
)
threads_dep = dependency('threads', required: true)
dl_dep = dependency('dl', required: false)
conf.set(
'HAVE_LIBC_DLSYM',
cc.has_function('dlsym', dependencies: dl_dep),
description: 'Is dlsym function present',
)
conf.set('NVME_HAVE_SENDFILE', cc.has_function('sendfile'))
conf.set('NVME_HAVE_MMAP', cc.has_function('mmap'))
project_config_file = 'nvme-config.h'
nvme_config_h = configure_file(output: project_config_file, configuration: conf)
config_dep = declare_dependency(
sources: nvme_config_h,
include_directories: '.',
)
# The -include option below requires the full path when
# nvme-cli is build as subproject of another meson project.
if meson.version().version_compare('>=1.4.0')
nvme_config_h_path = nvme_config_h.full_path()
else
nvme_config_h_path = meson.current_build_dir() / project_config_file
endif
add_project_arguments(
[
'-fomit-frame-pointer',
'-D_GNU_SOURCE',
'-include', nvme_config_h_path,
],
language : 'c',
)
# This handles a specific packaging scenario where libnvme is built and
# installed separately from nvme-cli. In this case, libnvme is installed
# under a non-standard prefix, and nvme-cli must be built against the
# previously installed libnvme headers.
#
# To support this layout, we explicitly add the libnvme include path from
# the non-standard prefix. This cannot be done using include_directories(),
# which only supports relative paths, while the libnvme include path is
# absolute.
if not want_libnvme and not std_prefix
libnvme_hdr_location = prefixdir / get_option('includedir')
message(
'Using non-standard libnvme headers location: ',
libnvme_hdr_location
)
# Allow compiler to find headers in non-standard location
add_project_arguments('-I' + libnvme_hdr_location, language : 'c')
endif
################################################################################
libtype = get_option('default_library')
if libtype == 'static'
requires = ''
endif
substs = configuration_data()
substs.set('VERSION', meson.project_version())
substs.set('NVMECLI_LICENSE', meson.project_license()[0])
substs.set('LIBNVME_LICENSE', meson.project_license()[1])
substs.set('UDEVRULESDIR', udevrulesdir)
substs.set('DRACUTRULESDIR', dracutrulesdir)
substs.set('REQUIRES', requires)
substs.set('DATADIR', datadir)
substs.set('MANDIR', mandir)
substs.set('RUNDIR', rundir)
substs.set('SBINDIR', sbindir)
substs.set('SYSCONFDIR', sysconfdir)
substs.set('SYSTEMDDIR', systemddir)
substs.set('SYSTEMCTL', get_option('systemctl'))
substs.set('PREFIX', prefixdir)
substs.set('URL', 'https://github.com/linux-nvme/nvme-cli/')
substs.set('VERSION_MAJOR', libnvme_so_version.split('.')[0])
################################################################################
doc_tgts = []
subdir('ccan') # declares: ccan_dep
subdir('libnvme') # declares: libnvme_dep
if want_nvme
subdir('plugins') # declares: plugin_sources
subdir('util') # declares: util_sources
sources = []
if host_system == 'windows'
sources += [
'nvme-dummy.c', # Dummy source file for Windows port bring up.
]
else
sources += [
'libnvme-wrap.c',
'logging.c',
'nvme-cmds.c',
'nvme-models.c',
'nvme-print-binary.c',
'nvme-print-stdout.c',
'nvme-print.c',
'nvme-rpmb.c',
'nvme.c',
'plugin.c',
]
if json_c_dep.found()
sources += [
'nvme-print-json.c',
]
endif
endif
if want_fabrics
sources += 'fabrics.c'
endif
sources += plugin_sources
sources += util_sources
link_args_list = []
link_deps = [
config_dep,
ccan_dep,
libnvme_dep,
json_c_dep,
libkmod_dep,
]
if host_system == 'windows'
link_deps += [
kernel32_dep,
]
else
link_args_list = ['-ldl']
endif
executable(
'nvme',
sources,
dependencies: link_deps,
link_args: link_args_list,
install: true,
install_dir: sbindir,
)
if host_system != 'windows'
subdir('unit')
endif
if get_option('nvme-tests')
subdir('tests')
endif
configure_file(
input: 'nvme.spec.in',
output: 'nvme.spec',
configuration: substs,
)
disc = configure_file(
input: 'etc/discovery.conf.in',
output: 'discovery.conf',
configuration: substs,
install: true,
install_dir: join_paths(sysconfdir, 'nvme'),
)
dracut_files = [
'70-nvmf-autoconnect.conf',
]
foreach file : dracut_files
configure_file(
input: 'nvmf-autoconnect/dracut-conf/' + file + '.in',
output: file,
configuration: substs,
install: true,
install_dir: dracutrulesdir,
)
endforeach
systemd_files = [
'nvmefc-boot-connections.service',
'nvmf-autoconnect.service',
'nvmf-connect-nbft.service',
'nvmf-connect.target',
]
foreach file : systemd_files
configure_file(
input: 'nvmf-autoconnect/systemd/' + file + '.in',
output: file,
configuration: substs,
install: true,
install_dir: systemddir,
)
endforeach
udev_files = [
'65-persistent-net-nbft.rules',
'70-nvmf-autoconnect.rules',
'70-nvmf-keys.rules',
'71-nvmf-hpe.rules',
'71-nvmf-netapp.rules',
'71-nvmf-vastdata.rules',
]
foreach file : udev_files
configure_file(
input: 'nvmf-autoconnect/udev-rules/' + file + '.in',
output: file,
configuration: substs,
install: true,
install_dir: udevrulesdir
)
endforeach
nm_dispatcher_files = [
'80-nvmf-connect-nbft.sh'
]
foreach file : nm_dispatcher_files
configure_file(
input: 'nvmf-autoconnect/nm-dispatcher/' + file + '.in',
output: file,
configuration: substs,
install: true,
install_mode: 'rwxr-xr-x',
install_dir: nmdispatchdir
)
endforeach
install_data(
'completions/bash-nvme-completion.sh',
rename: 'nvme',
install_dir: datadir / 'bash-completion/completions',
)
install_data(
'completions/_nvme',
install_dir: datadir / 'zsh/site-functions',
)
subdir('Documentation')
endif
if doc_tgts.length() == 0
doc_tgts += custom_target(
'docs-dummy',
output: 'docs.stamp',
command: ['true'],
build_by_default: false,
)
endif
alias_target('docs', doc_tgts)
################################################################################
path_dict = {
'prefixdir': prefixdir,
'sysconfdir': sysconfdir,
'sbindir': sbindir,
'datadir': datadir,
'mandir': mandir,
'udevrulesdir': udevrulesdir,
'dracutrulesdir': dracutrulesdir,
'rundir': rundir,
'systemddir': systemddir,
'nmdispatchdir': nmdispatchdir,
'build location': meson.current_build_dir(),
}
summary(path_dict, section: 'Paths')
dep_dict = {
'json-c': json_c_dep.found(),
'OpenSSL': openssl_dep.found(),
'keyutils': keyutils_dep.found(),
'libdbus': libdbus_dep.found(),
'python3': py3_dep.found(),
'liburing': liburing_dep.found(),
'libkmod': libkmod_dep.found(),
}
if host_system == 'windows'
dep_dict += {
'kernel32': kernel32_dep.found(),
}
endif
summary(dep_dict, section: 'Dependencies', bool_yn: true)
wanted_dict = {
'nvme': want_nvme,
'libnvme': want_libnvme,
'fabrics': want_fabrics,
'python bindings ': want_python,
'build docs': want_docs_build,
}
summary(wanted_dict, section: 'Features to build', bool_yn: true)
conf_dict = {
'git version': conf.get('GIT_VERSION'),
'pdc enabled': get_option('pdc-enabled'),
}
summary(conf_dict, section: 'Configuration', bool_yn: true)