-
Notifications
You must be signed in to change notification settings - Fork 9
/
meson.build
2422 lines (2067 loc) · 68.7 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
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
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
project(
'libvirt', 'c',
version: '7.10.0',
license: 'LGPLv2+',
meson_version: '>= 0.54.0',
default_options: [
'buildtype=debugoptimized',
'b_pie=true',
'c_std=gnu99',
'warning_level=2',
],
)
# figure out if we are building from git
git = run_command('test', '-d', '.git').returncode() == 0
if git and not get_option('no_git')
run_command('git', 'submodule', 'update', '--init')
endif
# prepare build configuration data
conf = configuration_data()
conf.set('_GNU_SOURCE', 1)
conf.set_quoted('abs_top_builddir', meson.build_root())
conf.set_quoted('abs_top_srcdir', meson.source_root())
conf.set_quoted('PACKAGE', meson.project_name())
conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set_quoted('VERSION', meson.project_version())
if host_machine.system() == 'windows'
# For AI_ADDRCONFIG
conf.set('_WIN32_WINNT', '0x0600') # Win Vista / Server 2008
conf.set('WINVER', '0x0600') # Win Vista / Server 2008
endif
# set various paths
if get_option('system')
prefix = '/usr'
libdir = prefix / 'lib64'
if run_command('test', '-d', libdir).returncode() != 0
libdir = prefix / 'lib'
endif
localstatedir = '/var'
sysconfdir = '/etc'
else
prefix = get_option('prefix')
libdir = prefix / get_option('libdir')
localstatedir = prefix / get_option('localstatedir')
sysconfdir = prefix / get_option('sysconfdir')
endif
# if --prefix is /usr, don't use /usr/var for localstatedir or /usr/etc for
# sysconfdir as this makes a lot of things break in testing situations
if prefix == '/usr'
if localstatedir == '/usr/var'
localstatedir = '/var'
endif
if sysconfdir == '/usr/etc'
sysconfdir = '/etc'
endif
endif
runstatedir = get_option('runstatedir')
if runstatedir == ''
runstatedir = localstatedir / 'run'
endif
bindir = prefix / get_option('bindir')
datadir = prefix / get_option('datadir')
includedir = prefix / get_option('includedir')
infodir = prefix / get_option('infodir')
libexecdir = prefix / get_option('libexecdir')
localedir = prefix / get_option('localedir')
mandir = prefix / get_option('mandir')
sbindir = prefix / get_option('sbindir')
sharedstatedir = prefix / get_option('sharedstatedir')
docdir = get_option('docdir')
if docdir == ''
docdir = datadir / 'doc' / meson.project_name()
endif
confdir = sysconfdir / meson.project_name()
pkgdatadir = datadir / meson.project_name()
# generate configmake.h header
configmake_conf = configuration_data()
configmake_conf.set_quoted('BINDIR', bindir)
configmake_conf.set_quoted('DATADIR', datadir)
configmake_conf.set_quoted('LIBDIR', libdir)
configmake_conf.set_quoted('LIBEXECDIR', libexecdir)
configmake_conf.set_quoted('LOCALEDIR', localedir)
configmake_conf.set_quoted('LOCALSTATEDIR', localstatedir)
configmake_conf.set_quoted('MANDIR', mandir)
configmake_conf.set_quoted('PKGDATADIR', pkgdatadir)
configmake_conf.set_quoted('PREFIX', prefix)
configmake_conf.set_quoted('RUNSTATEDIR', runstatedir)
configmake_conf.set_quoted('SBINDIR', sbindir)
configmake_conf.set_quoted('SYSCONFDIR', sysconfdir)
configure_file(
input: 'configmake.h.in',
output: '@BASENAME@',
configuration: configmake_conf,
)
# packager options
packager = get_option('packager')
packager_version = get_option('packager_version')
if packager != ''
conf.set_quoted('PACKAGER', packager)
endif
if packager_version != ''
conf.set_quoted('PACKAGER_VERSION', packager_version)
endif
# test options
if get_option('expensive_tests').auto()
use_expensive_tests = not git
else
use_expensive_tests = get_option('expensive_tests').enabled()
endif
coverage_flags = []
if get_option('test_coverage')
coverage_flags = [
'-fprofile-arcs',
'-ftest-coverage',
]
endif
# Add RPATH information when building for a non-standard prefix, or
# when explicitly requested to do so
if prefix == '/usr' and not get_option('rpath').enabled()
libvirt_rpath = ''
else
libvirt_rpath = libdir
endif
# figure out libvirt version strings
arr_version = meson.project_version().split('.')
libvirt_version_number = 1000000 * arr_version[0].to_int() + 1000 * arr_version[1].to_int() + arr_version[2].to_int()
conf.set('LIBVIRT_VERSION_NUMBER', libvirt_version_number)
# In libtool terminology we need to figure out:
#
# CURRENT
# The most recent interface number that this library implements.
#
# REVISION
# The implementation number of the CURRENT interface.
#
# AGE
# The difference between the newest and oldest interfaces that this
# library implements.
#
# In other words, the library implements all the interface numbers
# in the range from number `CURRENT - AGE' to `CURRENT'.
#
# Libtool assigns the soname version from `CURRENT - AGE', and we
# don't want that to ever change in libvirt. ie it must always be
# zero, to produce libvirt.so.0.
#
# We would, however, like the libvirt version number reflected
# in the so version'd symlinks, and this is based on AGE.REVISION
# eg libvirt.so.0.AGE.REVISION
#
# The following examples show what libtool will do
#
# Input: 0.9.14 -> libvirt.so.0.9.14
# Input: 1.0.0 -> libvirt.so.0.1000.0
# Input: 2.5.8 -> libvirt.so.0.2005.8
#
# Assuming we do ever want to break soname version, this can
# toggled. But seriously, don't ever touch this.
libvirt_so_version = 0
libvirt_age = 1000 * arr_version[0].to_int() + arr_version[1].to_int()
libvirt_revision = arr_version[2].to_int()
libvirt_lib_version = '@0@.@1@.@2@'.format(libvirt_so_version, libvirt_age, libvirt_revision)
# check compile flags
cc = meson.get_compiler('c')
cc_flags = []
git_werror = get_option('git_werror')
if (git_werror.enabled() or git_werror.auto()) and git and not get_option('werror')
cc_flags += [ '-Werror' ]
endif
# gcc --help=warnings outputs
ptrdiff_max = cc.sizeof('ptrdiff_t', prefix: '#include <stddef.h>')
size_max = cc.sizeof('size_t', prefix: '#include <stdint.h>')
# Compute max safe object size by checking ptrdiff_t and size_t sizes.
# Ideally we would get PTRDIFF_MAX and SIZE_MAX values but it would
# give us (2147483647L) and we would have to remove the () and the suffix
# in order to convert it to numbers to be able to pick the smaller one.
alloc_max = run_command(
'python3', '-c',
'print(min(2**(@0@ * 8 - 1) - 1, 2**(@1@ * 8) - 1))'.format(ptrdiff_max, size_max),
)
# sanitizer instrumentation may enlarge stack frames
stack_frame_size = get_option('b_sanitize') == 'none' ? 4096 : 32768
# array_bounds=2 check triggers false positive on some GCC
# versions when using sanitizers. Seen on Fedora 34 with
# GCC 11.1.1
array_bounds = get_option('b_sanitize') == 'none' ? 2 : 1
cc_flags += [
'-fasynchronous-unwind-tables',
'-fexceptions',
'-fipa-pure-const',
'-fno-common',
'-Wabsolute-value',
'-Waddress',
'-Waddress-of-packed-member',
'-Waggressive-loop-optimizations',
'-Walloc-size-larger-than=@0@'.format(alloc_max.stdout().strip()),
'-Walloca',
'-Warray-bounds=@0@'.format(array_bounds),
'-Wattribute-alias=2',
'-Wattribute-warning',
'-Wattributes',
'-Wbool-compare',
'-Wbool-operation',
'-Wbuiltin-declaration-mismatch',
'-Wbuiltin-macro-redefined',
'-Wcannot-profile',
'-Wcast-align',
'-Wcast-align=strict',
# We do "bad" function casts all the time for event callbacks
'-Wno-cast-function-type',
'-Wchar-subscripts',
'-Wclobbered',
'-Wcomment',
'-Wcomments',
'-Wcoverage-mismatch',
'-Wcpp',
'-Wdangling-else',
'-Wdate-time',
'-Wdeclaration-after-statement',
'-Wdeprecated-declarations',
'-Wdesignated-init',
'-Wdiscarded-array-qualifiers',
'-Wdiscarded-qualifiers',
'-Wdiv-by-zero',
'-Wduplicated-cond',
'-Wduplicate-decl-specifier',
'-Wempty-body',
'-Wendif-labels',
'-Wexpansion-to-defined',
'-Wformat-contains-nul',
'-Wformat-extra-args',
# -Wformat=2 implies -Wformat-nonliteral so we need to manually exclude it
'-Wno-format-nonliteral',
'-Wformat-overflow=2',
'-Wformat-security',
# -Wformat enables this by default, and we should keep it,
# but need to rewrite various areas of code first
'-Wno-format-truncation',
'-Wformat-y2k',
'-Wformat-zero-length',
'-Wframe-address',
'-Wframe-larger-than=@0@'.format(stack_frame_size),
'-Wfree-nonheap-object',
'-Whsa',
'-Wif-not-aligned',
'-Wignored-attributes',
'-Wignored-qualifiers',
'-Wimplicit',
'-Wimplicit-fallthrough=5',
'-Wimplicit-function-declaration',
'-Wimplicit-int',
'-Wincompatible-pointer-types',
'-Winit-self',
'-Winline',
'-Wint-conversion',
'-Wint-in-bool-context',
'-Wint-to-pointer-cast',
'-Winvalid-memory-model',
'-Winvalid-pch',
'-Wjump-misses-init',
'-Wlogical-not-parentheses',
'-Wlogical-op',
'-Wmain',
'-Wmaybe-uninitialized',
'-Wmemset-elt-size',
'-Wmemset-transposed-args',
'-Wmisleading-indentation',
'-Wmissing-attributes',
'-Wmissing-braces',
'-Wmissing-declarations',
'-Wmissing-field-initializers',
'-Wmissing-include-dirs',
'-Wmissing-parameter-type',
'-Wmissing-profile',
'-Wmissing-prototypes',
'-Wmultichar',
'-Wmultistatement-macros',
'-Wnarrowing',
'-Wnested-externs',
'-Wnonnull',
'-Wnonnull-compare',
'-Wnormalized=nfc',
'-Wnull-dereference',
'-Wodr',
'-Wold-style-declaration',
'-Wold-style-definition',
'-Wopenmp-simd',
'-Woverflow',
'-Woverride-init',
'-Wpacked-bitfield-compat',
'-Wpacked-not-aligned',
'-Wparentheses',
'-Wpointer-arith',
'-Wpointer-compare',
'-Wpointer-sign',
'-Wpointer-to-int-cast',
'-Wpragmas',
'-Wpsabi',
'-Wrestrict',
'-Wreturn-local-addr',
'-Wreturn-type',
'-Wscalar-storage-order',
'-Wsequence-point',
'-Wshadow',
'-Wshift-count-negative',
'-Wshift-count-overflow',
'-Wshift-negative-value',
'-Wshift-overflow=2',
# So we have -W enabled, and then have to explicitly turn off...
'-Wno-sign-compare',
'-Wsizeof-array-argument',
'-Wsizeof-pointer-div',
'-Wsizeof-pointer-memaccess',
'-Wstrict-aliasing',
'-Wstrict-prototypes',
'-Wstringop-overflow=2',
'-Wstringop-truncation',
'-Wsuggest-attribute=cold',
'-Wno-suggest-attribute=const',
'-Wsuggest-attribute=format',
'-Wsuggest-attribute=noreturn',
'-Wno-suggest-attribute=pure',
'-Wsuggest-final-methods',
'-Wsuggest-final-types',
'-Wswitch',
'-Wswitch-bool',
'-Wswitch-enum',
'-Wswitch-unreachable',
'-Wsync-nand',
'-Wtautological-compare',
'-Wtrampolines',
'-Wtrigraphs',
'-Wtype-limits',
# Clang incorrectly complains about dup typedefs win gnu99 mode
# so use this Clang-specific arg to keep it quiet
'-Wno-typedef-redefinition',
'-Wuninitialized',
'-Wunknown-pragmas',
'-Wunused',
'-Wunused-but-set-parameter',
'-Wunused-but-set-variable',
'-Wunused-const-variable=2',
'-Wunused-function',
'-Wunused-label',
'-Wunused-local-typedefs',
'-Wunused-parameter',
'-Wunused-result',
'-Wunused-value',
'-Wunused-variable',
'-Wvarargs',
'-Wvariadic-macros',
'-Wvector-operation-performance',
'-Wvla',
'-Wvolatile-register-var',
'-Wwrite-strings',
]
supported_cc_flags = []
if get_option('warning_level') == '2'
supported_cc_flags = cc.get_supported_arguments(cc_flags)
# on aarch64 error: -fstack-protector not supported for this target
if host_machine.cpu_family() != 'aarch64'
if host_machine.system() in [ 'linux', 'freebsd', 'windows' ]
# we prefer -fstack-protector-strong but fallback to -fstack-protector-all
fstack_cflags = cc.first_supported_argument([
'-fstack-protector-strong',
'-fstack-protector-all',
])
supported_cc_flags += fstack_cflags
# When building with mingw using -fstack-protector requires libssp library
# which is included by using -fstack-protector with linker.
if fstack_cflags.length() == 1 and host_machine.system() == 'windows'
add_project_link_arguments(fstack_cflags, language: 'c')
endif
endif
endif
if supported_cc_flags.contains('-Wlogical-op')
# Broken in 6.0 and later
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602
w_logical_op_args = [ '-O2', '-Wlogical-op', '-Werror' ]
w_logical_op_code = '''
#define TEST1 1
#define TEST2 TEST1
int main(void) {
int test = 0;
return test == TEST1 || test == TEST2;
}
'''
if not cc.compiles(w_logical_op_code, args: w_logical_op_args)
conf.set('BROKEN_GCC_WLOGICALOP_EQUAL_EXPR', 1)
endif
endif
# Check whether clang gives bogus warning for -Wdouble-promotion.
w_double_promotion_args = [ '-O2', '-Wdouble-promotion', '-Werror' ]
w_double_promotion_code = '''
#include <math.h>
int main(void) {
float f = 0.0;
return isnan(f);
}
'''
if cc.compiles(w_double_promotion_code, args: w_double_promotion_args, name: '-Wdouble-promotion')
supported_cc_flags += [ '-Wdouble-promotion' ]
endif
# Clang complains about unused static inline functions which are common
# with G_DEFINE_AUTOPTR_CLEANUP_FUNC.
w_unused_function_args = [ '-Wunused-function', '-Werror' ]
w_unused_function_code = '''
static inline void foo(void) {}
int main(void) { return 0; }
'''
# -Wunused-function is implied by -Wall, we must turn it off explicitly.
if not cc.compiles(w_unused_function_code, args: w_unused_function_args)
supported_cc_flags += [ '-Wno-unused-function' ]
endif
endif
add_project_arguments(supported_cc_flags, language: 'c')
if cc.has_argument('-Wsuggest-attribute=format')
conf.set('WITH_SUGGEST_ATTRIBUTE_FORMAT', 1)
endif
# used in tests
cc_flags_relaxed_frame_limit = []
if cc.has_argument('-Wframe-larger-than=262144')
cc_flags_relaxed_frame_limit += [
'-Wframe-larger-than=262144',
]
endif
# various linker checks
libvirt_relro = cc.get_supported_link_arguments([
'-Wl,-z,relro',
'-Wl,-z,now',
])
libvirt_nodelete = cc.get_supported_link_arguments([
'-Wl,-z,nodelete',
])
libvirt_no_undefined = []
if get_option('b_sanitize') == 'none'
libvirt_no_undefined += cc.get_supported_link_arguments([
'-Wl,-z,defs',
])
endif
libvirt_no_indirect = cc.get_supported_link_arguments([
'-Wl,--no-copy-dt-needed-entries',
])
if host_machine.system() == 'windows'
version_script_flags = '-Wl,'
else
test_file = '@0@/src/libvirt_qemu.syms'.format(meson.source_root())
if cc.has_link_argument('-Wl,--version-script=@0@'.format(test_file))
version_script_flags = '-Wl,--version-script='
elif cc.has_link_argument('-Wl,-M,')
version_script_flags = '-Wl,-M,'
else
error('No supported version script link argument found.')
endif
endif
libvirt_flat_namespace = []
if host_machine.system() == 'darwin'
libvirt_flat_namespace = '-Wl,-flat_namespace'
endif
libvirt_export_dynamic = cc.first_supported_link_argument([
'-Wl,-export-dynamic',
'-Wl,-export_dynamic',
])
# check availability of various common functions (non-fatal if missing)
functions = [
'elf_aux_info',
'fallocate',
'getauxval',
'getegid',
'geteuid',
'getgid',
'getifaddrs',
'getmntent_r',
'getpwuid_r',
'getrlimit',
'getuid',
'getutxid',
'if_indextoname',
'mmap',
'newlocale',
'pipe2',
'posix_fallocate',
'posix_memalign',
'prlimit',
'sched_setscheduler',
'setgroups',
'setns',
'setrlimit',
'symlink',
'sysctlbyname',
]
stat_functions = [
'__lxstat',
'__lxstat64',
'__xstat',
'__xstat64',
'lstat',
'lstat64',
'stat',
'stat64',
]
functions += stat_functions
foreach function : functions
if cc.has_function(function)
conf.set('WITH_@0@'.format(function.to_upper()), 1)
endif
endforeach
foreach function : stat_functions
if cc.has_header_symbol('sys/stat.h', function)
conf.set('WITH_@0@_DECL'.format(function.to_upper()), 1)
endif
endforeach
# various header checks
headers = [
'asm/hwcap.h',
'ifaddrs.h',
'libtasn1.h',
'linux/kvm.h',
'linux/magic.h',
'mntent.h',
'net/ethernet.h',
'net/if.h',
'pty.h',
'pwd.h',
'sched.h',
'sys/auxv.h',
'sys/ioctl.h',
'sys/mount.h',
'sys/syscall.h',
'sys/ucred.h',
'syslog.h',
'util.h',
'xlocale.h',
]
if host_machine.system() == 'linux'
# check for kernel headers required by btrfs ioctl
headers += 'linux/btrfs.h'
# check for xfs dev headers required by xfs ioctl
headers += 'xfs/xfs.h'
# check for DEVLINK_CMD_ESWITCH_GET
headers += 'linux/devlink.h'
endif
if host_machine.system() == 'freebsd'
headers += 'libutil.h'
endif
foreach name : headers
if cc.has_header(name)
conf.set('WITH_@0@'.format(name.underscorify().to_upper()), 1)
endif
endforeach
# check for kernel headers required by src/util/virnetdevbridge.c
if host_machine.system() == 'linux'
required_headers = [
'linux/param.h',
'linux/sockios.h',
'linux/if_bridge.h',
'linux/if_tun.h',
]
foreach name : required_headers
if not cc.has_header(name)
error('You must install kernel-headers in order to compile libvirt with QEMU or LXC support')
endif
endforeach
endif
# check various symbols
symbols = [
# Check whether endian provides handy macros.
[ 'endian.h', 'htole64' ],
[ 'linux/ethtool.h', 'ETH_FLAG_TXVLAN' ],
[ 'linux/ethtool.h', 'ETH_FLAG_NTUPLE' ],
[ 'linux/ethtool.h', 'ETH_FLAG_RXHASH' ],
[ 'linux/ethtool.h', 'ETH_FLAG_LRO' ],
[ 'linux/ethtool.h', 'ETHTOOL_GGSO' ],
[ 'linux/ethtool.h', 'ETHTOOL_GGRO' ],
[ 'linux/ethtool.h', 'ETHTOOL_GFLAGS' ],
[ 'linux/ethtool.h', 'ETHTOOL_GFEATURES' ],
[ 'linux/ethtool.h', 'ETHTOOL_SCOALESCE' ],
[ 'linux/ethtool.h', 'ETHTOOL_GCOALESCE' ],
# GET_VLAN_VID_CMD is required for virNetDevGetVLanID
[ 'linux/if_vlan.h', 'GET_VLAN_VID_CMD' ],
[ 'unistd.h', 'SEEK_HOLE' ],
# Check for BSD approach for setting MAC addr
[ 'net/if_dl.h', 'link_addr', '#include <sys/types.h>\n#include <sys/socket.h>' ],
[ 'sched.h', 'cpu_set_t' ],
]
if host_machine.system() == 'linux'
symbols += [
# check for DEVLINK_CMD_ESWITCH_GET
# Assume DEVLINK_ESWITCH_MODE_SWITCHDEV is also available, as it was
# introudced in kernel 4.8 along with the original spelling of this
# constant (DEVLINK_CMD_ESWITCH_MODE_GET, not supported by libvirt).
[ 'linux/devlink.h', 'DEVLINK_CMD_ESWITCH_GET' ],
# check for VHOST_VSOCK_SET_GUEST_CID
[ 'linux/vhost.h', 'VHOST_VSOCK_SET_GUEST_CID' ],
# Check if we have new enough kernel to support BPF devices for cgroups v2
[ 'linux/bpf.h', 'BPF_PROG_QUERY' ],
[ 'linux/bpf.h', 'BPF_CGROUP_DEVICE' ],
]
endif
foreach symbol : symbols
if cc.has_header_symbol(symbol[0], symbol[1], args: '-D_GNU_SOURCE', prefix: symbol.get(2, ''))
conf.set('WITH_DECL_@0@'.format(symbol[1].to_upper()), 1)
endif
endforeach
# Check for BSD approach for bridge management
brd_required_headers = '''#include <stdint.h>
#include <net/if.h>
#include <net/ethernet.h>'''
if (cc.has_header_symbol('net/if_bridgevar.h', 'BRDGSFD', prefix: brd_required_headers) and
cc.has_header_symbol('net/if_bridgevar.h', 'BRDGADD', prefix: brd_required_headers) and
cc.has_header_symbol('net/if_bridgevar.h', 'BRDGDEL', prefix: brd_required_headers))
conf.set('WITH_BSD_BRIDGE_MGMT', 1)
endif
# Check for BSD CPU affinity availability
if cc.has_header_symbol('sys/cpuset.h', 'cpuset_getaffinity', prefix: '#include <sys/param.h>')
conf.set('WITH_BSD_CPU_AFFINITY', 1)
endif
# whether Mach clock routines are available
if (cc.has_header_symbol('mach/clock.h', 'clock_serv_t') and
cc.has_header_symbol('mach/clock.h', 'host_get_clock_service') and
cc.has_header_symbol('mach/clock.h', 'clock_get_time'))
conf.set('WITH_MACH_CLOCK_ROUTINES', 1)
endif
# check various types
types = [
[ 'struct ifreq', '#include <sys/socket.h>\n#include <net/if.h>'] ,
[ 'struct sockpeercred', '#include <sys/socket.h' ],
]
foreach type : types
if cc.has_type(type[0], prefix: type[1])
name = type[0].underscorify().to_upper()
conf.set('WITH_@0@'.format(name), 1)
endif
endforeach
if host_machine.system() == 'windows'
uid_types = [
'uid_t',
'gid_t',
]
foreach type : uid_types
if not cc.has_type(type, prefix: '#include <sys/types.h>')
conf.set(type, 'int')
endif
endforeach
endif
# check various members
members = [
# Check for Linux vs. BSD ifreq members
[ 'struct ifreq', 'ifr_newname', '#include <sys/socket.h>\n#include <net/if.h>' ],
[ 'struct ifreq', 'ifr_ifindex', '#include <sys/socket.h>\n#include <net/if.h>' ],
[ 'struct ifreq', 'ifr_index', '#include <sys/socket.h>\n#include <net/if.h>' ],
[ 'struct ifreq', 'ifr_hwaddr', '#include <sys/socket.h>\n#include <net/if.h>' ],
]
foreach member : members
if cc.has_member(member[0], member[1], prefix: member[2])
type = member[0].underscorify().to_upper()
member = member[1].underscorify().to_upper()
conf.set('WITH_@0@_@1@'.format(type, member), 1)
endif
endforeach
# check various types sizeof
conf.set('SIZEOF_LONG', cc.sizeof('long'))
# Where we look for daemons and admin binaries during configure
libvirt_sbin_path = [
'/sbin',
'/usr/sbin',
'/usr/local/sbin',
]
# required programs check
required_programs = [
'perl',
'python3',
'xmllint',
'xsltproc',
]
required_programs_groups = [
{ 'name': 'rpcgen', 'prog': [ 'rpcgen', 'portable-rpcgen' ] },
{ 'name': 'rst2html5', 'prog': [ 'rst2html5', 'rst2html5.py', 'rst2html5-3' ] },
{ 'name': 'rst2man', 'prog': [ 'rst2man', 'rst2man.py', 'rst2man-3' ] },
]
if host_machine.system() == 'freebsd'
required_programs += 'ifconfig'
endif
foreach name : required_programs
prog = find_program(name, dirs: libvirt_sbin_path)
varname = name.underscorify()
conf.set_quoted(varname.to_upper(), prog.path())
set_variable('@0@_prog'.format(varname), prog)
endforeach
foreach item : required_programs_groups
prog = find_program(item.get('prog'), dirs: libvirt_sbin_path)
varname = item.get('name').underscorify()
conf.set_quoted(varname.to_upper(), prog.path())
set_variable('@0@_prog'.format(varname), prog)
endforeach
# There are two versions of rst2html5 in the wild: one is the version
# coming from the docutils package, and the other is the one coming
# from the rst2html5 package. These versions are subtly different,
# and the libvirt documentation can only be successfully generated
# using the docutils version. Every now and then, users will report
# build failures that can be traced back to having the wrong version
# installed.
#
# The only reliable way to tell the two binaries apart seems to be
# looking look at their version information: the docutils version
# will report
#
# rst2html5 (Docutils ..., Python ..., on ...)
#
# whereas the rst2html5 version will report
#
# rst2html5 ... (Docutils ..., Python ..., on ...)
#
# with the additional bit of information being the version number for
# the rst2html5 package itself.
#
# Use this knowledge to detect the version that we know doesn't work
# for building libvirt and reject it
rst2html5_version = run_command(rst2html5_prog, '--version')
rst2html5_version = rst2html5_version.stdout().split(' ')
if rst2html5_version[1] != '(Docutils'
error('Please uninstall the rst2html5 package and install the docutils package')
endif
# optional programs
optional_programs = [
'augparse',
'dmidecode',
'dnsmasq',
'ebtables',
'flake8',
'ip',
'ip6tables',
'iptables',
'iscsiadm',
'mdevctl',
'mm-ctl',
'modprobe',
'ovs-vsctl',
'pdwtags',
'radvd',
'rmmod',
'scrub',
'tc',
'udevadm',
]
foreach name : optional_programs
prog = find_program(name, required: false, dirs: libvirt_sbin_path)
varname = name.underscorify()
if prog.found()
prog_path = prog.path()
else
prog_path = name
endif
conf.set_quoted(varname.to_upper(), prog_path)
set_variable('@0@_prog'.format(varname), prog)
endforeach
# early checks where lot of other packages depend on the result
# On MinGW portablexdr provides XDR functions, on linux they are
# provided by libtirpc and on FreeBSD/macOS there is no need to
# use extra library as it's provided by libc directly.
if host_machine.system() == 'windows'
xdr_dep = cc.find_library('portablexdr', required: false)
elif host_machine.system() == 'linux'
xdr_dep = dependency('libtirpc', required: false)
elif host_machine.system() in [ 'freebsd', 'darwin' ]
xdr_dep = cc.find_library('c', required: false)
else
xdr_dep = dependency('', required: false)
endif
if not get_option('driver_remote').disabled()
use_remote = true
if not xdr_dep.found()
use_remote = false
if get_option('driver_remote').enabled()
error('XDR is required for remote driver')
endif
endif
if use_remote
conf.set('WITH_REMOTE', 1)
endif
endif
# generic build dependencies
# FIXME rewrite to use dependency()
acl_dep = cc.find_library('acl', required: false)
if acl_dep.found()
conf.set('WITH_LIBACL', 1)
endif
apparmor_dep = dependency('libapparmor', required: get_option('apparmor'))
if apparmor_dep.found()
conf.set('WITH_APPARMOR', 1)
conf.set_quoted('APPARMOR_DIR', sysconfdir / 'apparmor.d')
conf.set_quoted('APPARMOR_PROFILES_PATH', '/sys/kernel/security/apparmor/profiles')
endif
if not get_option('apparmor_profiles').disabled()
apparmor_profiles_enable = true
if not conf.has('WITH_APPARMOR')
apparmor_profiles_enable = false
if get_option('apparmor_profiles').enabled()
error('Cannot enable apparmor_profiles without apparmor')
endif
endif
if apparmor_profiles_enable
conf.set('WITH_APPARMOR_PROFILES', 1)
endif
endif
# FIXME rewrite to use dependency() once we can use 2.4.48
attr_dep = cc.find_library('attr', required: get_option('attr'))
if attr_dep.found()
conf.set('WITH_LIBATTR', 1)
endif
audit_dep = dependency('audit', required: get_option('audit'))
if audit_dep.found()
conf.set('WITH_AUDIT', 1)
endif
bash_completion_version = '2.0'
bash_completion_dep = dependency('bash-completion', version: '>=' + bash_completion_version, required: get_option('bash_completion'))
blkid_version = '2.17'
blkid_dep = dependency('blkid', version: '>=' + blkid_version, required: get_option('blkid'))
if blkid_dep.found()
conf.set('WITH_BLKID', 1)
endif
capng_dep = dependency('libcap-ng', required: get_option('capng'))
if capng_dep.found()
conf.set('WITH_CAPNG', 1)
endif
curl_version = '7.19.1'
curl_dep = dependency('libcurl', version: '>=' + curl_version, required: get_option('curl'))
if curl_dep.found()
conf.set('WITH_CURL', 1)
endif
devmapper_version = '1.0.0'
devmapper_dep = dependency('devmapper', version: '>=' + devmapper_version, required: false)
if devmapper_dep.found()
conf.set('WITH_DEVMAPPER', 1)
endif
dlopen_use = host_machine.system() != 'windows'
dlopen_dep = cc.find_library('dl', required: dlopen_use)
if dlopen_dep.found()
if not cc.has_header('dlfcn.h')
error('Unable to find dlfcn.h')
endif
conf.set('WITH_DLFCN_H', 1)
endif
fuse_version = '2.8.6'
fuse_dep = dependency('fuse', version: '>=' + fuse_version, required: get_option('fuse'))
if fuse_dep.found()
conf.set('WITH_FUSE', 1)
endif
glib_version = '2.56.0'
glib_dep = dependency('glib-2.0', version: '>=' + glib_version)
gobject_dep = dependency('gobject-2.0', version: '>=' + glib_version)
if host_machine.system() == 'windows'