-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
3529 lines (2898 loc) · 104 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: '17devel',
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: gssapiopt)
have_gssapi = gssapi.found()
if not have_gssapi
elif cc.check_header('gssapi/gssapi.h', dependencies: gssapi, required: false,
args: test_c_args, include_directories: postgres_inc)
cdata.set('HAVE_GSSAPI_GSSAPI_H', 1)
elif cc.check_header('gssapi.h', args: test_c_args, dependencies: gssapi, required: gssapiopt)
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, 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', args: test_c_args, dependencies: gssapi, required: gssapiopt)
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,
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
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)
clang = find_program(llvm_binpath / '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: icuopt)
icu_i18n = dependency('icu-i18n', required: icuopt)
if icu.found()
cdata.set('USE_ICU', 1)
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: libxmlopt, version: '>= 2.6.23')
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: libxsltopt)
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: lz4opt)
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'
endif
# Then inquire perl about its configuration
if perl_may_work
perl_conf_cmd = [perl, '-MConfig', '-e', 'print $Config{$ARGV[0]}']
perlversion = run_command(perl_conf_cmd, 'api_versionstring', check: true).stdout()
archlibexp = run_command(perl_conf_cmd, 'archlibexp', check: true).stdout()
privlibexp = run_command(perl_conf_cmd, 'privlibexp', check: true).stdout()
useshrplib = run_command(perl_conf_cmd, 'useshrplib', check: true).stdout()
perl_inc_dir = '@0@/CORE'.format(archlibexp)
if perlversion.version_compare('< 5.14')
perl_may_work = false
perl_msg = 'Perl version 5.14 or later is required, but this is @0@'.format(perlversion)
elif useshrplib != 'true'
perl_may_work = false
perl_msg = 'need a shared perl'
endif
endif
if perl_may_work
# On most platforms, archlibexp is also where the Perl include files live ...
perl_ccflags = ['-I@0@'.format(perl_inc_dir)]
# ... but on newer macOS versions, we must use -iwithsysroot to look
# under sysroot
if not fs.is_file('@0@/perl.h'.format(perl_inc_dir)) and \
fs.is_file('@0@@1@/perl.h'.format(pg_sysroot, perl_inc_dir))
perl_ccflags = ['-iwithsysroot', perl_inc_dir]
endif
# check compiler finds header
if not cc.has_header('perl.h', required: false,
args: test_c_args + perl_ccflags, include_directories: postgres_inc)
perl_may_work = false
perl_msg = 'missing perl.h'
endif
endif
if perl_may_work
perl_ccflags_r = run_command(perl_conf_cmd, 'ccflags', check: true).stdout()
# See comments for PGAC_CHECK_PERL_EMBED_CCFLAGS in perl.m4
foreach flag : perl_ccflags_r.split(' ')
if flag.startswith('-D') and \
(not flag.startswith('-D_') or flag == '_USE_32BIT_TIME_T')
perl_ccflags += flag
endif
endforeach
if host_system == 'windows'
perl_ccflags += ['-DPLPERL_HAVE_UID_GID']
if cc.get_id() == 'msvc'
# prevent binary mismatch between MSVC built plperl and Strawberry or
# msys ucrt perl libraries
perl_ccflags += ['-DNO_THREAD_SAFE_LOCALE']
endif
endif
message('CCFLAGS recommended by perl: @0@'.format(perl_ccflags_r))
message('CCFLAGS for embedding perl: @0@'.format(' '.join(perl_ccflags)))
# We are after Embed's ldopts, but without the subset mentioned in
# Config's ccdlflags and ldflags. (Those are the choices of those who
# built the Perl installation, which are not necessarily appropriate
# for building PostgreSQL.)
ldopts = run_command(perl, '-MExtUtils::Embed', '-e', 'ldopts', check: true).stdout().strip()
undesired = run_command(perl_conf_cmd, 'ccdlflags', check: true).stdout().split()
undesired += run_command(perl_conf_cmd, 'ldflags', check: true).stdout().split()
perl_ldopts = []