meson: wire up extra_libs option

This is more elegant as a meson feature option because feature options
propagate in a useful way to `dependency(..., required: ...)`.

Without this, the option was ignored. Wiring it up naively meant that
disabling it still searched for libbsd as well, so a feature option
is the best fit.

Also, mark it as a dependency of `arc4random`.

Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2026-07-24 07:37:40 +01:00
parent 1bd2e4b3ef
commit cf958091ad
2 changed files with 39 additions and 25 deletions
+38 -24
View File
@@ -11,6 +11,8 @@ conf_data = configuration_data()
jconf_data = configuration_data() jconf_data = configuration_data()
conf_data.set('VERSION', meson.project_version()) conf_data.set('VERSION', meson.project_version())
libjson_deps = []
has_std_lib = cc.has_header('stdlib.h') has_std_lib = cc.has_header('stdlib.h')
has_std_arg = cc.has_header('stdarg.h') has_std_arg = cc.has_header('stdarg.h')
has_string = cc.has_header('string.h') has_string = cc.has_header('string.h')
@@ -20,10 +22,7 @@ if has_std_lib and has_std_arg and has_string and has_float
conf_data.set('STDC_HEADERS', 1, description : 'Define to 1 if you have the ANSI C header files.') conf_data.set('STDC_HEADERS', 1, description : 'Define to 1 if you have the ANSI C header files.')
endif endif
bsd_dep = dependency('libbsd', required: false)
headers = { headers = {
'bsd/stdlib.h': bsd_dep,
'dlfcn.h': [], 'dlfcn.h': [],
'endian.h': [], 'endian.h': [],
'fcntl.h': [], 'fcntl.h': [],
@@ -47,6 +46,15 @@ headers = {
'xlocale.h': [], 'xlocale.h': [],
} }
may_need_libbsd = true
if cc.has_function('arc4random')
may_need_libbsd = false
conf_data.set('HAVE_@0@'.format('arc4random'.underscorify().to_upper()), 1, description : 'Define to 1 if you have the <@0@> header file'.format('arc4random'))
else
bsd_dep = dependency('libbsd', required: get_option('extra_libs'))
headers += { 'bsd/stdlib.h': [bsd_dep] }
endif
foreach h, d : headers foreach h, d : headers
if cc.has_header(h, dependencies: d) if cc.has_header(h, dependencies: d)
conf_data.set('HAVE_@0@'.format(h.underscorify().to_upper()), 1, description : 'Define to 1 if you have the <@0@> header file'.format(h)) conf_data.set('HAVE_@0@'.format(h.underscorify().to_upper()), 1, description : 'Define to 1 if you have the <@0@> header file'.format(h))
@@ -63,29 +71,35 @@ if cc.has_header('stdint.h')
jconf_data.set('JSON_C_HAVE_STDINT_H', 1, description : 'Define to 1 if you have the <stdint.h> header file.') jconf_data.set('JSON_C_HAVE_STDINT_H', 1, description : 'Define to 1 if you have the <stdint.h> header file.')
endif endif
funcs = [ funcs = {
'open', 'open': [],
'realloc', 'realloc': [],
'setlocale', 'setlocale': [],
'strdup', 'strdup': [],
'strerror', 'strerror': [],
'uselocale', 'uselocale': [],
'duplocale', 'duplocale': [],
'vsyslog', 'vsyslog': [],
'getrandom', 'getrandom': [],
'getrusage', 'getrusage': [],
'strtoll', 'strtoll': [],
'strtoull', 'strtoull': [],
'arc4random', 'vasprintf': [],
'vasprintf', }
]
if conf_data.has('HAVE_STRINGS_H') if may_need_libbsd
funcs += ['strcasecmp', 'strncasecmp'] funcs += { 'arc4random': [bsd_dep] }
libjson_deps += [bsd_dep]
else
funcs += { 'arc4random': [] }
endif endif
foreach f : funcs if conf_data.has('HAVE_STRINGS_H')
if cc.has_function(f) funcs += {'strcasecmp': [], 'strncasecmp': []}
endif
foreach f, d : funcs
if cc.has_function(f, dependencies: d)
conf_data.set('HAVE_@0@'.format(f.to_upper()), 1, description : 'Define to 1 if you have the `@0@` function.'.format(f)) conf_data.set('HAVE_@0@'.format(f.to_upper()), 1, description : 'Define to 1 if you have the `@0@` function.'.format(f))
endif endif
endforeach endforeach
@@ -255,7 +269,7 @@ inc = include_directories('.')
libjson = library('json-c', libjson = library('json-c',
sources, sources,
include_directories: inc, include_directories: inc,
dependencies: bsd_dep, dependencies: libjson_deps,
install: true, install: true,
link_args: sym, link_args: sym,
version: '5.4.0', version: '5.4.0',
+1 -1
View File
@@ -4,7 +4,7 @@ option('disable_thread_local_storage', type: 'boolean', value: false, descriptio
option('enable_rdrand', type: 'boolean', value: false, description: 'Enable RDRAND Hardware RNG') option('enable_rdrand', type: 'boolean', value: false, description: 'Enable RDRAND Hardware RNG')
option('enable_threading', type: 'boolean', value: false, description: 'Enable partial threading support') option('enable_threading', type: 'boolean', value: false, description: 'Enable partial threading support')
option('override_get_random_seed', type: 'boolean', value: false, description: 'Override json_c_get_random_seed()') option('override_get_random_seed', type: 'boolean', value: false, description: 'Override json_c_get_random_seed()')
option('disable_extra_libs', type: 'boolean', value: false, description: 'Avoid linking extra libraries like libbsd') option('extra_libs', type: 'feature', value: 'enabled', description: 'Allow linking extra libraries like libbsd')
option('disable_json_pointer', type: 'boolean', value: false, description: 'Disable JSON pointer support') option('disable_json_pointer', type: 'boolean', value: false, description: 'Disable JSON pointer support')
option('disable_json_patch', type: 'boolean', value: false, description: 'Disable JSON patch support') option('disable_json_patch', type: 'boolean', value: false, description: 'Disable JSON patch support')
option('newlocale_needs_freelocale', type: 'boolean', value: false, description: 'FreeBSD workaround for newlocale') option('newlocale_needs_freelocale', type: 'boolean', value: false, description: 'FreeBSD workaround for newlocale')