Repository navigation
Expand file tree
/
Copy pathmeson.build
More file actions
1067 lines (976 loc) · 37.8 KB
/
Copy pathmeson.build
File metadata and controls
1067 lines (976 loc) · 37.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
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 setup
# -----------------------------------------------------------------------------
project(
'PCRE2',
'c',
# This line is updated by UpdateRelease.rb
version: '10.50-DEV',
license: 'BSD-3-Clause WITH PCRE2-exception',
meson_version: '>=1.6.0',
default_options: ['c_std=gnu11,c11,gnu99,c99', 'default_library=static'],
)
cc = meson.get_compiler('c')
fs = import('fs')
host_is_windows = host_machine.system() == 'windows'
host_has_import_library = host_is_windows or host_machine.system() == 'cygwin'
msvc_syntax = cc.get_argument_syntax() == 'msvc'
msvc_abi = host_is_windows and cc.get_linker_id() in ['link', 'lld-link', 'xilink', 'optlink']
# Meson recognizes feature-version guards in if statements, not ternaries.
if meson.version().version_compare('>=1.12.0')
meson_default = default()
else
meson_default = []
endif
# Small over-approximation to detect linking against the Windows CRT.
if host_is_windows
add_project_arguments('-D_CRT_SECURE_NO_DEPRECATE', '-D_CRT_SECURE_NO_WARNINGS', language: 'c')
endif
# -----------------------------------------------------------------------------
# External packages
# -----------------------------------------------------------------------------
subdir('meson/FindBZip2')
zlib_dep = dependency('zlib', required: get_option('pcre2_support_libz'))
subdir('meson/FindReadline')
subdir('meson/FindEditline')
# -----------------------------------------------------------------------------
# Configuration checks
# -----------------------------------------------------------------------------
# Feature macros are 1 when enabled and undefined otherwise, as documented in
# config.h.generic and emitted by config-cmake.h.in. set10() would define disabled
# features to 0, which is not equivalent for the source's #ifdef checks.
config = configuration_data()
foreach header : ['assert.h', 'dirent.h', 'sys/stat.h', 'sys/types.h', 'unistd.h', 'windows.h']
config.set('HAVE_' + header.underscorify().to_upper(), cc.check_header(header) ? 1 : false)
endforeach
# Check whether any system-wide extensions need to be enabled, in order for
# OS functionality to be exposed.
subdir('meson/PCRE2UseSystemExtensions')
config.set(
'HAVE_MEMFD_CREATE',
cc.has_function('memfd_create', prefix: '#include <sys/mman.h>', args: system_extension_args) ? 1 : false,
)
config.set(
'HAVE_SECURE_GETENV',
cc.has_function('secure_getenv', prefix: '#include <stdlib.h>', args: system_extension_args) ? 1 : false,
)
config.set(
'HAVE_SETRLIMIT',
cc.has_function('setrlimit', prefix: '#include <sys/resource.h>', args: system_extension_args) ? 1 : false,
)
config.set(
'HAVE_STDATOMIC_H',
cc.links(
'''
#ifdef __STDC_NO_ATOMICS__
#error "C compiler does not support standard C atomics"
#endif
#include <stdatomic.h>
int main(void) {
atomic_int value;
atomic_init(&value, 0);
return atomic_load(&value);
}
''',
name: 'standard C atomics',
) ? 1 : false,
)
config.set(
'HAVE_REALPATH',
cc.links(
'''
#include <stdlib.h>
#include <limits.h>
int main(int c, char *v[]) {
char buf[PATH_MAX];
return realpath(v[c], buf) == NULL;
}
''',
name: 'realpath',
) ? 1 : false,
)
config.set(
'HAVE_ATTRIBUTE_UNINITIALIZED',
cc.links(
'int main(void) { char buf[128] __attribute__((uninitialized)); (void)buf; return 0; }',
werror: true,
name: '__attribute__((uninitialized))',
) ? 1 : false,
)
have_visibility = false
if not msvc_abi
have_visibility = cc.links(
'''
extern __attribute__ ((visibility ("default"))) int f(void);
int main(void) { return f(); }
int f(void) { return 42; }
''',
werror: true,
name: '__attribute__((visibility("default")))',
)
endif
# Library targets use gnu_symbol_visibility: 'hidden'. Meson does not expose its
# compiler-specific visibility flags for a CMake-style consistency check.
config.set('PCRE2_EXPORT', have_visibility ? '__attribute__ ((visibility ("default")))' : '')
config.set('HAVE_BUILTIN_ASSUME', cc.links('int main(void) { __assume(1); return 0; }', name: '__assume') ? 1 : false)
config.set(
'HAVE_BUILTIN_MUL_OVERFLOW',
cc.links(
'''
#include <stddef.h>
int main(void) { int a, b; size_t m; __builtin_mul_overflow(a, b, &m); return 0; }
''',
name: '__builtin_mul_overflow',
) ? 1 : false,
)
config.set(
'HAVE_BUILTIN_UNREACHABLE',
cc.links(
'int main(int c, char *v[]) { if (c) __builtin_unreachable(); return (int)(*v[0]); }',
name: '__builtin_unreachable',
) ? 1 : false,
)
# Detect support for linker scripts.
subdir('meson/PCRE2CheckVscript')
if cc.links('#ifndef __CET__\n#error CET is not enabled\n#endif\nint main(void) { return 0; }', name: 'Intel CET')
add_project_arguments(cc.get_supported_arguments('-mshstk'), language: 'c')
endif
# -----------------------------------------------------------------------------
# User-configurable options
# -----------------------------------------------------------------------------
# Declarations and value constraints are in meson.options.
library_type = get_option('default_library')
build_shared = library_type in ['shared', 'both']
build_static = library_type in ['static', 'both']
# With both variants, Meson's auto selection falls back to shared.
default_to_static = library_type == 'static' or \
(library_type == 'both' and get_option('default_both_libraries') == 'static')
build_8 = get_option('pcre2_build_pcre2_8')
build_16 = get_option('pcre2_build_pcre2_16')
build_32 = get_option('pcre2_build_pcre2_32')
# As on CMake, we provide our own (configurable) library name suffix for static
# outputs, regardless of whether static/shared/both are requested, on all
# Windows-hosted targets making use of DLL import libraries.
static_library_postfix = ''
if host_has_import_library
static_library_postfix = get_option('pcre2_static_library_postfix')
if static_library_postfix == 'auto'
static_library_postfix = '-static'
endif
endif
config_options = {
'PCRE2_LINK_SIZE': 'pcre2_link_size',
'PCRE2_PARENS_NEST_LIMIT': 'pcre2_parens_nest_limit',
'PCRE2_HEAP_LIMIT': 'pcre2_heap_limit',
'PCRE2_MAX_VARLOOKBEHIND': 'pcre2_max_varlookbehind',
'PCRE2_MATCH_LIMIT': 'pcre2_match_limit',
'PCRE2_MATCH_LIMIT_DEPTH': 'pcre2_match_limit_depth',
'PCRE2GREP_BUFSIZE': 'pcre2grep_bufsize',
'PCRE2GREP_MAX_BUFSIZE': 'pcre2grep_max_bufsize',
}
foreach config_name, option_name : config_options
config.set(config_name, get_option(option_name))
endforeach
# -----------------------------------------------------------------------------
# Build configuration
# -----------------------------------------------------------------------------
pcre2_includes = include_directories('.', 'src')
common_c_args = ['-DHAVE_CONFIG_H']
debug_option = get_option('pcre2_debug')
if debug_option == 'enabled' or (debug_option == 'auto' and get_option('buildtype') == 'debug')
common_c_args += '-DPCRE2_DEBUG'
endif
if not build_8 and not build_16 and not build_32
error('At least one PCRE2 code unit width must be enabled.')
endif
config.set('SUPPORT_PCRE2_8', build_8 ? 1 : false)
config.set('SUPPORT_PCRE2_16', build_16 ? 1 : false)
config.set('SUPPORT_PCRE2_32', build_32 ? 1 : false)
build_grep = get_option('pcre2_build_pcre2grep')
if build_grep and not build_8
message('PCRE2_BUILD_PCRE2_8 must be enabled for pcre2grep; disabling pcre2grep.')
build_grep = false
endif
# The dependency finders have already checked explicitly requested libraries.
if editline_dep.found() and readline_dep.found()
error('Only one of PCRE2_SUPPORT_LIBREADLINE and PCRE2_SUPPORT_LIBEDIT can be enabled.')
endif
config.set('BSR_ANYCRLF', get_option('pcre2_support_bsr_anycrlf') ? 1 : false)
config.set('NEVER_BACKSLASH_C', get_option('pcre2_never_backslash_c') ? 1 : false)
config.set('SUPPORT_UNICODE', get_option('pcre2_support_unicode') ? 1 : false)
jit_option = get_option('pcre2_support_jit')
jit_enabled = jit_option.enabled()
if jit_option.auto()
jit_enabled = cc.links(
'''
#define SLJIT_CONFIG_AUTO 1
#include "sljit_src/sljitConfigCPU.h"
#if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED
#error unsupported
#endif
int main(void) { return 0; }
''',
include_directories: include_directories('deps/sljit'),
name: 'JIT support on this CPU',
)
endif
config.set('SUPPORT_JIT', jit_enabled ? 1 : false)
thread_dep = dependency('threads', required: jit_enabled)
config.set('SLJIT_PROT_EXECUTABLE_ALLOCATOR', get_option('pcre2_support_jit_sealloc') ? 1 : false)
config.set('SUPPORT_PCRE2GREP_JIT', get_option('pcre2grep_support_jit') ? 1 : false)
config.set('SUPPORT_PCRE2GREP_CALLOUT', get_option('pcre2grep_support_callout') ? 1 : false)
config.set(
'SUPPORT_PCRE2GREP_CALLOUT_FORK',
(get_option('pcre2grep_support_callout') and get_option('pcre2grep_support_callout_fork')) ? 1 : false,
)
config.set('SUPPORT_VALGRIND', get_option('pcre2_support_valgrind') ? 1 : false)
if get_option('pcre2_fuzz_support') and not build_8
error('Fuzzer support requires PCRE2_BUILD_PCRE2_8.')
endif
if get_option('pcre2_diff_fuzz_support')
if not get_option('pcre2_fuzz_support')
error('Differential fuzzing requires PCRE2_FUZZ_SUPPORT.')
endif
if not jit_enabled
error('Differential fuzzing requires PCRE2_SUPPORT_JIT.')
endif
endif
config.set('SUPPORT_DIFF_FUZZ', get_option('pcre2_diff_fuzz_support') ? 1 : false)
config.set('DISABLE_PERCENT_ZT', get_option('pcre2_disable_percent_zt') ? 1 : false)
pcre2test_deps = []
pcre2grep_deps = []
config.set('SUPPORT_LIBREADLINE', readline_dep.found() ? 1 : false)
if readline_dep.found()
pcre2test_deps += readline_dep
endif
config.set('SUPPORT_LIBEDIT', editline_dep.found() ? 1 : false)
config.set('HAVE_EDITLINE_READLINE_H', editline_header == 'editline/readline.h' ? 1 : false)
config.set('HAVE_EDIT_READLINE_READLINE_H', editline_header == 'edit/readline/readline.h' ? 1 : false)
if editline_dep.found()
pcre2test_deps += editline_dep
endif
config.set('SUPPORT_LIBZ', zlib_dep.found() ? 1 : false)
if zlib_dep.found()
pcre2grep_deps += zlib_dep
endif
config.set('SUPPORT_LIBBZ2', bzip2_dep.found() ? 1 : false)
if bzip2_dep.found()
pcre2grep_deps += bzip2_dep
endif
newline_values = {'CR': 1, 'LF': 2, 'CRLF': 3, 'ANY': 4, 'ANYCRLF': 5, 'NUL': 6}
config.set('NEWLINE_DEFAULT', newline_values[get_option('pcre2_newline')])
rebuild_chartables = get_option('pcre2_rebuild_chartables')
ebcdic = get_option('pcre2_ebcdic') or get_option('pcre2_ebcdic_nl25') or get_option('pcre2_ebcdic_ignoring_compiler')
config.set('EBCDIC', ebcdic ? 1 : false)
config.set('EBCDIC_NL25', get_option('pcre2_ebcdic_nl25') ? 1 : false)
config.set('EBCDIC_IGNORING_COMPILER', get_option('pcre2_ebcdic_ignoring_compiler') ? 1 : false)
if ebcdic
if not get_option('pcre2_ebcdic_ignoring_compiler')
rebuild_chartables = true
endif
if get_option('pcre2_support_unicode')
error('Support for EBCDIC and Unicode cannot be enabled at the same time.')
endif
if build_16 or build_32
error('EBCDIC support is available only for the 8-bit library.')
endif
endif
# Detect the Autotools-generated copy of config.h and pcre2.h. I sometimes switch
# between Autoconf and other build systems, and the conflicting copies of config.h
# generate some very unintuitive build errors.
foreach header : ['config.h', 'pcre2.h']
path = meson.project_source_root() / 'src' / header
if fs.exists(path) or fs.is_symlink(path)
error(
'Source-tree header src/@0@ conflicts with Meson-generated headers. '.format(header) + 'Remove it before configuring with Meson. ' + 'After an in-source Autotools build, run \'make distclean\' first.',
)
endif
endforeach
# -----------------------------------------------------------------------------
# Release and library version information
# -----------------------------------------------------------------------------
project_version_parts = meson.project_version().split('-')
pcre2_version = project_version_parts[0]
pcre2_major = pcre2_version.split('.')[0]
pcre2_minor = pcre2_version.split('.')[1]
pcre2_prerelease = project_version_parts.length() > 1 ? '-' + project_version_parts[1] : ''
# These lines are updated by UpdateRelease.rb
pcre2_date = '2026-11-31'
libtool_versions = {'posix': '3:10:0', '8': '17:0:17', '16': '17:0:17', '32': '17:0:17'}
lib_versions = {}
lib_soversions = {}
lib_darwin_versions = {}
foreach library : ['posix', '8', '16', '32']
parts = libtool_versions[library].split(':')
current = parts[0].to_int()
revision = parts[1]
age = parts[2]
soversion = current - age.to_int()
lib_soversions += {library: soversion.to_string()}
lib_versions += {library: '@0@.@1@.@2@'.format(soversion, age, revision)}
darwin_compatibility = current + 1
lib_darwin_versions += {library: [darwin_compatibility.to_string(), '@0@.@1@'.format(darwin_compatibility, revision)]}
endforeach
# -----------------------------------------------------------------------------
# Generated files
# -----------------------------------------------------------------------------
config_h = configure_file(input: 'src/config-meson.h.in', output: 'config.h', configuration: config)
pcre2_header_config = {
'PCRE2_MAJOR': pcre2_major,
'PCRE2_MINOR': pcre2_minor,
'PCRE2_PRERELEASE': pcre2_prerelease,
'PCRE2_DATE': pcre2_date,
}
pcre2_h = configure_file(input: 'src/pcre2.h.in', output: 'pcre2.h', configuration: pcre2_header_config)
pcre2posix_h = configure_file(input: 'src/pcre2posix.h', output: 'pcre2posix.h', copy: true)
symbol_files = {}
use_vscript = have_vscript and get_option('pcre2_symvers')
if use_vscript
foreach library : ['pcre2-8', 'pcre2-16', 'pcre2-32', 'pcre2-posix']
symbol_files += {
library: configure_file(
input: 'src/lib@0@.sym.in'.format(library),
output: 'lib@0@.sym'.format(library),
configuration: {'PCRE2_EXTRA_LOCAL_SYMS': have_vscript_no_star ? '' : ' local: *;'},
),
}
endforeach
endif
# -----------------------------------------------------------------------------
# Character table generation
# -----------------------------------------------------------------------------
if rebuild_chartables
pcre2_dftables = executable(
'pcre2_dftables',
'src/pcre2_dftables.c',
config_h,
include_directories: include_directories('.', 'src'),
c_args: '-DHAVE_CONFIG_H',
native: true,
)
chartables = custom_target('pcre2_chartables', output: 'pcre2_chartables.c', command: [pcre2_dftables, '@OUTPUT@'])
elif not ebcdic
chartables = configure_file(input: 'src/pcre2_chartables.c.dist', output: 'pcre2_chartables.c', copy: true)
elif get_option('pcre2_ebcdic_nl25')
chartables = configure_file(input: 'src/pcre2_chartables.c.ebcdic-1047-nl25', output: 'pcre2_chartables.c', copy: true)
else
chartables = configure_file(input: 'src/pcre2_chartables.c.ebcdic-1047-nl15', output: 'pcre2_chartables.c', copy: true)
endif
# -----------------------------------------------------------------------------
# Source code
# -----------------------------------------------------------------------------
pcre2_sources = files(
'src/pcre2_auto_possess.c',
'src/pcre2_chkdint.c',
'src/pcre2_compile.c',
'src/pcre2_compile_cgroup.c',
'src/pcre2_compile_class.c',
'src/pcre2_config.c',
'src/pcre2_context.c',
'src/pcre2_convert.c',
'src/pcre2_dfa_match.c',
'src/pcre2_error.c',
'src/pcre2_extuni.c',
'src/pcre2_find_bracket.c',
'src/pcre2_jit_compile.c',
'src/pcre2_maketables.c',
'src/pcre2_match.c',
'src/pcre2_match_data.c',
'src/pcre2_match_next.c',
'src/pcre2_newline.c',
'src/pcre2_ord2utf.c',
'src/pcre2_pattern_info.c',
'src/pcre2_script_run.c',
'src/pcre2_serialize.c',
'src/pcre2_string_utils.c',
'src/pcre2_study.c',
'src/pcre2_substitute.c',
'src/pcre2_substring.c',
'src/pcre2_tables.c',
'src/pcre2_ucd.c',
'src/pcre2_valid_utf.c',
'src/pcre2_xclass.c',
)
pcre2_sources += [chartables, config_h, pcre2_h]
# -----------------------------------------------------------------------------
# Libraries
# -----------------------------------------------------------------------------
# Use the conventional Windows suffix to allow debug and release libs to coexist.
windows_debug_postfix = host_is_windows and get_option('buildtype') == 'debug' ? 'd' : ''
# Meson has two conventions for the filenames of Windows DLL 'import library' files,
# controlled by namingscheme=classic/platfom. Neither matches the scheme we use with
# CMake, which we adopt here for compatibility on standard (non-Cygwin, non-MinGW) builds.
override_import_library_naming = host_is_windows and cc.get_linker_id() in ['link', 'lld-link', 'xilink', 'optlink']
static_name_prefix = meson_default
static_name_suffix = meson_default
library_naming_options = []
if override_import_library_naming
if meson.version().version_compare('>=1.10.0')
# name_prefix/name_suffix do not override the platform scheme's .dll.lib import suffix.
library_naming_options = ['namingscheme=classic']
endif
static_name_prefix = ''
static_name_suffix = 'lib'
# For the cases where we override Meson's naming, we take responsibility for
# the outputs not to collide. Provide an explicit diagnostic.
nonconfigurable_classic_import_name_prefix = ''
nonconfigurable_classic_import_name_suffix = 'lib'
sample_shared_filename = '@0@X.@1@'.format(nonconfigurable_classic_import_name_prefix, nonconfigurable_classic_import_name_suffix)
sample_static_filename = '@0@X@1@.@2@'.format(static_name_prefix, static_library_postfix, static_name_suffix)
if build_static and build_shared and sample_shared_filename == sample_static_filename
error(
'Static and shared libraries are being built with colliding suffix "' + static_name_suffix + '"; pcre2_static_library_postfix must be used to avoid this.'
)
endif
endif
private_deps = jit_enabled ? [thread_dep] : []
# Separate targets keep each variant's arguments and platform names explicit.
foreach width : ['8', '16', '32']
enabled = get_variable('build_' + width)
if not enabled
continue
endif
name = 'pcre2-' + width
width_args = common_c_args + ['-DPCRE2_CODE_UNIT_WIDTH=' + width]
if build_static
static_name = name + static_library_postfix + windows_debug_postfix
static_lib = static_library(
static_name,
pcre2_sources,
include_directories: pcre2_includes,
dependencies: private_deps,
c_args: width_args + ['-DPCRE2_STATIC'],
name_prefix: static_name_prefix,
name_suffix: static_name_suffix,
override_options: library_naming_options,
gnu_symbol_visibility: 'hidden',
install: true,
)
static_dep = declare_dependency(
link_with: static_lib,
include_directories: pcre2_includes,
compile_args: '-DPCRE2_STATIC',
dependencies: private_deps,
version: meson.project_version(),
)
set_variable('pcre2_' + width + '_static_lib', static_lib)
set_variable('pcre2_' + width + '_static_dep', static_dep)
endif
if build_shared
shared_name = name + windows_debug_postfix
link_args = use_vscript ? ['-Wl,' + vscript_flag + ',' + meson.current_build_dir() / ('lib' + name + '.sym')] : []
shared_kwargs = {
'include_directories': pcre2_includes,
'dependencies': private_deps,
'c_args': width_args,
'link_args': link_args,
'link_depends': use_vscript ? symbol_files[name] : [],
'gnu_symbol_visibility': 'hidden',
'install': true,
'override_options': library_naming_options,
}
if not host_is_windows
shared_kwargs += {'version': lib_versions[width], 'soversion': lib_soversions[width]}
endif
if host_machine.system() == 'darwin'
shared_kwargs += {'darwin_versions': lib_darwin_versions[width]}
endif
shared_lib = shared_library(shared_name, pcre2_sources, kwargs: shared_kwargs)
shared_dep = declare_dependency(
link_with: shared_lib,
include_directories: pcre2_includes,
dependencies: private_deps,
version: meson.project_version(),
)
set_variable('pcre2_' + width + '_shared_lib', shared_lib)
set_variable('pcre2_' + width + '_shared_dep', shared_dep)
endif
# The first variant override also supplies unqualified dependency() calls, so the
# order of the dependency overrides matters.
if default_to_static
static_dep = get_variable('pcre2_' + width + '_static_dep')
set_variable('libpcre2_' + width, static_dep)
meson.override_dependency('libpcre2-' + width, static_dep, static: true)
if build_shared
shared_dep = get_variable('pcre2_' + width + '_shared_dep')
meson.override_dependency('libpcre2-' + width, shared_dep, static: false)
endif
else
shared_dep = get_variable('pcre2_' + width + '_shared_dep')
set_variable('libpcre2_' + width, shared_dep)
meson.override_dependency('libpcre2-' + width, shared_dep, static: false)
if build_static
static_dep = get_variable('pcre2_' + width + '_static_dep')
meson.override_dependency('libpcre2-' + width, static_dep, static: true)
endif
endif
endforeach
if build_8
if build_static
posix_static_name = 'pcre2-posix' + static_library_postfix + windows_debug_postfix
pcre2_posix_static = static_library(
posix_static_name,
'src/pcre2posix.c',
config_h,
pcre2_h,
pcre2posix_h,
include_directories: pcre2_includes,
dependencies: pcre2_8_static_dep,
c_args: common_c_args + ['-DPCRE2_CODE_UNIT_WIDTH=8', '-DPCRE2_STATIC'],
name_prefix: static_name_prefix,
name_suffix: static_name_suffix,
override_options: library_naming_options,
gnu_symbol_visibility: 'hidden',
install: true,
)
pcre2_posix_static_dep = declare_dependency(
link_with: pcre2_posix_static,
include_directories: pcre2_includes,
compile_args: '-DPCRE2_STATIC',
dependencies: pcre2_8_static_dep,
version: meson.project_version(),
)
endif
if build_shared
posix_shared_name = 'pcre2-posix' + windows_debug_postfix
posix_link_args = use_vscript ? ['-Wl,' + vscript_flag + ',' + meson.current_build_dir() / 'libpcre2-posix.sym'] : []
posix_shared_kwargs = {
'include_directories': pcre2_includes,
'dependencies': pcre2_8_shared_dep,
'c_args': common_c_args + ['-DPCRE2_CODE_UNIT_WIDTH=8', '-DPCRE2POSIX_SHARED'],
'link_args': posix_link_args,
'link_depends': use_vscript ? symbol_files['pcre2-posix'] : [],
'gnu_symbol_visibility': 'hidden',
'install': true,
'override_options': library_naming_options,
}
if not host_is_windows
posix_shared_kwargs += {'version': lib_versions['posix'], 'soversion': lib_soversions['posix']}
endif
if host_machine.system() == 'darwin'
posix_shared_kwargs += {'darwin_versions': lib_darwin_versions['posix']}
endif
pcre2_posix_shared = shared_library(
posix_shared_name,
'src/pcre2posix.c',
config_h,
pcre2_h,
pcre2posix_h,
kwargs: posix_shared_kwargs,
)
pcre2_posix_shared_dep = declare_dependency(
link_with: pcre2_posix_shared,
include_directories: pcre2_includes,
compile_args: '-DPCRE2POSIX_SHARED',
dependencies: pcre2_8_shared_dep,
version: meson.project_version(),
)
endif
if default_to_static
libpcre2_posix = pcre2_posix_static_dep
meson.override_dependency('libpcre2-posix', pcre2_posix_static_dep, static: true)
if build_shared
meson.override_dependency('libpcre2-posix', pcre2_posix_shared_dep, static: false)
endif
else
libpcre2_posix = pcre2_posix_shared_dep
meson.override_dependency('libpcre2-posix', pcre2_posix_shared_dep, static: false)
if build_static
meson.override_dependency('libpcre2-posix', pcre2_posix_static_dep, static: true)
endif
endif
endif
# -----------------------------------------------------------------------------
# Package metadata
# -----------------------------------------------------------------------------
pkg = import('pkgconfig')
# In pkg-config versions, a tilde sorts prereleases before the final release.
pkg_version = meson.project_version().replace('-', '~')
foreach width : ['8', '16', '32']
enabled = get_variable('build_' + width)
if not enabled
continue
endif
pkg_lib = build_shared ? get_variable('pcre2_' + width + '_shared_lib') : get_variable(
'pcre2_' + width + '_static_lib',
)
pkg.generate(
pkg_lib,
filebase: 'libpcre2-' + width,
name: 'libpcre2-' + width,
description: 'PCRE2 - Perl compatible regular expressions C library (2nd API) with @0@ bit character support'.format(
width,
),
extra_cflags: build_shared ? [] : ['-DPCRE2_STATIC'],
# Shared targets do not contribute their dependencies automatically.
libraries_private: private_deps,
version: pkg_version,
install_dir: get_option('libdir') / 'pkgconfig',
)
endforeach
if build_8
pkg_posix_lib = build_shared ? pcre2_posix_shared : pcre2_posix_static
pkg.generate(
pkg_posix_lib,
filebase: 'libpcre2-posix',
name: 'libpcre2-posix',
description: 'Posix compatible interface to libpcre2-8',
extra_cflags: build_shared ? ['-DPCRE2POSIX_SHARED'] : ['-DPCRE2_STATIC'],
requires_private: 'libpcre2-8',
version: pkg_version,
install_dir: get_option('libdir') / 'pkgconfig',
)
endif
pcre2_config_data = {
'prefix': get_option('prefix'),
'exec_prefix': '${prefix}',
'libdir': fs.is_absolute(get_option('libdir')) ? get_option('libdir') : '${exec_prefix}/' + get_option('libdir'),
'includedir': fs.is_absolute(get_option('includedir')) ? get_option('includedir') : '${prefix}/' + get_option(
'includedir',
),
'PACKAGE_VERSION': meson.project_version(),
'enable_pcre2_8': build_8 ? 'yes' : 'no',
'enable_pcre2_16': build_16 ? 'yes' : 'no',
'enable_pcre2_32': build_32 ? 'yes' : 'no',
'PCRE2_STATIC_CFLAG': build_shared ? '' : '-DPCRE2_STATIC',
'PCRE2POSIX_CFLAG': build_shared ? '-DPCRE2POSIX_SHARED' : '',
'LIB_POSTFIX': (build_shared ? '' : static_library_postfix) + windows_debug_postfix,
# TODO We have (as yet) no straightforward way to extract the pthread flags from
# Meson, which is a shame. Leave them empty until this is supported.
'PTHREAD_CFLAGS': '',
'PTHREAD_LIBS': '',
}
pcre2_config = configure_file(
input: 'pcre2-config.in',
output: 'pcre2-config',
configuration: pcre2_config_data,
install: true,
install_dir: get_option('bindir'),
install_mode: 'rwxr-xr-x',
)
# -----------------------------------------------------------------------------
# Executables
# -----------------------------------------------------------------------------
if build_grep
pcre2grep = executable(
'pcre2grep',
'src/pcre2grep.c',
config_h,
pcre2_h,
include_directories: pcre2_includes,
dependencies: [libpcre2_posix] + pcre2grep_deps,
c_args: common_c_args + ['-DPCRE2_CODE_UNIT_WIDTH=8'],
install: true,
)
endif
# -----------------------------------------------------------------------------
# Testing
# -----------------------------------------------------------------------------
if get_option('pcre2_build_tests')
if build_8
pcre2test_deps += libpcre2_posix
endif
pcre2_jit_test_deps = []
foreach width : ['8', '16', '32']
enabled = get_variable('build_' + width)
if enabled
pcre2test_deps += get_variable('libpcre2_' + width)
pcre2_jit_test_deps += get_variable('libpcre2_' + width)
endif
endforeach
pcre2test = executable(
'pcre2test',
'src/pcre2test.c',
config_h,
pcre2_h,
include_directories: pcre2_includes,
dependencies: pcre2test_deps,
c_args: common_c_args,
link_args: msvc_syntax ? ['/STACK:2500000'] : [],
install: true,
)
if build_8
pcre2posix_test = executable(
'pcre2posix_test',
'src/pcre2posix_test.c',
dependencies: [libpcre2_posix, libpcre2_8],
include_directories: pcre2_includes,
)
endif
if jit_enabled
pcre2_jit_test = executable(
'pcre2_jit_test',
'src/pcre2_jit_test.c',
config_h,
pcre2_h,
dependencies: pcre2_jit_test_deps,
include_directories: pcre2_includes,
c_args: common_c_args,
)
endif
if meson.can_run_host_binaries()
python = find_program('python3', native: true, required: false)
if python.found()
test_runner = python
test_script = files('RunTest.py')
grep_test_script = files('RunGrepTest.py')
else
test_runner = find_program('sh', native: true)
test_script = files('RunTest')
grep_test_script = files('RunGrepTest')
endif
# Passing the target lets Meson provide MESON_EXE_WRAPPER to the harness.
test(
'pcre2_test',
test_runner,
args: [test_script, '--srcdir', meson.project_source_root(), '--pcre2test', pcre2test],
workdir: meson.project_build_root(),
timeout: -1,
)
if build_grep and not meson.is_cross_build() and not ebcdic
test(
'pcre2_grep_test',
test_runner,
args: [
grep_test_script,
'--srcdir',
meson.project_source_root(),
'--pcre2test',
pcre2test.full_path(),
'--pcre2grep',
pcre2grep.full_path(),
],
depends: [pcre2test, pcre2grep],
workdir: meson.project_build_root(),
timeout: -1,
)
endif
else
message('Skipping pcre2_test: host binaries cannot run without an exe_wrapper.')
endif
if build_grep and meson.is_cross_build()
message('Skipping pcre2_grep_test: the grep harness does not support cross builds.')
endif
if jit_enabled
test('pcre2_jit_test', pcre2_jit_test, timeout: -1)
endif
if build_8
test('pcre2posix_test', pcre2posix_test, timeout: -1)
endif
endif
# -----------------------------------------------------------------------------
# Fuzzer support
# -----------------------------------------------------------------------------
if get_option('pcre2_fuzz_support')
foreach width : ['8', '16', '32']
enabled = get_variable('build_' + width)
if not enabled
continue
endif
suffix = width == '8' ? '' : '-' + width
static_library(
'pcre2-fuzzsupport' + suffix,
'src/pcre2_fuzzsupport.c',
config_h,
pcre2_h,
include_directories: pcre2_includes,
c_args: common_c_args + ['-DPCRE2_CODE_UNIT_WIDTH=' + width],
)
executable(
'pcre2fuzzcheck-' + width,
'src/pcre2_fuzzsupport.c',
config_h,
pcre2_h,
include_directories: pcre2_includes,
dependencies: get_variable('libpcre2_' + width),
c_args: common_c_args + ['-DSTANDALONE', '-DPCRE2_CODE_UNIT_WIDTH=' + width],
)
endforeach
endif
# -----------------------------------------------------------------------------
# Installation
# -----------------------------------------------------------------------------
install_headers(pcre2_h, pcre2posix_h)
# Alas, Meson has no support for globbing, nor does install_man apparently accept a directory
man_pages = [
'doc/man/pcre2-config.1',
'doc/man/pcre2grep.1',
'doc/man/pcre2test.1',
'doc/man/pcre2.3',
'doc/man/pcre2_callout_enumerate.3',
'doc/man/pcre2_code_copy.3',
'doc/man/pcre2_code_copy_with_tables.3',
'doc/man/pcre2_code_free.3',
'doc/man/pcre2_compile.3',
'doc/man/pcre2_compile_context_copy.3',
'doc/man/pcre2_compile_context_create.3',
'doc/man/pcre2_compile_context_free.3',
'doc/man/pcre2_config.3',
'doc/man/pcre2_convert_context_copy.3',
'doc/man/pcre2_convert_context_create.3',
'doc/man/pcre2_convert_context_free.3',
'doc/man/pcre2_converted_pattern_free.3',
'doc/man/pcre2_dfa_match.3',
'doc/man/pcre2_general_context_copy.3',
'doc/man/pcre2_general_context_create.3',
'doc/man/pcre2_general_context_free.3',
'doc/man/pcre2_get_bsr.3',
'doc/man/pcre2_get_depth_limit.3',
'doc/man/pcre2_get_error_message.3',
'doc/man/pcre2_get_heap_limit.3',
'doc/man/pcre2_get_mark.3',
'doc/man/pcre2_get_match_data_heapframes_size.3',
'doc/man/pcre2_get_match_data_size.3',
'doc/man/pcre2_get_match_limit.3',
'doc/man/pcre2_get_max_pattern_length.3',
'doc/man/pcre2_get_newline.3',
'doc/man/pcre2_get_offset_limit.3',
'doc/man/pcre2_get_ovector_count.3',
'doc/man/pcre2_get_ovector_pointer.3',
'doc/man/pcre2_get_parens_nest_limit.3',
'doc/man/pcre2_get_startchar.3',
'doc/man/pcre2_get_subject.3',
'doc/man/pcre2_jit_compile.3',
'doc/man/pcre2_jit_free_unused_memory.3',
'doc/man/pcre2_jit_match.3',
'doc/man/pcre2_jit_stack_assign.3',
'doc/man/pcre2_jit_stack_create.3',
'doc/man/pcre2_jit_stack_free.3',
'doc/man/pcre2_maketables.3',
'doc/man/pcre2_maketables_free.3',
'doc/man/pcre2_match.3',
'doc/man/pcre2_match_context_copy.3',
'doc/man/pcre2_match_context_create.3',
'doc/man/pcre2_match_context_free.3',
'doc/man/pcre2_match_data_create.3',
'doc/man/pcre2_match_data_create_from_pattern.3',
'doc/man/pcre2_match_data_free.3',
'doc/man/pcre2_next_match.3',
'doc/man/pcre2_pattern_convert.3',
'doc/man/pcre2_pattern_info.3',
'doc/man/pcre2_serialize_decode.3',
'doc/man/pcre2_serialize_encode.3',
'doc/man/pcre2_serialize_free.3',
'doc/man/pcre2_serialize_get_number_of_codes.3',
'doc/man/pcre2_set_bsr.3',
'doc/man/pcre2_set_callout.3',
'doc/man/pcre2_set_character_tables.3',
'doc/man/pcre2_set_compile_extra_options.3',
'doc/man/pcre2_set_compile_recursion_guard.3',
'doc/man/pcre2_set_depth_limit.3',
'doc/man/pcre2_set_glob_escape.3',
'doc/man/pcre2_set_glob_separator.3',
'doc/man/pcre2_set_heap_limit.3',
'doc/man/pcre2_set_match_limit.3',
'doc/man/pcre2_set_max_pattern_compiled_length.3',
'doc/man/pcre2_set_max_pattern_length.3',
'doc/man/pcre2_set_max_varlookbehind.3',
'doc/man/pcre2_set_newline.3',
'doc/man/pcre2_set_offset_limit.3',
'doc/man/pcre2_set_optimize.3',
'doc/man/pcre2_set_parens_nest_limit.3',
'doc/man/pcre2_set_recursion_limit.3',
'doc/man/pcre2_set_recursion_memory_management.3',
'doc/man/pcre2_set_substitute_callout.3',
'doc/man/pcre2_set_substitute_case_callout.3',
'doc/man/pcre2_substitute.3',
'doc/man/pcre2_substring_copy_byname.3',
'doc/man/pcre2_substring_copy_bynumber.3',
'doc/man/pcre2_substring_free.3',
'doc/man/pcre2_substring_get_byname.3',
'doc/man/pcre2_substring_get_bynumber.3',
'doc/man/pcre2_substring_length_byname.3',
'doc/man/pcre2_substring_length_bynumber.3',
'doc/man/pcre2_substring_list_free.3',
'doc/man/pcre2_substring_list_get.3',
'doc/man/pcre2_substring_nametable_scan.3',
'doc/man/pcre2_substring_number_from_name.3',
'doc/man/pcre2api.3',
'doc/man/pcre2build.3',
'doc/man/pcre2callout.3',
'doc/man/pcre2compat.3',
'doc/man/pcre2convert.3',
'doc/man/pcre2demo.3',
'doc/man/pcre2jit.3',
'doc/man/pcre2limits.3',
'doc/man/pcre2matching.3',
'doc/man/pcre2partial.3',
'doc/man/pcre2pattern.3',
'doc/man/pcre2perform.3',
'doc/man/pcre2posix.3',
'doc/man/pcre2sample.3',
'doc/man/pcre2serialize.3',
'doc/man/pcre2syntax.3',
'doc/man/pcre2unicode.3',
]
install_man(man_pages)
install_data(
'AUTHORS.md',
'ChangeLog',
'LICENCE.md',
'NEWS',