diff options
-rw-r--r-- | json-glib/json-enum-types.c.in | 4 | ||||
-rw-r--r-- | json-glib/meson.build | 112 | ||||
-rw-r--r-- | json-glib/tests/meson.build | 34 | ||||
-rw-r--r-- | meson.build | 75 | ||||
-rw-r--r-- | meson_options.txt | 4 |
5 files changed, 229 insertions, 0 deletions
diff --git a/json-glib/json-enum-types.c.in b/json-glib/json-enum-types.c.in index a2a13b4..da07c46 100644 --- a/json-glib/json-enum-types.c.in +++ b/json-glib/json-enum-types.c.in @@ -1,4 +1,8 @@ /*** BEGIN file-header ***/ +#ifndef JSON_COMPILATION +#define JSON_COMPILATION +#endif + #include "config.h" #include "json-enum-types.h" /*** END file-header ***/ diff --git a/json-glib/meson.build b/json-glib/meson.build new file mode 100644 index 0000000..1857354 --- /dev/null +++ b/json-glib/meson.build @@ -0,0 +1,112 @@ +install_header_subdir = 'json-glib-1.0/json-glib' +install_header_dir = join_paths(get_option('includedir'), install_header_subdir) + +source_h = [ + 'json-builder.h', + 'json-generator.h', + 'json-gobject.h', + 'json-gvariant.h', + 'json-parser.h', + 'json-path.h', + 'json-reader.h', + 'json-types.h', + 'json-utils.h', + 'json-version-macros.h' +] + +json_glib_enums = gnome.mkenums('json-enum-types', + sources: source_h, + h_template: 'json-enum-types.h.in', + c_template: 'json-enum-types.c.in', + install_header: true, + install_dir: install_header_dir) + +source_c = [ + 'json-array.c', + 'json-builder.c', + 'json-debug.c', + 'json-gboxed.c', + 'json-generator.c', + 'json-gobject.c', + 'json-gvariant.c', + 'json-node.c', + 'json-object.c', + 'json-parser.c', + 'json-path.c', + 'json-reader.c', + 'json-scanner.c', + 'json-serializable.c', + 'json-utils.c', + 'json-value.c', +] + +version_data = configuration_data() +version_data.set('JSON_MAJOR_VERSION', json_version_major) +version_data.set('JSON_MINOR_VERSION', json_version_minor) +version_data.set('JSON_MICRO_VERSION', json_version_micro) +version_data.set('JSON_VERSION', meson.project_version()) + +version_h = configure_file(input: 'json-version.h.in', + output: 'json-version.h', + install_dir: install_header_dir, + configuration: version_data) + +install_headers(source_h, subdir: install_header_subdir) + +localedir = join_paths(get_option('prefix'), get_option('localedir')) +json_c_args = ['-DJSON_COMPILATION', '-DG_LOG_DOMAIN="Json"', '-DJSON_LOCALEDIR="@0@"'.format(localedir)] +json_lib = library('json-glib-1.0', + source_c, + version: libversion, + soversion: soversion, + include_directories: root_dir, + dependencies: [gio_dep, gobject_dep], + c_args: json_c_args + extra_args, + install: true, +) + +pkgg = import('pkgconfig') + +pkgg.generate( + libraries: [json_lib], + subdirs: '.', + version: json_version, + name: 'JSON-GLib', + filebase: 'json-glib-@0@'.format(apiversion), + description: 'JSON Parser for GLib.', + requires: 'glib-2.0 gio-2.0' +) + +json_gen_sources = [json_glib_enums, version_h] +if build_gir + json_gen_sources += [gnome.generate_gir(json_lib, + sources: source_c + source_h, + namespace: 'Json', + nsversion: apiversion, + identifier_prefix: 'Json', + symbol_prefix: 'json', + export_packages: 'json-glib-1.0', + includes: ['GObject-2.0', 'Gio-2.0' ], + install: true, + extra_args: ['-DJSON_COMPILATION'], + )] +endif + +json_glib_dep = declare_dependency(link_with: json_lib, + include_directories: root_dir, + dependencies: [gobject_dep, gio_dep], + # Everything that uses libjson needs this built to compile + sources: json_gen_sources, +) + +json_glib_validate = executable('json-glib-validate', + 'json-glib-validate.c', + c_args: json_c_args, + dependencies: json_glib_dep) + +json_glib_format = executable('json-glib-format', + 'json-glib-format.c', + c_args: json_c_args, + dependencies: json_glib_dep) + +subdir('tests') diff --git a/json-glib/tests/meson.build b/json-glib/tests/meson.build new file mode 100644 index 0000000..eb0c304 --- /dev/null +++ b/json-glib/tests/meson.build @@ -0,0 +1,34 @@ +tests = [ + 'array', + 'boxed', + 'builder', + 'generator', + 'gvariant', + 'invalid', + 'node', + 'object', + 'parser', + 'path', + 'reader', + 'serialize-simple', + 'serialize-complex', + 'serialize-full', +] + +python3 = find_program('python3') + +cp = run_command(python3, '-c', + 'from shutil import copyfile; copyfile("@0@", "@1@")'.format( + 'stream-load.json', + meson.current_build_dir() + '/stream-load.json')) + +if cp.returncode() != 0 + error('Could not copy file: ' + cp.stderr()) +endif + +foreach t: tests + exe = executable(t, '@0@.c'.format(t), + c_args: json_c_args, + dependencies: [json_glib_dep],) + test(t, exe) +endforeach diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..9437eb9 --- /dev/null +++ b/meson.build @@ -0,0 +1,75 @@ +project('json-glib', 'c', + version: '1.2.3', + meson_version: '>= 0.37.1', + default_options: [ 'warning_level=1', + 'buildtype=debugoptimized' ]) + + +# Versionning +json_version = meson.project_version() +version_arr = json_version.split('.') +json_version_major = version_arr[0] +json_version_minor = version_arr[1] +json_version_micro = version_arr[2] + +apiversion = '1.0' +soversion = 0 + +if json_version_micro.to_int().is_odd() + json_interface_age = 0 +else + json_interface_age = json_version_micro +endif + +# maintaining compatibility with the previous libtool versioning +# current = minor * 100 + micro - interface +# revision = interface +soversion = 0 +current = json_version_minor.to_int() * 100 + json_version_micro.to_int() - json_interface_age +revision = json_interface_age +libversion = '@0@.@1@.@2@'.format(soversion, current, revision) + +# Dependencies +glib_req_version = '>= 2.37.6' +gobject_dep = dependency('gobject-2.0', version: glib_req_version) +gio_dep = dependency('gio-2.0', version: glib_req_version) + +# Configurations +cc = meson.get_compiler('c') +extra_args = [] + +cdata = configuration_data() +check_headers = [ + ['unistd.h', 'HAVE_UNISTD_H'], +] + +foreach h: check_headers + if cc.has_header(h.get(0)) + cdata.set(h.get(1), 1) + endif +endforeach +cdata.set_quoted('GETTEXT_PACKAGE', 'json-glib-1.0') + +if get_option('default_library') != 'static' + if host_machine.system() == 'windows' + cdata.set('DLL_EXPORT', true) + if cc.get_id() == 'msvc' + cdata.set('_JSON_EXTERN', '__declspec(dllexport) extern') + else + cdata.set('_JSON_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern') + extra_args += ['-fvisibility=hidden'] + endif + else + cdata.set('_JSON_EXTERN', '__attribute__((visibility("default")))') + extra_args += ['-fvisibility=hidden'] + endif +endif + +configure_file(output: 'config.h', configuration: cdata) + +root_dir = include_directories('.') +gnome = import('gnome') +gir = find_program('g-ir-scanner', required: false) +build_gir = gir.found() and not meson.is_cross_build() and not get_option('disable_introspection') + +subdir('json-glib') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..dc0aab7 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,4 @@ +option('disable_introspection', + type : 'boolean', value : false, + description : 'Whether to disable the introspection generation') + |