aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Corgan <nicholas.corgan@ni.com>2019-04-29 20:22:39 -0500
committerMartin Braun <martin.braun@ettus.com>2019-05-02 08:36:44 -0700
commit918e4ff20c4e843b5b32d27274fbe558ec1b0000 (patch)
tree445f6ab9c2b7cfaaafeed2b606fe1ac3b63f0c2f
parent436df1087b0f26ee9a3990e3a575c94e43c34293 (diff)
downloaduhd-918e4ff20c4e843b5b32d27274fbe558ec1b0000.tar.gz
uhd-918e4ff20c4e843b5b32d27274fbe558ec1b0000.tar.bz2
uhd-918e4ff20c4e843b5b32d27274fbe558ec1b0000.zip
C: Add uhd_get_abi_string, uhd_get_version_string
Clients that include the UHD C headers have access to the version and ABI #defines, but this is not available to clients that dynamically load the library. This commit adds publicly exported functions to provide this information.
-rw-r--r--host/include/uhd.h2
-rw-r--r--host/include/uhd/CMakeLists.txt1
-rw-r--r--host/include/uhd/version.h35
-rw-r--r--host/lib/CMakeLists.txt1
-rw-r--r--host/lib/version_c.cpp34
5 files changed, 73 insertions, 0 deletions
diff --git a/host/include/uhd.h b/host/include/uhd.h
index b9143baac..413e786f9 100644
--- a/host/include/uhd.h
+++ b/host/include/uhd.h
@@ -1,6 +1,7 @@
/*
* Copyright 2015 Ettus Research LLC
* Copyright 2018 Ettus Research, a National Instruments Company
+ * Copyright 2019 Ettus Research, a National Instruments Brand
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -10,6 +11,7 @@
#include <uhd/config.h>
#include <uhd/error.h>
+#include <uhd/version.h>
#include <uhd/types/metadata.h>
#include <uhd/types/ranges.h>
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index e4a186f8a..6a103fa18 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -44,6 +44,7 @@ if(ENABLE_C_API)
UHD_INSTALL(FILES
config.h
error.h
+ version.h
DESTINATION ${INCLUDE_DIR}/uhd
COMPONENT headers
)
diff --git a/host/include/uhd/version.h b/host/include/uhd/version.h
new file mode 100644
index 000000000..b67098b36
--- /dev/null
+++ b/host/include/uhd/version.h
@@ -0,0 +1,35 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#ifndef INCLUDED_UHD_VERSION_H
+#define INCLUDED_UHD_VERSION_H
+
+#include <uhd/config.h>
+#include <uhd/error.h>
+
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//! Get the ABI compatibility string for this build of the library
+UHD_API uhd_error uhd_get_abi_string(
+ char* abi_string_out,
+ size_t buffer_len
+);
+
+//! Get the version string (dotted version number + build info)
+UHD_API uhd_error uhd_get_version_string(
+ char* version_out,
+ size_t buffer_len
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_UHD_VERSION_H */
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index b171cbfef..7e28399b4 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -131,6 +131,7 @@ LIBUHD_APPEND_SOURCES(
if(ENABLE_C_API)
LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/error_c.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/version_c.cpp
)
endif(ENABLE_C_API)
diff --git a/host/lib/version_c.cpp b/host/lib/version_c.cpp
new file mode 100644
index 000000000..2897a6407
--- /dev/null
+++ b/host/lib/version_c.cpp
@@ -0,0 +1,34 @@
+//
+// Copyright 2019 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhd/version.h>
+#include <uhd/version.hpp>
+
+#include <string.h>
+
+uhd_error uhd_get_abi_string(
+ char* abi_string_out,
+ size_t buffer_len
+){
+ UHD_SAFE_C(
+ const std::string cpp_abi_string = uhd::get_abi_string();
+
+ memset(abi_string_out, 0, buffer_len);
+ strncpy(abi_string_out, cpp_abi_string.c_str(), buffer_len);
+ )
+}
+
+uhd_error uhd_get_version_string(
+ char* version_out,
+ size_t buffer_len
+){
+ UHD_SAFE_C(
+ const std::string cpp_version = uhd::get_version_string();
+
+ memset(version_out, 0, buffer_len);
+ strncpy(version_out, cpp_version.c_str(), buffer_len);
+ )
+}