-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
3772 lines (3112 loc) · 113 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
# Copyright (c) 2022-2024, PostgreSQL Global Development Group
# Entry point for building PostgreSQL with meson
#
# Good starting points for writing meson.build files are:
# - https://mesonbuild.com/Syntax.html
# - https://mesonbuild.com/Reference-manual.html
project('postgresql',
['c'],
version: '17.0',
license: 'PostgreSQL',
# We want < 0.56 for python 3.5 compatibility on old platforms. EPEL for
# RHEL 7 has 0.55. < 0.54 would require replacing some uses of the fs
# module, < 0.53 all uses of fs. So far there's no need to go to >=0.56.
meson_version: '>=0.54',
default_options: [
'warning_level=1', #-Wall equivalent
'b_pch=false',
'buildtype=debugoptimized', # -O2 + debug
# For compatibility with the autoconf build, set a default prefix. This
# works even on windows, where it's a drive-relative path (i.e. when on
# d:/somepath it'll install to d:/usr/local/pgsql)
'prefix=/usr/local/pgsql',
]
)
###############################################################
# Basic prep
###############################################################
fs = import('fs')
pkgconfig = import('pkgconfig')
host_system = host_machine.system()
build_system = build_machine.system()
host_cpu = host_machine.cpu_family()
cc = meson.get_compiler('c')
not_found_dep = dependency('', required: false)
thread_dep = dependency('threads')
auto_features = get_option('auto_features')
###############################################################
# Safety first
###############################################################
# It's very easy to get into confusing states when the source directory
# contains an in-place build. E.g. the wrong pg_config.h will be used. So just
# refuse to build in that case.
#
# There's a more elaborate check later, that checks for conflicts around all
# generated files. But we can only do that much further down the line, so this
# quick check seems worth it. Adhering to this advice should clean up the
# conflict, but won't protect against somebody doing make distclean or just
# removing pg_config.h
errmsg_nonclean_base = '''
****
Non-clean source code directory detected.
To build with meson the source tree may not have an in-place, ./configure
style, build configured. You can have both meson and ./configure style builds
for the same source tree by building out-of-source / VPATH with
configure. Alternatively use a separate check out for meson based builds.
@0@
****'''
if fs.exists(meson.current_source_dir() / 'src' / 'include' / 'pg_config.h')
errmsg_cleanup = 'To clean up, run make distclean in the source tree.'
error(errmsg_nonclean_base.format(errmsg_cleanup))
endif
###############################################################
# Variables to be determined
###############################################################
postgres_inc_d = ['src/include']
postgres_inc_d += get_option('extra_include_dirs')
postgres_lib_d = get_option('extra_lib_dirs')
cppflags = []
cflags = []
cxxflags = []
cflags_warn = []
cxxflags_warn = []
cflags_mod = []
cxxflags_mod = []
ldflags = []
ldflags_be = []
ldflags_sl = []
ldflags_mod = []
test_c_args = []
os_deps = []
backend_both_deps = []
backend_deps = []
libpq_deps = []
pg_sysroot = ''
# source of data for pg_config.h etc
cdata = configuration_data()
###############################################################
# Version and other metadata
###############################################################
pg_version = meson.project_version()
if pg_version.endswith('devel')
pg_version_arr = [pg_version.split('devel')[0], '0']
elif pg_version.contains('beta')
pg_version_arr = [pg_version.split('beta')[0], '0']
elif pg_version.contains('rc')
pg_version_arr = [pg_version.split('rc')[0], '0']
else
pg_version_arr = pg_version.split('.')
endif
pg_version_major = pg_version_arr[0].to_int()
pg_version_minor = pg_version_arr[1].to_int()
pg_version_num = (pg_version_major * 10000) + pg_version_minor
pg_url = 'https://www.postgresql.org/'
cdata.set_quoted('PACKAGE_NAME', 'PostgreSQL')
cdata.set_quoted('PACKAGE_BUGREPORT', '[email protected]')
cdata.set_quoted('PACKAGE_URL', pg_url)
cdata.set_quoted('PACKAGE_VERSION', pg_version)
cdata.set_quoted('PACKAGE_STRING', 'PostgreSQL @0@'.format(pg_version))
cdata.set_quoted('PACKAGE_TARNAME', 'postgresql')
pg_version += get_option('extra_version')
cdata.set_quoted('PG_VERSION', pg_version)
cdata.set_quoted('PG_MAJORVERSION', pg_version_major.to_string())
cdata.set('PG_MAJORVERSION_NUM', pg_version_major)
cdata.set('PG_MINORVERSION_NUM', pg_version_minor)
cdata.set('PG_VERSION_NUM', pg_version_num)
# PG_VERSION_STR is built later, it depends on compiler test results
cdata.set_quoted('CONFIGURE_ARGS', '')
###############################################################
# Basic platform specific configuration
###############################################################
exesuffix = '' # overridden below where necessary
dlsuffix = '.so' # overridden below where necessary
library_path_var = 'LD_LIBRARY_PATH'
# Format of file to control exports from libraries, and how to pass them to
# the compiler. For export_fmt @0@ is the path to the file export file.
export_file_format = 'gnu'
export_file_suffix = 'list'
export_fmt = '-Wl,--version-script=@0@'
# Flags to add when linking a postgres extension, @0@ is path to
# the relevant object on the platform.
mod_link_args_fmt = []
memset_loop_limit = 1024
# Choice of shared memory and semaphore implementation
shmem_kind = 'sysv'
sema_kind = 'sysv'
# We implement support for some operating systems by pretending they're
# another. Map here, before determining system properties below
if host_system == 'dragonfly'
# apparently the most similar
host_system = 'netbsd'
elif host_system == 'android'
# while android isn't quite a normal linux, it seems close enough
# for our purposes so far
host_system = 'linux'
endif
# meson's system names don't quite map to our "traditional" names. In some
# places we need the "traditional" name, e.g., for mapping
# src/include/port/$os.h to src/include/pg_config_os.h. Define portname for
# that purpose.
portname = host_system
if host_system == 'cygwin'
sema_kind = 'unnamed_posix'
cppflags += '-D_GNU_SOURCE'
dlsuffix = '.dll'
mod_link_args_fmt = ['@0@']
mod_link_with_name = 'lib@[email protected]'
mod_link_with_dir = 'libdir'
elif host_system == 'darwin'
dlsuffix = '.dylib'
library_path_var = 'DYLD_LIBRARY_PATH'
export_file_format = 'darwin'
export_fmt = '-Wl,-exported_symbols_list,@0@'
mod_link_args_fmt = ['-bundle_loader', '@0@']
mod_link_with_dir = 'bindir'
mod_link_with_name = '@0@'
sysroot_args = [files('src/tools/darwin_sysroot'), get_option('darwin_sysroot')]
pg_sysroot = run_command(sysroot_args, check:true).stdout().strip()
message('darwin sysroot: @0@'.format(pg_sysroot))
if pg_sysroot != ''
cflags += ['-isysroot', pg_sysroot]
ldflags += ['-isysroot', pg_sysroot]
endif
# meson defaults to -Wl,-undefined,dynamic_lookup for modules, which we
# don't want because a) it's different from what we do for autoconf, b) it
# causes warnings in macOS Ventura. But using -Wl,-undefined,error causes a
# warning starting in Sonoma. So only add -Wl,-undefined,error if it does
# not cause a warning.
if cc.has_multi_link_arguments('-Wl,-undefined,error', '-Werror')
ldflags_mod += '-Wl,-undefined,error'
endif
# Starting in Sonoma, the linker warns about the same library being
# linked twice. Which can easily happen when multiple dependencies
# depend on the same library. Quiesce the ill considered warning.
ldflags += cc.get_supported_link_arguments('-Wl,-no_warn_duplicate_libraries')
elif host_system == 'freebsd'
sema_kind = 'unnamed_posix'
elif host_system == 'linux'
sema_kind = 'unnamed_posix'
cppflags += '-D_GNU_SOURCE'
elif host_system == 'netbsd'
# We must resolve all dynamic linking in the core server at program start.
# Otherwise the postmaster can self-deadlock due to signals interrupting
# resolution of calls, since NetBSD's linker takes a lock while doing that
# and some postmaster signal handlers do things that will also acquire that
# lock. As long as we need "-z now", might as well specify "-z relro" too.
# While there's not a hard reason to adopt these settings for our other
# executables, there's also little reason not to, so just add them to
# LDFLAGS.
ldflags += ['-Wl,-z,now', '-Wl,-z,relro']
elif host_system == 'openbsd'
# you're ok
elif host_system == 'sunos'
portname = 'solaris'
export_fmt = '-Wl,-M@0@'
cppflags += '-D_POSIX_PTHREAD_SEMANTICS'
elif host_system == 'windows'
portname = 'win32'
exesuffix = '.exe'
dlsuffix = '.dll'
library_path_var = ''
export_file_format = 'win'
export_file_suffix = 'def'
if cc.get_id() == 'msvc'
export_fmt = '/DEF:@0@'
mod_link_with_name = '@[email protected]'
else
export_fmt = '@0@'
mod_link_with_name = 'lib@[email protected]'
endif
mod_link_args_fmt = ['@0@']
mod_link_with_dir = 'libdir'
shmem_kind = 'win32'
sema_kind = 'win32'
cdata.set('WIN32_STACK_RLIMIT', 4194304)
if cc.get_id() == 'msvc'
ldflags += '/INCREMENTAL:NO'
ldflags += '/STACK:@0@'.format(cdata.get('WIN32_STACK_RLIMIT'))
# ldflags += '/nxcompat' # generated by msbuild, should have it for ninja?
else
ldflags += '-Wl,--stack,@0@'.format(cdata.get('WIN32_STACK_RLIMIT'))
# Need to allow multiple definitions, we e.g. want to override getopt.
ldflags += '-Wl,--allow-multiple-definition'
# Ensure we get MSVC-like linking behavior.
ldflags += '-Wl,--disable-auto-import'
endif
os_deps += cc.find_library('ws2_32', required: true)
secur32_dep = cc.find_library('secur32', required: true)
backend_deps += secur32_dep
libpq_deps += secur32_dep
postgres_inc_d += 'src/include/port/win32'
if cc.get_id() == 'msvc'
postgres_inc_d += 'src/include/port/win32_msvc'
endif
windows = import('windows')
else
# XXX: Should we add an option to override the host_system as an escape
# hatch?
error('unknown host system: @0@'.format(host_system))
endif
###############################################################
# Program paths
###############################################################
# External programs
perl = find_program(get_option('PERL'), required: true, native: true)
python = find_program(get_option('PYTHON'), required: true, native: true)
flex = find_program(get_option('FLEX'), native: true, version: '>= 2.5.35')
bison = find_program(get_option('BISON'), native: true, version: '>= 2.3')
sed = find_program(get_option('SED'), 'sed', native: true, required: false)
prove = find_program(get_option('PROVE'), native: true, required: false)
tar = find_program(get_option('TAR'), native: true, required: false)
gzip = find_program(get_option('GZIP'), native: true, required: false)
program_lz4 = find_program(get_option('LZ4'), native: true, required: false)
openssl = find_program(get_option('OPENSSL'), native: true, required: false)
program_zstd = find_program(get_option('ZSTD'), native: true, required: false)
dtrace = find_program(get_option('DTRACE'), native: true, required: get_option('dtrace'))
missing = find_program('config/missing', native: true)
cp = find_program('cp', required: false, native: true)
xmllint_bin = find_program(get_option('XMLLINT'), native: true, required: false)
xsltproc_bin = find_program(get_option('XSLTPROC'), native: true, required: false)
bison_flags = []
if bison.found()
bison_version_c = run_command(bison, '--version', check: true)
# bison version string helpfully is something like
# >>bison (GNU bison) 3.8.1<<
bison_version = bison_version_c.stdout().split(' ')[3].split('\n')[0]
if bison_version.version_compare('>=3.0')
bison_flags += ['-Wno-deprecated']
endif
endif
bison_cmd = [bison, bison_flags, '-o', '@OUTPUT0@', '-d', '@INPUT@']
bison_kw = {
'output': ['@[email protected]', '@[email protected]'],
'command': bison_cmd,
}
flex_flags = []
if flex.found()
flex_version_c = run_command(flex, '--version', check: true)
flex_version = flex_version_c.stdout().split(' ')[1].split('\n')[0]
endif
flex_wrapper = files('src/tools/pgflex')
flex_cmd = [python, flex_wrapper,
'--builddir', '@BUILD_ROOT@',
'--srcdir', '@SOURCE_ROOT@',
'--privatedir', '@PRIVATE_DIR@',
'--flex', flex, '--perl', perl,
'-i', '@INPUT@', '-o', '@OUTPUT0@',
]
wget = find_program('wget', required: false, native: true)
wget_flags = ['-O', '@OUTPUT0@', '--no-use-server-timestamps']
install_files = files('src/tools/install_files')
###############################################################
# Path to meson (for tests etc)
###############################################################
# NB: this should really be part of meson, see
# https://github.com/mesonbuild/meson/issues/8511
meson_binpath_r = run_command(python, 'src/tools/find_meson', check: true)
if meson_binpath_r.stdout() == ''
error('huh, could not run find_meson.\nerrcode: @0@\nstdout: @1@\nstderr: @2@'.format(
meson_binpath_r.returncode(),
meson_binpath_r.stdout(),
meson_binpath_r.stderr()))
endif
meson_binpath_s = meson_binpath_r.stdout().split('\n')
meson_binpath_len = meson_binpath_s.length()
if meson_binpath_len < 1
error('unexpected introspect line @0@'.format(meson_binpath_r.stdout()))
endif
i = 0
meson_impl = ''
meson_binpath = ''
meson_args = []
foreach e : meson_binpath_s
if i == 0
meson_impl = e
elif i == 1
meson_binpath = e
else
meson_args += e
endif
i += 1
endforeach
if meson_impl not in ['muon', 'meson']
error('unknown meson implementation "@0@"'.format(meson_impl))
endif
meson_bin = find_program(meson_binpath, native: true)
###############################################################
# Option Handling
###############################################################
cdata.set('USE_ASSERT_CHECKING', get_option('cassert') ? 1 : false)
cdata.set('USE_INJECTION_POINTS', get_option('injection_points') ? 1 : false)
blocksize = get_option('blocksize').to_int() * 1024
if get_option('segsize_blocks') != 0
if get_option('segsize') != 1
warning('both segsize and segsize_blocks specified, segsize_blocks wins')
endif
segsize = get_option('segsize_blocks')
else
segsize = (get_option('segsize') * 1024 * 1024 * 1024) / blocksize
endif
cdata.set('BLCKSZ', blocksize, description:
'''Size of a disk block --- this also limits the size of a tuple. You can set
it bigger if you need bigger tuples (although TOAST should reduce the need
to have large tuples, since fields can be spread across multiple tuples).
BLCKSZ must be a power of 2. The maximum possible value of BLCKSZ is
currently 2^15 (32768). This is determined by the 15-bit widths of the
lp_off and lp_len fields in ItemIdData (see include/storage/itemid.h).
Changing BLCKSZ requires an initdb.''')
cdata.set('XLOG_BLCKSZ', get_option('wal_blocksize').to_int() * 1024)
cdata.set('RELSEG_SIZE', segsize)
cdata.set('DEF_PGPORT', get_option('pgport'))
cdata.set_quoted('DEF_PGPORT_STR', get_option('pgport').to_string())
cdata.set_quoted('PG_KRB_SRVNAM', get_option('krb_srvnam'))
if get_option('system_tzdata') != ''
cdata.set_quoted('SYSTEMTZDIR', get_option('system_tzdata'))
endif
###############################################################
# Directories
###############################################################
# These are set by the equivalent --xxxdir configure options. We
# append "postgresql" to some of them, if the string does not already
# contain "pgsql" or "postgres", in order to avoid directory clutter.
pkg = 'postgresql'
dir_prefix = get_option('prefix')
dir_prefix_contains_pg = (dir_prefix.contains('pgsql') or dir_prefix.contains('postgres'))
dir_bin = get_option('bindir')
dir_data = get_option('datadir')
if not (dir_prefix_contains_pg or dir_data.contains('pgsql') or dir_data.contains('postgres'))
dir_data = dir_data / pkg
endif
dir_sysconf = get_option('sysconfdir')
if not (dir_prefix_contains_pg or dir_sysconf.contains('pgsql') or dir_sysconf.contains('postgres'))
dir_sysconf = dir_sysconf / pkg
endif
dir_lib = get_option('libdir')
dir_lib_pkg = dir_lib
if not (dir_prefix_contains_pg or dir_lib_pkg.contains('pgsql') or dir_lib_pkg.contains('postgres'))
dir_lib_pkg = dir_lib_pkg / pkg
endif
dir_pgxs = dir_lib_pkg / 'pgxs'
dir_include = get_option('includedir')
dir_include_pkg = dir_include
dir_include_pkg_rel = ''
if not (dir_prefix_contains_pg or dir_include_pkg.contains('pgsql') or dir_include_pkg.contains('postgres'))
dir_include_pkg = dir_include_pkg / pkg
dir_include_pkg_rel = pkg
endif
dir_man = get_option('mandir')
# FIXME: These used to be separately configurable - worth adding?
dir_doc = get_option('datadir') / 'doc'
if not (dir_prefix_contains_pg or dir_doc.contains('pgsql') or dir_doc.contains('postgres'))
dir_doc = dir_doc / pkg
endif
dir_doc_html = dir_doc / 'html'
dir_locale = get_option('localedir')
# Derived values
dir_bitcode = dir_lib_pkg / 'bitcode'
dir_include_internal = dir_include_pkg / 'internal'
dir_include_server = dir_include_pkg / 'server'
dir_include_extension = dir_include_server / 'extension'
dir_data_extension = dir_data / 'extension'
dir_doc_extension = dir_doc / 'extension'
###############################################################
# Search paths, preparation for compiler tests
#
# NB: Arguments added later are not automatically used for subsequent
# configuration-time checks (so they are more isolated). If they should be
# used, they need to be added to test_c_args as well.
###############################################################
postgres_inc = [include_directories(postgres_inc_d)]
test_lib_d = postgres_lib_d
test_c_args = cppflags + cflags
###############################################################
# Library: bsd-auth
###############################################################
bsd_authopt = get_option('bsd_auth')
bsd_auth = not_found_dep
if cc.check_header('bsd_auth.h', required: bsd_authopt,
args: test_c_args, include_directories: postgres_inc)
cdata.set('USE_BSD_AUTH', 1)
bsd_auth = declare_dependency()
endif
###############################################################
# Library: bonjour
#
# For now don't search for DNSServiceRegister in a library - only Apple's
# Bonjour implementation, which is always linked, works.
###############################################################
bonjouropt = get_option('bonjour')
bonjour = not_found_dep
if cc.check_header('dns_sd.h', required: bonjouropt,
args: test_c_args, include_directories: postgres_inc) and \
cc.has_function('DNSServiceRegister',
args: test_c_args, include_directories: postgres_inc)
cdata.set('USE_BONJOUR', 1)
bonjour = declare_dependency()
endif
###############################################################
# Option: docs in HTML and man page format
###############################################################
docs_opt = get_option('docs')
docs_dep = not_found_dep
if not docs_opt.disabled()
if xmllint_bin.found() and xsltproc_bin.found()
docs_dep = declare_dependency()
elif docs_opt.enabled()
error('missing required tools (xmllint and xsltproc needed) for docs in HTML / man page format')
endif
endif
###############################################################
# Option: docs in PDF format
###############################################################
docs_pdf_opt = get_option('docs_pdf')
docs_pdf_dep = not_found_dep
if not docs_pdf_opt.disabled()
fop = find_program(get_option('FOP'), native: true, required: docs_pdf_opt)
if xmllint_bin.found() and xsltproc_bin.found() and fop.found()
docs_pdf_dep = declare_dependency()
elif docs_pdf_opt.enabled()
error('missing required tools for docs in PDF format')
endif
endif
###############################################################
# Library: GSSAPI
###############################################################
gssapiopt = get_option('gssapi')
krb_srvtab = ''
have_gssapi = false
if not gssapiopt.disabled()
gssapi = dependency('krb5-gssapi', required: false)
have_gssapi = gssapi.found()
if have_gssapi
gssapi_deps = [gssapi]
elif not have_gssapi
# Hardcoded lookup for gssapi. This is necessary as gssapi on windows does
# not install neither pkg-config nor cmake dependency information.
if host_system == 'windows'
is_64 = cc.sizeof('void *', args: test_c_args) == 8
if is_64
gssapi_search_libs = ['gssapi64', 'krb5_64', 'comerr64']
else
gssapi_search_libs = ['gssapi32', 'krb5_32', 'comerr32']
endif
else
gssapi_search_libs = ['gssapi_krb5']
endif
gssapi_deps = []
foreach libname : gssapi_search_libs
lib = cc.find_library(libname, dirs: test_lib_d, required: false)
if lib.found()
have_gssapi = true
gssapi_deps += lib
endif
endforeach
if have_gssapi
# Meson before 0.57.0 did not support using check_header() etc with
# declare_dependency(). Thus the tests below use the library looked up
# above. Once we require a newer meson version, we can simplify.
gssapi = declare_dependency(dependencies: gssapi_deps)
endif
endif
if not have_gssapi
elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi_deps, required: false,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_GSSAPI_GSSAPI_H', 1)
elif cc.check_header('gssapi.h', dependencies: gssapi_deps, required: gssapiopt,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_GSSAPI_H', 1)
else
have_gssapi = false
endif
if not have_gssapi
elif cc.check_header('gssapi/gssapi_ext.h', dependencies: gssapi_deps, required: false,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_GSSAPI_GSSAPI_EXT_H', 1)
elif cc.check_header('gssapi_ext.h', dependencies: gssapi_deps, required: gssapiopt,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_GSSAPI_EXT_H', 1)
else
have_gssapi = false
endif
if not have_gssapi
elif cc.has_function('gss_store_cred_into', dependencies: gssapi_deps,
args: test_c_args, include_directories: postgres_inc)
cdata.set('ENABLE_GSS', 1)
krb_srvtab = 'FILE:/@0@/krb5.keytab)'.format(get_option('sysconfdir'))
cdata.set_quoted('PG_KRB_SRVTAB', krb_srvtab)
elif gssapiopt.enabled()
error('''could not find function 'gss_store_cred_into' required for GSSAPI''')
else
have_gssapi = false
endif
if not have_gssapi and gssapiopt.enabled()
error('dependency lookup for gssapi failed')
endif
endif
if not have_gssapi
gssapi = not_found_dep
endif
###############################################################
# Library: ldap
###############################################################
ldapopt = get_option('ldap')
if ldapopt.disabled()
ldap = not_found_dep
ldap_r = not_found_dep
elif host_system == 'windows'
ldap = cc.find_library('wldap32', required: ldapopt)
ldap_r = ldap
else
# macos framework dependency is buggy for ldap (one can argue whether it's
# Apple's or meson's fault), leading to an endless recursion with ldap.h
# including itself. See https://github.com/mesonbuild/meson/issues/10002
# Luckily we only need pkg-config support, so the workaround isn't
# complicated.
ldap = dependency('ldap', method: 'pkg-config', required: false)
ldap_r = ldap
# Before 2.5 openldap didn't have a pkg-config file, and it might not be
# installed
if not ldap.found()
ldap = cc.find_library('ldap', required: ldapopt, dirs: test_lib_d,
has_headers: 'ldap.h', header_include_directories: postgres_inc)
# The separate ldap_r library only exists in OpenLDAP < 2.5, and if we
# have 2.5 or later, we shouldn't even probe for ldap_r (we might find a
# library from a separate OpenLDAP installation). The most reliable
# way to check that is to check for a function introduced in 2.5.
if not ldap.found()
# don't have ldap, we shouldn't check for ldap_r
elif cc.has_function('ldap_verify_credentials',
dependencies: ldap, args: test_c_args)
ldap_r = ldap # ldap >= 2.5, no need for ldap_r
else
# Use ldap_r for FE if available, else assume ldap is thread-safe.
ldap_r = cc.find_library('ldap_r', required: false, dirs: test_lib_d,
has_headers: 'ldap.h', header_include_directories: postgres_inc)
if not ldap_r.found()
ldap_r = ldap
else
# On some platforms ldap_r fails to link without PTHREAD_LIBS.
ldap_r = declare_dependency(dependencies: [ldap_r, thread_dep])
endif
# PostgreSQL sometimes loads libldap_r and plain libldap into the same
# process. Check for OpenLDAP versions known not to tolerate doing so;
# assume non-OpenLDAP implementations are safe. The dblink test suite
# exercises the hazardous interaction directly.
compat_test_code = '''
#include <ldap.h>
#if !defined(LDAP_VENDOR_VERSION) || \
(defined(LDAP_API_FEATURE_X_OPENLDAP) && \
LDAP_VENDOR_VERSION >= 20424 && LDAP_VENDOR_VERSION <= 20431)
choke me
#endif
'''
if not cc.compiles(compat_test_code,
name: 'LDAP implementation compatible',
dependencies: ldap, args: test_c_args)
warning('''
*** With OpenLDAP versions 2.4.24 through 2.4.31, inclusive, each backend
*** process that loads libpq (via WAL receiver, dblink, or postgres_fdw) and
*** also uses LDAP will crash on exit.''')
endif
endif
endif
if ldap.found() and cc.has_function('ldap_initialize',
dependencies: ldap, args: test_c_args)
cdata.set('HAVE_LDAP_INITIALIZE', 1)
endif
endif
if ldap.found()
assert(ldap_r.found())
cdata.set('USE_LDAP', 1)
else
assert(not ldap_r.found())
endif
###############################################################
# Library: LLVM
###############################################################
llvmopt = get_option('llvm')
llvm = not_found_dep
if add_languages('cpp', required: llvmopt, native: false)
llvm = dependency('llvm', version: '>=10', method: 'config-tool', required: llvmopt)
if llvm.found()
cdata.set('USE_LLVM', 1)
cpp = meson.get_compiler('cpp')
llvm_binpath = llvm.get_variable(configtool: 'bindir')
ccache = find_program('ccache', native: true, required: false)
# Some distros put LLVM and clang in different paths, so fallback to
# find via PATH, too.
clang = find_program(llvm_binpath / 'clang', 'clang', required: true)
endif
elif llvmopt.auto()
message('llvm requires a C++ compiler')
endif
###############################################################
# Library: icu
###############################################################
icuopt = get_option('icu')
if not icuopt.disabled()
icu = dependency('icu-uc', required: false)
if icu.found()
icu_i18n = dependency('icu-i18n', required: true)
endif
# Unfortunately the dependency is named differently with cmake
if not icu.found() # combine with above once meson 0.60.0 is required
icu = dependency('ICU', required: icuopt,
components: ['uc'], modules: ['ICU::uc'], method: 'cmake')
if icu.found()
icu_i18n = dependency('ICU', required: true,
components: ['i18n'], modules: ['ICU::i18n'])
endif
endif
if icu.found()
cdata.set('USE_ICU', 1)
else
icu_i18n = not_found_dep
endif
else
icu = not_found_dep
icu_i18n = not_found_dep
endif
###############################################################
# Library: libxml
###############################################################
libxmlopt = get_option('libxml')
if not libxmlopt.disabled()
libxml = dependency('libxml-2.0', required: false, version: '>= 2.6.23')
# Unfortunately the dependency is named differently with cmake
if not libxml.found() # combine with above once meson 0.60.0 is required
libxml = dependency('LibXml2', required: libxmlopt, version: '>= 2.6.23',
method: 'cmake')
endif
if libxml.found()
cdata.set('USE_LIBXML', 1)
endif
else
libxml = not_found_dep
endif
###############################################################
# Library: libxslt
###############################################################
libxsltopt = get_option('libxslt')
if not libxsltopt.disabled()
libxslt = dependency('libxslt', required: false)
# Unfortunately the dependency is named differently with cmake
if not libxslt.found() # combine with above once meson 0.60.0 is required
libxslt = dependency('LibXslt', required: libxsltopt, method: 'cmake')
endif
if libxslt.found()
cdata.set('USE_LIBXSLT', 1)
endif
else
libxslt = not_found_dep
endif
###############################################################
# Library: lz4
###############################################################
lz4opt = get_option('lz4')
if not lz4opt.disabled()
lz4 = dependency('liblz4', required: false)
# Unfortunately the dependency is named differently with cmake
if not lz4.found() # combine with above once meson 0.60.0 is required
lz4 = dependency('lz4', required: lz4opt,
method: 'cmake', modules: ['LZ4::lz4_shared'],
)
endif
if lz4.found()
cdata.set('USE_LZ4', 1)
cdata.set('HAVE_LIBLZ4', 1)
endif
else
lz4 = not_found_dep
endif
###############################################################
# Library: Tcl (for pltcl)
#
# NB: tclConfig.sh is used in autoconf build for getting
# TCL_SHARED_BUILD, TCL_INCLUDE_SPEC, TCL_LIBS and TCL_LIB_SPEC
# variables. For now we have not seen a need to copy
# that behaviour to the meson build.
###############################################################
tclopt = get_option('pltcl')
tcl_version = get_option('tcl_version')
tcl_dep = not_found_dep
if not tclopt.disabled()
# via pkg-config
tcl_dep = dependency(tcl_version, required: false)
if not tcl_dep.found()
tcl_dep = cc.find_library(tcl_version,
required: tclopt,
dirs: test_lib_d)
endif
if not cc.has_header('tcl.h', dependencies: tcl_dep, required: tclopt)
tcl_dep = not_found_dep
endif
endif
###############################################################
# Library: pam
###############################################################
pamopt = get_option('pam')
if not pamopt.disabled()
pam = dependency('pam', required: false)
if not pam.found()
pam = cc.find_library('pam', required: pamopt, dirs: test_lib_d)
endif
if pam.found()
pam_header_found = false
# header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.
if cc.check_header('security/pam_appl.h', dependencies: pam, required: false,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_SECURITY_PAM_APPL_H', 1)
pam_header_found = true
elif cc.check_header('pam/pam_appl.h', dependencies: pam, required: pamopt,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_PAM_PAM_APPL_H', 1)
pam_header_found = true
endif
if pam_header_found
cdata.set('USE_PAM', 1)
else
pam = not_found_dep
endif
endif
else
pam = not_found_dep
endif
###############################################################
# Library: Perl (for plperl)
###############################################################
perlopt = get_option('plperl')
perl_dep = not_found_dep
if not perlopt.disabled()
perl_may_work = true
# First verify that perl has the necessary dependencies installed
perl_mods = run_command(
[perl,
'-MConfig', '-MOpcode', '-MExtUtils::Embed', '-MExtUtils::ParseXS',
'-e', ''],
check: false)
if perl_mods.returncode() != 0
perl_may_work = false
perl_msg = 'perl installation does not have the required modules'