• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5assert(is_win)
6
7import("//build/config/win/visual_studio_version.gni")
8
9# This template defines a rule to invoke the MS IDL compiler.
10#
11# Parameters
12#
13#   sources
14#      List of .idl file to process.
15#
16#   out_dir (optional)
17#       Directory to write the generated files to. Defaults to target_gen_dir.
18#
19#   visibility (optional)
20
21template("midl") {
22  action_name = "${target_name}_idl_action"
23  source_set_name = target_name
24
25  assert(defined(invoker.sources), "Source must be defined for $target_name")
26
27  if (defined(invoker.out_dir)) {
28    out_dir = invoker.out_dir
29  } else {
30    out_dir = target_gen_dir
31  }
32
33  header_file = "{{source_name_part}}.h"
34  dlldata_file = "{{source_name_part}}.dlldata.c"
35  interface_identifier_file = "{{source_name_part}}_i.c"
36  proxy_file = "{{source_name_part}}_p.c"
37  type_library_file = "{{source_name_part}}.tlb"
38
39  action_foreach(action_name) {
40    visibility = [ ":$source_set_name" ]
41
42    # This functionality is handled by the win-tool because the GYP build has
43    # MIDL support built-in.
44    # TODO(brettw) move this to a separate MIDL wrapper script for better
45    # clarity once GYP support is not needed.
46    script = "$root_build_dir/gyp-win-tool"
47
48    sources = invoker.sources
49
50    # Note that .tlb is not included in the outputs as it is not always
51    # generated depending on the content of the input idl file.
52    outputs = [
53      "$out_dir/$header_file",
54      "$out_dir/$dlldata_file",
55      "$out_dir/$interface_identifier_file",
56      "$out_dir/$proxy_file",
57    ]
58
59    if (cpu_arch == "x86") {
60      win_tool_arch = "environment.x86"
61      idl_target_platform = "win32"
62    } else if (cpu_arch == "x64") {
63      win_tool_arch = "environment.x64"
64      idl_target_platform = "x64"
65    } else {
66      assert(false, "Need environment for this arch")
67    }
68
69    args = [
70      "midl-wrapper", win_tool_arch,
71      rebase_path(out_dir, root_build_dir),
72      type_library_file,
73      header_file,
74      dlldata_file,
75      interface_identifier_file,
76      proxy_file,
77      "{{source}}",
78      "/char", "signed",
79      "/env", idl_target_platform,
80      "/Oicf",
81    ]
82
83    foreach(include, system_include_dirs) {
84      args += [ "/I", include ]
85    }
86  }
87
88  source_set(target_name) {
89    if (defined(invoker.visibility)) {
90      visibility = invoker.visibility
91    }
92
93    # We only compile the IID files from the IDL tool rather than all outputs.
94    sources = process_file_template(
95        invoker.sources,
96        [ "$out_dir/$interface_identifier_file" ])
97
98    deps = [ ":$action_name" ]
99  }
100}
101