]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
build: Set minimum version for json-c and add fallback support
authorDaniel Wagner <dwagner@suse.de>
Mon, 18 Oct 2021 15:40:18 +0000 (17:40 +0200)
committerDaniel Wagner <dwagner@suse.de>
Tue, 19 Oct 2021 09:28:37 +0000 (11:28 +0200)
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
<json-c/json.h>" vs '#include <json.h>'. 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 <dwagner@suse.de>
Makefile
meson.build
nvme.h

index 3991fecba9e1abc5eb0a4e8fb286102aba024caa..0d45db415895f3d9104d3261c08d33c5538f98f8 100644 (file)
--- 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
 
index cf8fef3fda35fc2b65d157a1cd7b45647fe207f1..2d418356918bbd6e7e36b524d269f04a93431a0d 100644 (file)
@@ -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 63cb6c89953b46568e9b6e9322fdbcc36076ae82..de39e5fd2e4ca43e0e7251254773a65fc698dfc4 100644 (file)
--- a/nvme.h
+++ b/nvme.h
@@ -23,7 +23,7 @@
 
 #include "plugin.h"
 #ifdef LIBJSONC
-#include <json-c/json.h>
+#include <json.h>
 
 #define json_create_object(o) json_object_new_object(o)
 #define json_create_array(a) json_object_new_array(a)