From: Daniel Wagner Date: Mon, 18 Oct 2021 15:40:18 +0000 (+0200) Subject: build: Set minimum version for json-c and add fallback support X-Git-Tag: v2.0-rc0~69^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=cad1ef9710f3;p=users%2Fsagi%2Fnvme-cli.git build: Set minimum version for json-c and add fallback support Set minimum version for json-c to 0.13. nvme-cli uses json_util_get_last_err() which got introduced in 0.13, released in December 2017. Also, meson supports embedded library build. This is very handy for system which ship outdated an really outdated json-c library. The include path for json.h has to be adapted. The json-c upstream project is not clear which include prefix should be used ('#include " vs '#include '. In order to support embedded builds, we need to use the second version of the include. The source code is added to the build, hence we use the include directory path of the project layout. And json-c has all include files in the root directory. This is no problem when using a installed version of json-c as pkg-config adds '-I/usr/inlude/json-c' to the include paths: $pkg-config --cflags json-c -I/usr/include/json-c So the simplest thing to support both build cased (external/embedded) just drop the include prefix. Signed-off-by: Daniel Wagner --- diff --git a/Makefile b/Makefile index 3991fecb..0d45db41 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,8 @@ ifeq ($(HAVE_SYSTEMD),0) endif ifeq ($(LIBJSONC), 0) - override LDFLAGS += -ljson-c + override LDFLAGS += $(shell pkg-config --libs json-c) + override CFLAGS += $(shell pkg-config --cflags json-c) override CFLAGS += -DLIBJSONC endif diff --git a/meson.build b/meson.build index cf8fef3f..2d418356 100644 --- a/meson.build +++ b/meson.build @@ -31,8 +31,8 @@ libuuid = dependency('uuid', required: true) conf.set('LIBUUID', libuuid.found(), description: 'Is libuuid required?') # Check for libjson-c availability -libjson = dependency('json-c', required: true) -conf.set('LIBJSONC', libjson.found(), description: 'Is json-c required?') +json_c = dependency('json-c', version: '>=0.13', fallback : ['json-c', 'json_c']) +conf.set('CONFIG_JSONC', json_c.found(), description: 'Is json-c required?') # Check for libhugetlbfs availability libhugetlbfs = dependency('hugetlbfs', required: false) @@ -78,5 +78,5 @@ subdir('util') executable( 'nvme', sources, - dependencies: [ libnvme_dep, libuuid, libjson ], + dependencies: [ libnvme_dep, libuuid, json_c ], ) diff --git a/nvme.h b/nvme.h index 63cb6c89..de39e5fd 100644 --- a/nvme.h +++ b/nvme.h @@ -23,7 +23,7 @@ #include "plugin.h" #ifdef LIBJSONC -#include +#include #define json_create_object(o) json_object_new_object(o) #define json_create_array(a) json_object_new_array(a)