aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Volz <rvolz@mit.edu>2019-10-29 17:13:58 -0400
committermichael-west <michael.west@ettus.com>2020-05-05 12:48:02 -0700
commitce924d7a8f206fee932d31005716cb448d6828a9 (patch)
tree33d56affa1b9ec69f8bc95a622b2f8e61e466a31
parentpython: Set python module suffix to conform with PEP 3149. (diff)
downloaduhd-ce924d7a8f206fee932d31005716cb448d6828a9.tar.xz
uhd-ce924d7a8f206fee932d31005716cb448d6828a9.zip
lib: utils: Don't use hard-coded path constants
This replaces the package path constant with a runtime library path lookup. The package path is taken to be the parent directory of the library directory. When boost >= 1.61 is not available, this maintains the current behavior of using CMake to set path contants. Runtime path determination is preferable for making a relocatable library so that it is not necessary to do string substitution on relocated binaries (as with, for example, building a conda package).
-rw-r--r--host/include/uhd/utils/paths.hpp3
-rw-r--r--host/lib/utils/paths.cpp29
2 files changed, 30 insertions, 2 deletions
diff --git a/host/include/uhd/utils/paths.hpp b/host/include/uhd/utils/paths.hpp
index 035a4943d..e5b451542 100644
--- a/host/include/uhd/utils/paths.hpp
+++ b/host/include/uhd/utils/paths.hpp
@@ -23,6 +23,9 @@ UHD_API std::string get_tmp_path(void);
//! Get a string representing the system's appdata directory
UHD_API std::string get_app_path(void);
+//! Get a string representing the system's library directory
+UHD_API std::string get_lib_path(void);
+
//! Get a string representing the system's pkg directory
UHD_API std::string get_pkg_path(void);
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index 8fb7a773d..aecdbae80 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -11,6 +11,11 @@
#include <uhdlib/utils/paths.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
+#include <boost/version.hpp>
+#include <functional>
+#if BOOST_VERSION >= 106100
+# include <boost/dll/runtime_symbol_info.hpp>
+#endif
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/regex.hpp>
@@ -185,11 +190,32 @@ std::string uhd::get_app_path(void)
return uhd::get_tmp_path();
}
+#if BOOST_VERSION >= 106100
+std::string uhd::get_pkg_path(void)
+{
+ fs::path pkg_path = fs::path(uhd::get_lib_path()).parent_path().lexically_normal();
+ return get_env_var("UHD_PKG_PATH", pkg_path.string());
+}
+
+std::string uhd::get_lib_path(void)
+{
+ fs::path runtime_libfile_path = boost::dll::this_line_location();
+ return runtime_libfile_path.remove_filename().string();
+}
+#else
std::string uhd::get_pkg_path(void)
{
return get_env_var("UHD_PKG_PATH", UHD_PKG_PATH);
}
+std::string uhd::get_lib_path(void)
+{
+ fs::path lib_path = fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR;
+ return lib_path.string();
+}
+#endif
+
+
std::vector<fs::path> uhd::get_module_paths(void)
{
std::vector<fs::path> paths;
@@ -390,8 +416,7 @@ std::string uhd::find_image_path(
std::string uhd::find_utility(const std::string& name)
{
- return fs::path(fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / name)
- .string();
+ return fs::path(fs::path(uhd::get_lib_path()) / "uhd" / "utils" / name).string();
}
std::string uhd::print_utility_error(const std::string& name, const std::string& args)