Merge the two meson checks for arc4random, instead have the has_function loop check first without, then with the dependencies.

This commit is contained in:
Eric Hawicz
2026-08-15 10:58:04 -04:00
parent 133b0b8322
commit 27bf659204
2 changed files with 18 additions and 18 deletions
+17 -17
View File
@@ -23,6 +23,7 @@ if has_std_lib and has_std_arg and has_string and has_float
endif endif
headers = { headers = {
'bsd/stdlib.h': [],
'dlfcn.h': [], 'dlfcn.h': [],
'endian.h': [], 'endian.h': [],
'fcntl.h': [], 'fcntl.h': [],
@@ -46,15 +47,6 @@ 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))
@@ -71,7 +63,16 @@ 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
bsd_dep = []
if get_option('extra_libs')
_bsd_dep = dependency('libbsd', required: false)
if _bsd_dep.found()
bsd_dep = [ _bsd_dep ]
endif
endif
funcs = { funcs = {
'arc4random': bsd_dep,
'open': [], 'open': [],
'realloc': [], 'realloc': [],
'setlocale': [], 'setlocale': [],
@@ -87,20 +88,19 @@ funcs = {
'vasprintf': [], 'vasprintf': [],
} }
if may_need_libbsd
funcs += { 'arc4random': [bsd_dep] }
libjson_deps += [bsd_dep]
else
funcs += { 'arc4random': [] }
endif
if conf_data.has('HAVE_STRINGS_H') if conf_data.has('HAVE_STRINGS_H')
funcs += {'strcasecmp': [], 'strncasecmp': []} funcs += {'strcasecmp': [], 'strncasecmp': []}
endif endif
foreach f, d : funcs foreach f, d : funcs
if cc.has_function(f, dependencies: d) if cc.has_function(f)
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))
else
if d.length() > 0 and 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))
libjson_deps += d
endif
endif endif
endforeach endforeach
+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('extra_libs', type: 'feature', value: 'enabled', description: 'Allow linking extra libraries like libbsd') option('extra_libs', type: 'boolean', value: true, 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')