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