xref: /aosp_15_r20/external/angle/build/win/message_compiler.gni (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2015 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard Workerassert(is_win, "This only runs on Windows.")
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker# Runs mc.exe over a list of sources. The outputs (a header and rc file) are
8*8975f5c5SAndroid Build Coastguard Worker# placed in the target gen dir, and compiled. Sources without a BOM will be
9*8975f5c5SAndroid Build Coastguard Worker# processed as if they are UTF-16LE. Generated text files will be written in the
10*8975f5c5SAndroid Build Coastguard Worker# ANSI codepage.
11*8975f5c5SAndroid Build Coastguard Worker#
12*8975f5c5SAndroid Build Coastguard Worker# sources
13*8975f5c5SAndroid Build Coastguard Worker#   List of message files to process.
14*8975f5c5SAndroid Build Coastguard Worker#
15*8975f5c5SAndroid Build Coastguard Worker# user_mode_logging (optional bool)
16*8975f5c5SAndroid Build Coastguard Worker#   Generates user-mode logging code. Defaults to false (no logging code).
17*8975f5c5SAndroid Build Coastguard Worker#
18*8975f5c5SAndroid Build Coastguard Worker# compile_generated_code (optional, deafults = true)
19*8975f5c5SAndroid Build Coastguard Worker#   If unset or true, the generated code will be compiled and linked into
20*8975f5c5SAndroid Build Coastguard Worker#   targets that depend on it. If set to false, the .h and .rc files will only
21*8975f5c5SAndroid Build Coastguard Worker#   be generated.
22*8975f5c5SAndroid Build Coastguard Worker#
23*8975f5c5SAndroid Build Coastguard Worker# deps, public_deps, visibility
24*8975f5c5SAndroid Build Coastguard Worker#   Normal meaning.
25*8975f5c5SAndroid Build Coastguard Workertemplate("message_compiler") {
26*8975f5c5SAndroid Build Coastguard Worker  if (defined(invoker.compile_generated_code) &&
27*8975f5c5SAndroid Build Coastguard Worker      !invoker.compile_generated_code) {
28*8975f5c5SAndroid Build Coastguard Worker    compile_generated_code = false
29*8975f5c5SAndroid Build Coastguard Worker    action_name = target_name
30*8975f5c5SAndroid Build Coastguard Worker  } else {
31*8975f5c5SAndroid Build Coastguard Worker    compile_generated_code = true
32*8975f5c5SAndroid Build Coastguard Worker    action_name = "${target_name}_mc"
33*8975f5c5SAndroid Build Coastguard Worker    source_set_name = target_name
34*8975f5c5SAndroid Build Coastguard Worker  }
35*8975f5c5SAndroid Build Coastguard Worker
36*8975f5c5SAndroid Build Coastguard Worker  action_foreach(action_name) {
37*8975f5c5SAndroid Build Coastguard Worker    if (compile_generated_code) {
38*8975f5c5SAndroid Build Coastguard Worker      visibility = [ ":$source_set_name" ]
39*8975f5c5SAndroid Build Coastguard Worker    } else {
40*8975f5c5SAndroid Build Coastguard Worker      forward_variables_from(invoker, [ "visibility" ])
41*8975f5c5SAndroid Build Coastguard Worker    }
42*8975f5c5SAndroid Build Coastguard Worker
43*8975f5c5SAndroid Build Coastguard Worker    script = "//build/win/message_compiler.py"
44*8975f5c5SAndroid Build Coastguard Worker
45*8975f5c5SAndroid Build Coastguard Worker    outputs = [
46*8975f5c5SAndroid Build Coastguard Worker      "$target_gen_dir/{{source_name_part}}.h",
47*8975f5c5SAndroid Build Coastguard Worker      "$target_gen_dir/{{source_name_part}}.rc",
48*8975f5c5SAndroid Build Coastguard Worker    ]
49*8975f5c5SAndroid Build Coastguard Worker
50*8975f5c5SAndroid Build Coastguard Worker    args = [
51*8975f5c5SAndroid Build Coastguard Worker      # The first argument is the environment file saved to the build
52*8975f5c5SAndroid Build Coastguard Worker      # directory. This is required because the Windows toolchain setup saves
53*8975f5c5SAndroid Build Coastguard Worker      # the VC paths and such so that running "mc.exe" will work with the
54*8975f5c5SAndroid Build Coastguard Worker      # configured toolchain. This file is in the root build dir.
55*8975f5c5SAndroid Build Coastguard Worker      "environment.$current_cpu",
56*8975f5c5SAndroid Build Coastguard Worker
57*8975f5c5SAndroid Build Coastguard Worker      # Where to put the header.
58*8975f5c5SAndroid Build Coastguard Worker      "-h",
59*8975f5c5SAndroid Build Coastguard Worker      rebase_path(target_gen_dir, root_build_dir),
60*8975f5c5SAndroid Build Coastguard Worker
61*8975f5c5SAndroid Build Coastguard Worker      # Where to put the .rc file.
62*8975f5c5SAndroid Build Coastguard Worker      "-r",
63*8975f5c5SAndroid Build Coastguard Worker      rebase_path(target_gen_dir, root_build_dir),
64*8975f5c5SAndroid Build Coastguard Worker
65*8975f5c5SAndroid Build Coastguard Worker      # Sources without a BOM are UTF-16LE.
66*8975f5c5SAndroid Build Coastguard Worker      "-u",
67*8975f5c5SAndroid Build Coastguard Worker    ]
68*8975f5c5SAndroid Build Coastguard Worker    if (defined(invoker.user_mode_logging) && invoker.user_mode_logging) {
69*8975f5c5SAndroid Build Coastguard Worker      args += [ "-um" ]
70*8975f5c5SAndroid Build Coastguard Worker    }
71*8975f5c5SAndroid Build Coastguard Worker    args += [ "{{source}}" ]
72*8975f5c5SAndroid Build Coastguard Worker
73*8975f5c5SAndroid Build Coastguard Worker    forward_variables_from(invoker,
74*8975f5c5SAndroid Build Coastguard Worker                           [
75*8975f5c5SAndroid Build Coastguard Worker                             "deps",
76*8975f5c5SAndroid Build Coastguard Worker                             "public_deps",
77*8975f5c5SAndroid Build Coastguard Worker                             "sources",
78*8975f5c5SAndroid Build Coastguard Worker                           ])
79*8975f5c5SAndroid Build Coastguard Worker  }
80*8975f5c5SAndroid Build Coastguard Worker
81*8975f5c5SAndroid Build Coastguard Worker  if (compile_generated_code) {
82*8975f5c5SAndroid Build Coastguard Worker    # Compile the generated rc file.
83*8975f5c5SAndroid Build Coastguard Worker    source_set(source_set_name) {
84*8975f5c5SAndroid Build Coastguard Worker      forward_variables_from(invoker, [ "visibility" ])
85*8975f5c5SAndroid Build Coastguard Worker      sources = get_target_outputs(":$action_name")
86*8975f5c5SAndroid Build Coastguard Worker      deps = [ ":$action_name" ]
87*8975f5c5SAndroid Build Coastguard Worker    }
88*8975f5c5SAndroid Build Coastguard Worker  }
89*8975f5c5SAndroid Build Coastguard Worker}
90