From 965ad0527935f37d99f5f3f28dd27328e6af1ef8 Mon Sep 17 00:00:00 2001 From: Ryan Volz Date: Tue, 29 Oct 2019 17:13:58 -0400 Subject: 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). --- host/lib/utils/paths.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'host/lib/utils') 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 #include +#include +#if BOOST_VERSION >= 106100 +#include +#endif #include #include #include @@ -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 uhd::get_module_paths(void){ std::vector paths; @@ -185,7 +207,7 @@ std::vector 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(); } -- cgit v1.2.3