diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-04-24 12:29:20 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-04-24 12:29:20 +0200 |
commit | 2a0f9e035f673f1ee387924501a31990de37f18d (patch) | |
tree | b8e55ab74bc88b788e99d8649219b931b80432d5 /build/config/utility.txx | |
parent | 4c44c914d898af53152addad5530504548175e85 (diff) |
Implement lib/liba/libso{} target group, shared/static library build
Diffstat (limited to 'build/config/utility.txx')
-rw-r--r-- | build/config/utility.txx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/build/config/utility.txx b/build/config/utility.txx new file mode 100644 index 0000000..e37c2b5 --- /dev/null +++ b/build/config/utility.txx @@ -0,0 +1,61 @@ +// file : build/config/utility.txx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include <utility> // move() + +#include <build/scope> +#include <build/variable> + +namespace build +{ + namespace config + { + template <typename T> + std::pair<const T&, bool> + required (scope& root, const char* name, const T& def_value) + { + T r; + const variable& var (variable_pool.find (name)); + + if (auto v = root[var]) + { + const T& s (v.as<const T&> ()); + + if (!v.belongs (*global_scope)) // A value from (some) config.build. + return std::pair<const T&, bool> (s, false); + + r = s; + } + else + r = def_value; + + auto v (root.assign (var)); + v = std::move (r); + + return std::pair<const T&, bool> (v.as<const T&> (), true); + } + + template <typename T> + const T* + optional (scope& root, const char* name) + { + const T* r (nullptr); + const variable& var (variable_pool.find (name)); + + auto v (root[var]); + + if (v.defined ()) + { + if (v.belongs (*global_scope)) + root.assign (var) = v; + + r = v.null () ? nullptr : &v.as<const T&> (); + } + else + root.assign (var) = nullptr; + + return r; + } + } +} |