aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/cc/common.txx
blob: b21bbb1634edb8b48ac94fb64a72a37e44682d1c (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
// file      : libbuild2/cc/common.txx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

namespace build2
{
  namespace cc
  {
    // Insert a target "tagging" it with the specified process path and
    // verifying that it already exists if requested. Return the lock.
    //
    template <typename T>
    ulock common::
    insert_library (context& ctx,
                    T*& r,
                    string name,
                    dir_path dir,
                    const process_path& out,
                    optional<string> ext,
                    bool exist,
                    tracer& trace)
    {
      auto p (ctx.targets.insert_locked (T::static_type,
                                         move (dir),
                                         dir_path (out.effect_string ()),
                                         name,
                                         move (ext),
                                         target_decl::implied,
                                         trace));

      if (exist && p.second)
        throw non_existent_library {p.first.template as<mtime_target> ()};

      r = &p.first.template as<T> ();
      return move (p.second);
    }
  }
}