mirror of
https://github.com/json-c/json-c.git
synced 2026-09-07 16:46:50 +08:00
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:
+38
-24
@@ -11,6 +11,8 @@ conf_data = configuration_data()
|
||||
jconf_data = configuration_data()
|
||||
conf_data.set('VERSION', meson.project_version())
|
||||
|
||||
libjson_deps = []
|
||||
|
||||
has_std_lib = cc.has_header('stdlib.h')
|
||||
has_std_arg = cc.has_header('stdarg.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.')
|
||||
endif
|
||||
|
||||
bsd_dep = dependency('libbsd', required: false)
|
||||
|
||||
headers = {
|
||||
'bsd/stdlib.h': bsd_dep,
|
||||
'dlfcn.h': [],
|
||||
'endian.h': [],
|
||||
'fcntl.h': [],
|
||||
@@ -47,6 +46,15 @@ headers = {
|
||||
'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
|
||||
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))
|
||||
@@ -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.')
|
||||
endif
|
||||
|
||||
funcs = [
|
||||
'open',
|
||||
'realloc',
|
||||
'setlocale',
|
||||
'strdup',
|
||||
'strerror',
|
||||
'uselocale',
|
||||
'duplocale',
|
||||
'vsyslog',
|
||||
'getrandom',
|
||||
'getrusage',
|
||||
'strtoll',
|
||||
'strtoull',
|
||||
'arc4random',
|
||||
'vasprintf',
|
||||
]
|
||||
funcs = {
|
||||
'open': [],
|
||||
'realloc': [],
|
||||
'setlocale': [],
|
||||
'strdup': [],
|
||||
'strerror': [],
|
||||
'uselocale': [],
|
||||
'duplocale': [],
|
||||
'vsyslog': [],
|
||||
'getrandom': [],
|
||||
'getrusage': [],
|
||||
'strtoll': [],
|
||||
'strtoull': [],
|
||||
'vasprintf': [],
|
||||
}
|
||||
|
||||
if conf_data.has('HAVE_STRINGS_H')
|
||||
funcs += ['strcasecmp', 'strncasecmp']
|
||||
if may_need_libbsd
|
||||
funcs += { 'arc4random': [bsd_dep] }
|
||||
libjson_deps += [bsd_dep]
|
||||
else
|
||||
funcs += { 'arc4random': [] }
|
||||
endif
|
||||
|
||||
foreach f : funcs
|
||||
if cc.has_function(f)
|
||||
if conf_data.has('HAVE_STRINGS_H')
|
||||
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))
|
||||
endif
|
||||
endforeach
|
||||
@@ -255,7 +269,7 @@ inc = include_directories('.')
|
||||
libjson = library('json-c',
|
||||
sources,
|
||||
include_directories: inc,
|
||||
dependencies: bsd_dep,
|
||||
dependencies: libjson_deps,
|
||||
install: true,
|
||||
link_args: sym,
|
||||
version: '5.4.0',
|
||||
|
||||
+1
-1
@@ -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_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('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_patch', type: 'boolean', value: false, description: 'Disable JSON patch support')
|
||||
option('newlocale_needs_freelocale', type: 'boolean', value: false, description: 'FreeBSD workaround for newlocale')
|
||||
|
||||
Reference in New Issue
Block a user