aboutsummaryrefslogtreecommitdiff
path: root/build/config
diff options
context:
space:
mode:
Diffstat (limited to 'build/config')
-rw-r--r--build/config/utility24
-rw-r--r--build/config/utility.txx14
2 files changed, 27 insertions, 11 deletions
diff --git a/build/config/utility b/build/config/utility
index 406c271..9a5dc5e 100644
--- a/build/config/utility
+++ b/build/config/utility
@@ -21,24 +21,38 @@ namespace build
{
// Set, if necessary, a required config.* variable.
//
+ // If override is true and the variable doesn't come from this root
+ // scope or from the command line, then its value is "overridden"
+ // for this root scope.
+ //
// Return the reference to the value as well as the indication of
// whether the variable has actually been set.
//
template <typename T>
std::pair<std::reference_wrapper<const value>, bool>
- required (scope& root, const variable&, const T& default_value);
+ required (scope& root,
+ const variable&,
+ const T& default_value,
+ bool override = false);
template <typename T>
inline std::pair<std::reference_wrapper<const value>, bool>
- required (scope& root, const std::string& name, const T& default_value)
+ required (scope& root,
+ const std::string& name,
+ const T& default_value,
+ bool override = false)
{
- return required (root, variable_pool.find (name), default_value);
+ return required (
+ root, variable_pool.find (name), default_value, override);
}
inline std::pair<std::reference_wrapper<const value>, bool>
- required (scope& root, const std::string& name, const char* default_value)
+ required (scope& root,
+ const std::string& name,
+ const char* default_value,
+ bool override = false)
{
- return required (root, name, std::string (default_value));
+ return required (root, name, std::string (default_value), override);
}
// Set, if necessary, an optional config.* variable. In particular,
diff --git a/build/config/utility.txx b/build/config/utility.txx
index 943d308..06cb2eb 100644
--- a/build/config/utility.txx
+++ b/build/config/utility.txx
@@ -10,18 +10,20 @@ namespace build
{
template <typename T>
std::pair<std::reference_wrapper<const value>, bool>
- required (scope& root, const variable& var, const T& def_value)
+ required (scope& root, const variable& var, const T& def_value, bool ovr)
{
using result = std::pair<std::reference_wrapper<const value>, bool>;
if (auto l = root[var])
{
- return l.belongs (*global_scope)
- ? result (root.assign (var) = *l, true)
- : result (*l, false);
+ if (l.belongs (*global_scope))
+ return result (root.assign (var) = *l, true);
+
+ if (!ovr || l.belongs (root))
+ return result (*l, false);
}
- else
- return result (root.assign (var) = def_value, true);
+
+ return result (root.assign (var) = def_value, true);
}
template <typename T>