aboutsummaryrefslogtreecommitdiff
path: root/build/config/utility
blob: 82f71fe4fabb327b186a1111fb4ac3e10641c81e (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// file      : build/config/utility -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_CONFIG_UTILITY
#define BUILD_CONFIG_UTILITY

#include <string>
#include <utility>    // pair
#include <functional> // reference_wrapper

#include <build/types>
#include <build/variable>
#include <build/diagnostics>

namespace build
{
  class scope;

  namespace config
  {
    // Set, if necessary, a required config.* variable.
    //
    // 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);

    template <typename T>
    inline std::pair<std::reference_wrapper<const value>, bool>
    required (scope& root, const std::string& name, const T& default_value)
    {
      return required (root, variable_pool.find (name), default_value);
    }

    inline std::pair<std::reference_wrapper<const value>, bool>
    required (scope& root, const std::string& name, const char* default_value)
    {
      return required (root, name, std::string (default_value));
    }

    // Set, if necessary, an optional config.* variable. In particular,
    // an unspecified variable is set to NULL which is used to distinguish
    // between the "configured as unspecified" and "not yet configured"
    // cases.
    //
    // Return the value, which can be NULL.
    //
    const value&
    optional (scope& root, const variable& var);

    inline const value&
    optional (scope& root, const std::string& name)
    {
      return optional (root, variable_pool.find (name));
    }

    // Check whether there are any variables specified from the
    // config namespace. The idea is that we can check if there
    // are any, say, config.install.* values. If there are none,
    // then we can assume this functionality is not (yet) used
    // and omit writing a whole bunch of NULL config.install.*
    // values to the config.build file . We call it omitted/
    // delayed configuration.
    //
    bool
    specified (scope& root, const std::string& ns);

    // @@ Why are these here?
    //

    // Add all the values from a variable to the C-string list. T is
    // either target or scope. The variable is expected to be of type
    // strings.
    //
    template <typename T>
    void
    append_options (cstrings& args, T& s, const char* var);

    // As above but from the strings value directly.
    //
    void
    append_options (cstrings& args, const const_strings_value&);

    // Check if a specified option is present in the variable value.
    // T is either target or scope.
    //
    template <typename T>
    bool
    find_option (const char* option, T& s, const char* var);
  }
}

#include <build/config/utility.txx>
#include <build/config/utility.ixx>

#endif // BUILD_CONFIG_UTILITY