Ed Tanous | cd9b1c5 | 2025-04-22 08:59:45 -0700 | [diff] [blame^] | 1 | project( |
| 2 | 'json-c', |
| 3 | 'c', |
| 4 | version: '0.18', |
| 5 | license: 'MIT', |
| 6 | meson_version: '>=0.49', |
| 7 | default_options: [ |
| 8 | meson.version().version_compare('>=1.3.0') ? 'c_std=gnu99,c99' : 'c_std=gnu99', |
| 9 | ], |
| 10 | ) |
| 11 | |
| 12 | cc = meson.get_compiler('c') |
| 13 | |
| 14 | if cc.get_argument_syntax() == 'msvc' |
| 15 | add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language: 'c') |
| 16 | else |
| 17 | add_project_arguments('-D_GNU_SOURCE', language: 'c') |
| 18 | endif |
| 19 | |
| 20 | if get_option('default_library') != 'static' |
| 21 | add_project_arguments('-DJSON_C_DLL', language: 'c') |
| 22 | endif |
| 23 | |
| 24 | add_project_arguments( |
| 25 | cc.get_supported_arguments('-Wno-deprecated-declarations'), |
| 26 | language: 'c', |
| 27 | ) |
| 28 | |
| 29 | threads = dependency('threads', required: false) |
| 30 | math = cc.find_library('m', required: false) |
| 31 | |
| 32 | subdir('config') |
| 33 | inc = include_directories('config') |
| 34 | |
| 35 | json_config = configuration_data() |
| 36 | if conf.has('HAVE_INTTYPES_H') |
| 37 | json_config.set('JSON_C_HAVE_INTTYPES_H', 1) |
| 38 | endif |
| 39 | json_config_h = configure_file( |
| 40 | configuration: json_config, |
| 41 | output: 'json_config.h', |
| 42 | ) |
| 43 | |
| 44 | jconf = configuration_data() |
| 45 | jconf.set('JSON_H_JSON_POINTER', '#include "json_pointer.h"') |
| 46 | jconf.set('JSON_H_JSON_PATCH', '#include "json_patch.h"') |
| 47 | |
| 48 | json_h = configure_file( |
| 49 | input: 'json.h.cmakein', |
| 50 | output: 'json.h', |
| 51 | format: 'cmake@', |
| 52 | configuration: jconf, |
| 53 | ) |
| 54 | |
| 55 | public_headers = [ |
| 56 | json_config_h, |
| 57 | json_h, |
| 58 | 'arraylist.h', |
| 59 | 'debug.h', |
| 60 | 'json_c_version.h', |
| 61 | 'json_inttypes.h', |
| 62 | 'json_object.h', |
| 63 | 'json_pointer.h', |
| 64 | 'json_tokener.h', |
| 65 | 'json_util.h', |
| 66 | 'linkhash.h', |
| 67 | 'printbuf.h', |
| 68 | ] |
| 69 | |
| 70 | sources = files( |
| 71 | 'arraylist.c', |
| 72 | 'debug.c', |
| 73 | 'json_c_version.c', |
| 74 | 'json_object.c', |
| 75 | 'json_object_iterator.c', |
| 76 | 'json_pointer.c', |
| 77 | 'json_tokener.c', |
| 78 | 'json_util.c', |
| 79 | 'json_visit.c', |
| 80 | 'linkhash.c', |
| 81 | 'printbuf.c', |
| 82 | 'random_seed.c', |
| 83 | 'strerror_override.c', |
| 84 | ) |
| 85 | |
| 86 | libjson_c = library( |
| 87 | 'json-c', |
| 88 | sources, |
| 89 | include_directories: inc, |
| 90 | install: true, |
| 91 | version: '5.4.0', |
| 92 | ) |
| 93 | |
| 94 | json_c_dep = declare_dependency( |
| 95 | link_with: libjson_c, |
| 96 | include_directories: include_directories('.', '..'), |
| 97 | dependencies: [math, threads], |
| 98 | sources: json_config_h, |
| 99 | ) |
| 100 | |
| 101 | install_headers(public_headers, subdir: 'json-c') |
| 102 | |
| 103 | pkgconfig = import('pkgconfig') |
| 104 | pkgconfig.generate( |
| 105 | libjson_c, |
| 106 | description: 'A JSON implementation in C', |
| 107 | version: meson.project_version(), |
| 108 | filebase: meson.project_name(), |
| 109 | name: meson.project_name(), |
| 110 | subdirs: 'json-c', |
| 111 | ) |