aboutsummaryrefslogtreecommitdiff
path: root/build/config/utility.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-24 12:29:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-24 12:29:20 +0200
commit2a0f9e035f673f1ee387924501a31990de37f18d (patch)
treeb8e55ab74bc88b788e99d8649219b931b80432d5 /build/config/utility.txx
parent4c44c914d898af53152addad5530504548175e85 (diff)
Implement lib/liba/libso{} target group, shared/static library build
Diffstat (limited to 'build/config/utility.txx')
-rw-r--r--build/config/utility.txx61
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;
+ }
+ }
+}