diff options
author | Ryan Volz <ryan.volz@gmail.com> | 2021-01-19 12:40:26 -0500 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-01-21 02:27:20 -0800 |
commit | f191a13843751a4f4c1e910ccefeea84610d030a (patch) | |
tree | 062f2694dc5e3b3a8b79fafd32732c80713024a9 /gnuradio-runtime/lib | |
parent | 4eb0eb91f11faa2aa9c6cc970a61647bf206ce31 (diff) |
runtime: lib: Don't use hard-coded absolute path constants.
This replaces the path constants for the prefix, system configuration,
and preferences directories with a runtime prefix lookup based on the
gnuradio-runtime library location and relative paths from that. Boost >=
1.61 is required, but this is now compatible with the minimum version
required by GNU Radio overall.
Also use cmake-style paths instead of native paths for substitution to
avoid unescaped character problems. Windows is able to use the
forward-slash paths just fine, and this also has external benefits (e.g.
conda will do path replacement during installation and it substitutes
forward-slash paths, so this avoids mixed-slash paths).
Signed-off-by: Ryan Volz <ryan.volz@gmail.com>
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r-- | gnuradio-runtime/lib/CMakeLists.txt | 4 | ||||
-rw-r--r-- | gnuradio-runtime/lib/constants.cc.in | 29 |
2 files changed, 16 insertions, 17 deletions
diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt index db6d74949b..8dc9232216 100644 --- a/gnuradio-runtime/lib/CMakeLists.txt +++ b/gnuradio-runtime/lib/CMakeLists.txt @@ -23,10 +23,6 @@ string(TIMESTAMP BUILD_DATE "%a, %d %b %Y %H:%M:%S" UTC) message(STATUS "Loading build date ${BUILD_DATE} into constants...") message(STATUS "Loading version ${VERSION} into constants...") -#double escape for windows backslash path separators -string(REPLACE "\\" "\\\\" prefix "${prefix}") -string(REPLACE "\\" "\\\\" SYSCONFDIR "${SYSCONFDIR}") -string(REPLACE "\\" "\\\\" GR_PREFSDIR "${GR_PREFSDIR}") #Generate the constants file, now that we actually know which components will be enabled. configure_file( diff --git a/gnuradio-runtime/lib/constants.cc.in b/gnuradio-runtime/lib/constants.cc.in index 166a322da3..2c93d36449 100644 --- a/gnuradio-runtime/lib/constants.cc.in +++ b/gnuradio-runtime/lib/constants.cc.in @@ -14,6 +14,8 @@ #include <gnuradio/constants.h> #include <stdlib.h> +#include <boost/dll/runtime_symbol_info.hpp> +#include <boost/filesystem/path.hpp> namespace gr { @@ -24,29 +26,30 @@ const std::string prefix() if (prefix != NULL) return prefix; - return "@prefix@"; + boost::filesystem::path prefix_rel_lib = "@prefix_relative_to_lib@"; + boost::filesystem::path gr_runtime_lib_path = boost::dll::this_line_location(); + // Normalize before decomposing path so result is reliable + boost::filesystem::path prefix_path = + gr_runtime_lib_path.lexically_normal().parent_path() / prefix_rel_lib; + return prefix_path.lexically_normal().string(); } const std::string sysconfdir() { - // Provide the sysconfdir in terms of prefix() - // when the "GR_PREFIX" environment var is specified. - if (getenv("GR_PREFIX") != NULL) { - return prefix() + "/@GR_CONF_DIR@"; - } + boost::filesystem::path sysconfdir_rel_prefix = "@SYSCONFDIR_relative_to_prefix@"; + boost::filesystem::path prefix_path = prefix(); + boost::filesystem::path sysconfdir_path = prefix_path / sysconfdir_rel_prefix; - return "@SYSCONFDIR@"; + return sysconfdir_path.lexically_normal().string(); } const std::string prefsdir() { - // Provide the prefsdir in terms of sysconfdir() - // when the "GR_PREFIX" environment var is specified. - if (getenv("GR_PREFIX") != NULL) { - return sysconfdir() + "/@CMAKE_PROJECT_NAME@/conf.d"; - } + boost::filesystem::path prefsdir_rel_prefix = "@GR_PREFSDIR_relative_to_prefix@"; + boost::filesystem::path prefix_path = prefix(); + boost::filesystem::path prefsdir_path = prefix_path / prefsdir_rel_prefix; - return "@GR_PREFSDIR@"; + return prefsdir_path.lexically_normal().string(); } const std::string build_date() { return "@BUILD_DATE@"; } |