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