]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
Add c++ inclusion support
authorKeith Busch <kbusch@kernel.org>
Tue, 11 Feb 2020 01:38:36 +0000 (17:38 -0800)
committerKeith Busch <kbusch@kernel.org>
Tue, 11 Feb 2020 01:42:03 +0000 (17:42 -0800)
extern "C" the top level header file, and add a simple c++ compile test.

Signed-off-by: Keith Busch <kbusch@kernel.org>
.gitignore
configure
examples/Makefile
src/libnvme.h
test/Makefile
test/cpp.cc [new file with mode: 0644]

index 25a0499497da67af1da6ce67c2538766fc68e789..8ff3e73c890e27b46200503c64b52b4f849f20d1 100644 (file)
@@ -8,6 +8,7 @@ a.out
 *.so.*
 
 test/test
+test/cpp
 
 examples/display-tree
 examples/display-columnar
index 88663d6bc534c9ff21f5f1f152929bf7ec2c8010..0d6ebc6da9796b51bb60655ebeefcaf254a4fc61 100755 (executable)
--- a/configure
+++ b/configure
@@ -192,6 +192,16 @@ if [ $? -eq 0 ]; then
 fi
 print_config "systemd" "${systemd}"
 
+##########################################
+# check for c++
+cpp="no"
+which g++ > /dev/null 2> /dev/null
+if [ $? -eq 0 ]; then
+  cpp="yes"
+fi
+print_config "cpp" "${cpp}"
+
+
 if test "$libuuid" = "yes"; then
   output_sym "CONFIG_LIBUUID"
   echo "override LDFLAGS += -luuid" >> $config_host_mak
@@ -201,3 +211,6 @@ if test "$systemd" = "yes"; then
   output_sym "CONFIG_SYSTEMD"
   echo "override LDFLAGS += -lsystemd" >> $config_host_mak
 fi
+if test "$cpp" = "yes"; then
+  output_mak "CONFIG_CPLUSPLUS" "y"
+fi
index 0a70e9b812a4aad63fa05c0c05f667ebb8e0fa48..8cb7ded58d26fb69b5a9226fc711f97b66af3013 100644 (file)
@@ -11,12 +11,8 @@ all_targets += telemetry-listen display-tree display-columnar discover-loop
 
 all: $(all_targets)
 
-test_srcs := telemetry-listen.c display-tree.c display-columnar.c discover-loop.c
-
-test_objs := $(patsubst %.c,%.ol,$(test_srcs))
-
 %: %.c
        $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -lnvme
 
 clean:
-       @rm -f $(all_targets) $(test_objs)
+       rm -f $(all_targets)
index 66e17d0c1563ad4ed7b6f1a34a2a3d611c43f3c9..2a04bf8b4642363efbeedb629e1c3ec59c5a4719 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef _LIBNVME_H
 #define _LIBNVME_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "nvme/types.h"
 #include "nvme/ioctl.h"
 #include "nvme/fabrics.h"
@@ -8,4 +12,8 @@
 #include "nvme/tree.h"
 #include "nvme/util.h"
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _LIBNVME_H */
index b21e464320b4a96cc630c5c0b7b879d6437d0cfc..ddb80b7a27121e2abb77445a551a7673a4a6bc33 100644 (file)
@@ -5,18 +5,28 @@ include ../Makefile.quiet
 
 ifneq ($(MAKECMDGOALS),clean)
 include ../config-host.mak
+else
+CONFIG_CPLUSPLUS=y
 endif
 
-all_targets += test
+c_targets += test
 
+ifdef CONFIG_CPLUSPLUS
+cpp_targets += cpp
+else
+cpp_targets += 
+endif
+
+all_targets += $(c_targets) $(cpp_targets)
 all: $(all_targets)
 
-%: %.c
-       $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -lnvme
+CXXFLAGS ?= -lstdc++
 
-test_srs := test.c
+%: %.cc
+       $(QUIET_CC)$(CC) $(CFLAGS) $(CXXFLAGS) -o $@ $< -lnvme
 
-test_objs := $(patsubst %.c,%.ol,$(test_srcs))
+%: %.c
+       $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -lnvme
 
 clean:
-       @rm -f $(all_targets) $(test_objs)
+       rm -f $(all_targets)
diff --git a/test/cpp.cc b/test/cpp.cc
new file mode 100644 (file)
index 0000000..f294d00
--- /dev/null
@@ -0,0 +1,40 @@
+#include <iostream>
+#include <libnvme.h>
+
+int main()
+{
+       nvme_root_t r;
+       nvme_subsystem_t s;
+       nvme_ctrl_t c;
+       nvme_path_t p;
+       nvme_ns_t n;
+
+       r = nvme_scan();
+       if (!r)
+               return -1;
+
+       nvme_for_each_subsystem(r, s) {
+               std::cout <<  nvme_subsystem_get_name(s) << " - NQN=" << nvme_subsystem_get_nqn(s) << "\n";
+               nvme_subsystem_for_each_ctrl(s, c) {
+                       std::cout << " `- " << nvme_ctrl_get_name(c) << " " <<
+                               nvme_ctrl_get_transport(c) << " " <<
+                               nvme_ctrl_get_address(c) << " " <<
+                               nvme_ctrl_get_state(c) << "\n";
+                       nvme_ctrl_for_each_ns(c, n)
+                               std::cout << "   `- " << nvme_ns_get_name(n) <<
+                                       "lba size:" << nvme_ns_get_lba_size(n) << " lba max:" <<
+                                       nvme_ns_get_lba_count(n) << "\n";
+                       nvme_ctrl_for_each_path(c, p)
+                               std::cout << "   `- " << nvme_path_get_name(p) << " " <<
+                                       nvme_path_get_ana_state(p) << "\n";
+               }
+               nvme_subsystem_for_each_ns(s, n) {
+                       std::cout << "   `- " << nvme_ns_get_name(n) <<
+                               "lba size:" << nvme_ns_get_lba_size(n) << " lba max:" <<
+                                       nvme_ns_get_lba_count(n) << "\n";
+               }
+       }
+       std::cout << "\n";
+
+       return 0;
+}