aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils
diff options
context:
space:
mode:
authorRyan Volz <rvolz@mit.edu>2019-10-29 17:13:58 -0400
committeratrnati <54334261+atrnati@users.noreply.github.com>2020-02-07 09:12:56 -0600
commit965ad0527935f37d99f5f3f28dd27328e6af1ef8 (patch)
tree556136a4846361602deb293285356d05b3bf2e25 /host/lib/utils
parent2fab118bdc5afd5967ff876cc574bebef0ba0f67 (diff)
downloaduhd-965ad0527935f37d99f5f3f28dd27328e6af1ef8.tar.gz
uhd-965ad0527935f37d99f5f3f28dd27328e6af1ef8.tar.bz2
uhd-965ad0527935f37d99f5f3f28dd27328e6af1ef8.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).
Diffstat (limited to 'host/lib/utils')
-rw-r--r--host/lib/utils/paths.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index c99de2c89..258722d79 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -12,6 +12,10 @@
#include <boost/algorithm/string.hpp>
#include <functional>
+#include <boost/version.hpp>
+#if BOOST_VERSION >= 106100
+#include <boost/dll/runtime_symbol_info.hpp>
+#endif
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <regex>
@@ -173,10 +177,28 @@ 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;
@@ -185,7 +207,7 @@ std::vector<fs::path> uhd::get_module_paths(void){
paths.push_back(str_path);
}
- paths.push_back(fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "modules");
+ paths.push_back(fs::path(uhd::get_lib_path()) / "uhd" / "modules");
paths.push_back(fs::path(uhd::get_pkg_path()) / "share" / "uhd" / "modules");
return paths;
@@ -351,7 +373,7 @@ std::string uhd::find_image_path(const std::string &image_name, const std::strin
}
std::string uhd::find_utility(const std::string &name) {
- return fs::path(fs::path(uhd::get_pkg_path()) / UHD_LIB_DIR / "uhd" / "utils" / name)
+ return fs::path(fs::path(uhd::get_lib_path()) / "uhd" / "utils" / name)
.string();
}