From d64bbfa9c001cfb80b006fcb93dc9af3a89a1bbe Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 30 Dec 2019 16:04:07 +0700 Subject: [PATCH] #1469 Fixed build with gcc 4.8. --- CMakeLists.txt | 1 + src/base/base.cmake | 12 ++++++++++++ src/base/kernel/Env.cpp | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d792ef38..b6a9288c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) option(WITH_ASM "Enable ASM PoW implementations" ON) option(WITH_MSR "Enable MSR mod & 1st-gen Ryzen fix" ON) +option(WITH_ENV_VARS "Enable environment variables support in config file" ON) option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF) option(WITH_OPENCL "Enable OpenCL backend" ON) option(WITH_CUDA "Enable CUDA backend" ON) diff --git a/src/base/base.cmake b/src/base/base.cmake index 56aafdea..c92c317a 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -169,3 +169,15 @@ else() remove_definitions(/DXMRIG_FEATURE_HTTP) remove_definitions(/DXMRIG_FEATURE_API) endif() + + +if (WITH_ENV_VARS AND CMAKE_CXX_COMPILER_ID MATCHES GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) + set(WITH_ENV_VARS OFF) +endif() + + +if (WITH_ENV_VARS) + add_definitions(/DXMRIG_FEATURE_ENV) +else() + remove_definitions(/DXMRIG_FEATURE_ENV) +endif() diff --git a/src/base/kernel/Env.cpp b/src/base/kernel/Env.cpp index 6f8627b4..3498f2ec 100644 --- a/src/base/kernel/Env.cpp +++ b/src/base/kernel/Env.cpp @@ -50,6 +50,7 @@ namespace xmrig { +#ifdef XMRIG_FEATURE_ENV static std::map variables; @@ -59,6 +60,7 @@ static void createVariables() variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") }); variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") }); } +#endif } // namespace xmrig @@ -66,6 +68,7 @@ static void createVariables() xmrig::String xmrig::Env::expand(const char *in) { +# ifdef XMRIG_FEATURE_ENV if (in == nullptr) { return {}; } @@ -103,11 +106,15 @@ xmrig::String xmrig::Env::expand(const char *in) } return text.c_str(); +# else + return in; +# endif } xmrig::String xmrig::Env::get(const String &name) { +# ifdef XMRIG_FEATURE_ENV if (variables.empty()) { createVariables(); } @@ -115,6 +122,7 @@ xmrig::String xmrig::Env::get(const String &name) if (variables.count(name)) { return variables.at(name); } +# endif return static_cast(getenv(name)); }