Skip to content

Commit 8c3add5

Browse files
carenasgitster
authored andcommitted
meson: work around broken system PCRE2 dependency in macOS
macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include. Detect that case and if the feature is enabled, try to fallback to a wrapped subproject through an anonymous dependency, aborting with an error if that is not possible. Change the feature to "auto" and print a warning and disable it if a broken dependency was detected, but to keep consistency with the cmake build system used on Windows, add a special rule to re-enable the pcre2 feature by default there. Helped-by: Eric Sunshine <[email protected]> Suggested-by: Eli Schwartz <[email protected]> Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16bd9f2 commit 8c3add5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

meson.build

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,33 @@ else
10551055
build_options_config.set('NO_ICONV', '1')
10561056
endif
10571057

1058-
pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
1058+
# can't use enable_auto_if() because it is only available in meson 1.1
1059+
if host_machine.system() == 'windows' and get_option('pcre2').allowed()
1060+
pcre2_feature = true
1061+
else
1062+
pcre2_feature = get_option('pcre2')
1063+
endif
1064+
pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
1065+
if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
1066+
# macOS installs a broken system package, double check
1067+
if not compiler.has_header('pcre2.h', dependencies: pcre2)
1068+
if pcre2_feature.enabled()
1069+
pcre2_fallback = ['pcre2', 'libpcre2_8']
1070+
else
1071+
pcre2_fallback = []
1072+
endif
1073+
# Attempt to fallback or replace with not-found-dependency
1074+
pcre2 = dependency('', required: false, fallback: pcre2_fallback, default_options: ['default_library=static', 'test=false'])
1075+
if not pcre2.found()
1076+
if pcre2_feature.enabled()
1077+
error('only a broken pcre2 install found and pcre2 is required')
1078+
else
1079+
warning('broken pcre2 install found, disabling pcre2 feature')
1080+
endif
1081+
endif
1082+
endif
1083+
endif
1084+
10591085
if pcre2.found()
10601086
libgit_dependencies += pcre2
10611087
libgit_c_args += '-DUSE_LIBPCRE2'

meson_options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
4545
description: 'Build Git web interface. Requires Perl.')
4646
option('iconv', type: 'feature', value: 'auto',
4747
description: 'Support reencoding strings with different encodings.')
48-
option('pcre2', type: 'feature', value: 'enabled',
48+
option('pcre2', type: 'feature', value: 'auto',
4949
description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
5050
option('perl', type: 'feature', value: 'auto',
5151
description: 'Build tools written in Perl.')

0 commit comments

Comments
 (0)