From cf958091ad390d9375b697977e14ed02616543e7 Mon Sep 17 00:00:00 2001 From: Sam James Date: Sat, 18 Jul 2026 06:29:19 +0100 Subject: [PATCH 1/6] 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 --- meson.build | 62 +++++++++++++++++++++++++++++------------------ meson_options.txt | 2 +- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/meson.build b/meson.build index ebc9e46..4ef81eb 100644 --- a/meson.build +++ b/meson.build @@ -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 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', diff --git a/meson_options.txt b/meson_options.txt index 94205b0..bb757cf 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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') From 87087ded64366aa821c87d91d35ea7023272808f Mon Sep 17 00:00:00 2001 From: Sam James Date: Sat, 18 Jul 2026 06:32:31 +0100 Subject: [PATCH 2/6] meson: improve test handling Tests will now be built at `meson test`-time, so there's no cost if the user isn't going to run them. This is better than guarding on build type, as distros may want to test production builds before shipping. Signed-off-by: Sam James --- meson.build | 5 +---- tests/meson.build | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 4ef81eb..c77265a 100644 --- a/meson.build +++ b/meson.build @@ -317,7 +317,4 @@ if get_option('build_apps') and host_machine.system() != 'windows' subdir('apps') endif -# Optional tests -if get_option('buildtype') == 'debug' - subdir('tests') -endif +subdir('tests') diff --git a/tests/meson.build b/tests/meson.build index be8b084..f66d28a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -4,6 +4,7 @@ test_lib = static_library( objects: libjson.extract_all_objects( recursive: false, ), + build_by_default: false, install: false, ) @@ -65,7 +66,8 @@ foreach t : test_cases name = t[0] expected = t[1] exe = executable(name, name + '.c', - dependencies: test_deps + dependencies: test_deps, + build_by_default: false ) test(name, exe, From 7ee487cc613b6831a3bb2d649dafb69f4bdff11f Mon Sep 17 00:00:00 2001 From: Sam James Date: Sat, 18 Jul 2026 06:37:36 +0100 Subject: [PATCH 3/6] meson: fix version numbers Signed-off-by: Sam James --- RELEASE_CHECKLIST.txt | 3 +++ meson.build | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/RELEASE_CHECKLIST.txt b/RELEASE_CHECKLIST.txt index d69a5df..939ca30 100644 --- a/RELEASE_CHECKLIST.txt +++ b/RELEASE_CHECKLIST.txt @@ -75,6 +75,9 @@ library version. Generally, unless we're doing a major release, change: to VERSION x.y+1.z + Update the version in meson.build (both at the top, and down under + '# Build library') + git commit -a -m "Bump version to ${release}" If we're doing a major release (SONAME bump), also bump the version diff --git a/meson.build b/meson.build index c77265a..5e658c7 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ -project('json-c', 'c', version: '0.18.99', +project('json-c', 'c', version: '0.19.99', meson_version: '>=0.54.0', license: 'MIT', default_options: ['buildtype=release', 'warning_level=2']) @@ -272,7 +272,7 @@ libjson = library('json-c', dependencies: libjson_deps, install: true, link_args: sym, - version: '5.4.0', + version: '5.5.0', soversion: '5', ) From 2419dbd2ead3e45686978bc481384a93cb46f991 Mon Sep 17 00:00:00 2001 From: Sam James Date: Sat, 18 Jul 2026 06:37:36 +0100 Subject: [PATCH 4/6] meson: fix pkgconfig file Fix includedir and libdir to have proper paths (not just relative ones to prefix). Using Meson's native pkgconfig module is the best way of doing this. Signed-off-by: Sam James --- meson.build | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 5e658c7..8775c62 100644 --- a/meson.build +++ b/meson.build @@ -297,19 +297,11 @@ endif install_headers(installed_headers, subdir: 'json-c') # pkg-config file -configure_file( - input: 'json-c.pc.in', - output: 'json-c.pc', - install: true, - install_dir: get_option('libdir') / 'pkgconfig', - configuration: { - 'prefix': get_option('prefix'), - 'exec_prefix': get_option('prefix'), - 'libdir': get_option('libdir'), - 'includedir': get_option('includedir'), - 'VERSION': meson.project_version(), - 'LIBS': '', - } +pkg = import('pkgconfig') +pkg.generate( + libjson, + description: 'A JSON implementation in C', + subdirs: 'json-c', ) # Optional apps From 133b0b8322249cb7ac5c27650cfac968c1284cf6 Mon Sep 17 00:00:00 2001 From: Tyler Erickson Date: Wed, 22 Jul 2026 14:01:59 -0600 Subject: [PATCH 5/6] make: Fixing missing math dependency in non-Windows json-c builds with meson The -lm was missing in the pkgconfig file that was generated. This adds that similar to the CMake build system's output. Signed-off-by: Tyler Erickson Signed-off-by: Sam James --- meson.build | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/meson.build b/meson.build index 8775c62..cae8a08 100644 --- a/meson.build +++ b/meson.build @@ -265,6 +265,10 @@ endif # Include directories inc = include_directories('.') +# Math library (needed for INFINITY, isnan, etc.) +m_dep = cc.find_library('m', required: false) +libjson_deps += [m_dep] + # Build library libjson = library('json-c', sources, From 27bf6592043dec8d237f830f20e2ed515d1cadd6 Mon Sep 17 00:00:00 2001 From: Eric Hawicz Date: Sat, 15 Aug 2026 10:44:53 -0400 Subject: [PATCH 6/6] Merge the two meson checks for arc4random, instead have the has_function loop check first without, then with the dependencies. --- meson.build | 34 +++++++++++++++++----------------- meson_options.txt | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/meson.build b/meson.build index cae8a08..4de1c5b 100644 --- a/meson.build +++ b/meson.build @@ -23,6 +23,7 @@ if has_std_lib and has_std_arg and has_string and has_float endif headers = { + 'bsd/stdlib.h': [], 'dlfcn.h': [], 'endian.h': [], 'fcntl.h': [], @@ -46,15 +47,6 @@ 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)) @@ -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 header file.') 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 = { + 'arc4random': bsd_dep, 'open': [], 'realloc': [], 'setlocale': [], @@ -87,20 +88,19 @@ funcs = { 'vasprintf': [], } -if may_need_libbsd - funcs += { 'arc4random': [bsd_dep] } - libjson_deps += [bsd_dep] -else - funcs += { 'arc4random': [] } -endif - if conf_data.has('HAVE_STRINGS_H') funcs += {'strcasecmp': [], 'strncasecmp': []} endif + 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)) + 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 endforeach diff --git a/meson_options.txt b/meson_options.txt index bb757cf..ae26ebd 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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('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_patch', type: 'boolean', value: false, description: 'Disable JSON patch support') option('newlocale_needs_freelocale', type: 'boolean', value: false, description: 'FreeBSD workaround for newlocale')