From 06e10b5f469b8b06af33a8a95a6302a1e365b396 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 18 Apr 2011 17:17:32 -0700 Subject: uhd: use UHD_PKG_DATA_PATH environment variable to override the one in constants The installer sets UHD_PKG_DATA_PATH, we can can handle transplanted builds. --- host/Modules/UHDPackage.cmake | 10 ++++++++++ host/lib/utils/paths.cpp | 27 +++++++++++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'host') diff --git a/host/Modules/UHDPackage.cmake b/host/Modules/UHDPackage.cmake index 1988c7f11..416d89998 100644 --- a/host/Modules/UHDPackage.cmake +++ b/host/Modules/UHDPackage.cmake @@ -144,5 +144,15 @@ SET(CPACK_RPM_PACKAGE_REQUIRES "boost-devel, libusb1") ######################################################################## SET(CPACK_NSIS_MODIFY_PATH ON) +SET(HLKM_ENV "\\\"SYSTEM\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\Environment\\\"") + +SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS " + WriteRegStr HKLM ${HLKM_ENV} \\\"UHD_PKG_DATA_PATH\\\" \\\"$INSTDIR\\\\share\\\\uhd\\\" +") + +SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS " + DeleteRegValue HKLM ${HLKM_ENV} \\\"UHD_PKG_DATA_PATH\\\" +") + ######################################################################## INCLUDE(CPack) #include after setting vars diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 0ddc80d6e..a0e4da547 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -18,14 +18,13 @@ #include "constants.hpp" #include #include -#include #include #include #include +#include #include #include -namespace po = boost::program_options; namespace fs = boost::filesystem; /*********************************************************************** @@ -44,22 +43,14 @@ namespace fs = boost::filesystem; /*********************************************************************** * Get a list of paths for an environment variable **********************************************************************/ -static std::string name_mapper(const std::string &key, const std::string &var_name){ - return (var_name == key)? var_name : ""; +static std::string get_env_var(const std::string &var_name, const std::string &def_val = ""){ + const char *var_value_ptr = std::getenv(var_name.c_str()); + return (var_value_ptr == NULL)? def_val : var_value_ptr; } static std::vector get_env_paths(const std::string &var_name){ - //register the options - std::string var_value; - po::options_description desc; - desc.add_options() - (var_name.c_str(), po::value(&var_value)->default_value("")) - ; - //parse environment variables - po::variables_map vm; - po::store(po::parse_environment(desc, boost::bind(&name_mapper, var_name, _1)), vm); - po::notify(vm); + std::string var_value = get_env_var(var_name); //convert to filesystem path, filter blank paths std::vector paths; @@ -74,14 +65,18 @@ static std::vector get_env_paths(const std::string &var_name){ /*********************************************************************** * Get a list of special purpose paths **********************************************************************/ +static fs::path get_uhd_pkg_data_path(void){ + return fs::path(get_env_var("UHD_PKG_DATA_PATH", UHD_PKG_DATA_PATH)); +} + std::vector get_image_paths(void){ std::vector paths = get_env_paths("UHD_IMAGE_PATH"); - paths.push_back(fs::path(UHD_PKG_DATA_PATH) / "images"); + paths.push_back(get_uhd_pkg_data_path() / "images"); return paths; } std::vector get_module_paths(void){ std::vector paths = get_env_paths("UHD_MODULE_PATH"); - paths.push_back(fs::path(UHD_PKG_DATA_PATH) / "modules"); + paths.push_back(get_uhd_pkg_data_path() / "modules"); return paths; } -- cgit v1.2.3