blob: c9d7c66f956c9451cfd9edb59a7275df1ba84c64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// file : build/config/utility.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <build/config/utility>
#include <build/context>
using namespace std;
namespace build
{
namespace config
{
const value&
optional (scope& root, const variable& var)
{
auto l (root[var]);
return l.defined ()
? l.belongs (*global_scope) ? (root.assign (var) = *l) : *l
: root.assign (var); // NULL
}
const value&
optional_absolute (scope& root, const variable& var)
{
auto l (root[var]);
if (!l.defined ())
return root.assign (var); // NULL
if (!l.belongs (*global_scope)) // Value from (some) root scope.
return *l;
// Make the command-line value absolute. This is necessary to avoid
// a warning issued by the config module about global/root scope
// value mismatch.
//
value& v (const_cast<value&> (*l));
if (v && !v.empty ())
{
dir_path& d (as<dir_path> (v));
if (d.relative ())
{
d = work / d;
d.normalize ();
}
}
return root.assign (var) = v;
}
bool
specified (scope& r, const string& ns)
{
// Search all outer scopes for any value in this namespace.
//
for (scope* s (&r); s != nullptr; s = s->parent_scope ())
{
auto p (s->vars.find_namespace (ns));
if (p.first != p.second)
return true;
}
return false;
}
void
append_options (cstrings& args, const const_strings_value& sv)
{
if (!sv.empty ())
{
args.reserve (args.size () + sv.size ());
for (const string& s: sv)
args.push_back (s.c_str ());
}
}
}
}
|