OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 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 # HOW MANIFESTS WORK IN THE GN BUILD |
| 6 # |
| 7 # Use the windows_manifest template to declare a manifest generation step. |
| 8 # This will combine all listed .manifest files and generate a resource file |
| 9 # referencing the resulting manifest. To link this manifest, just depend on |
| 10 # the manifest target from your executable or shared library. |
| 11 # |
| 12 # This will define an empty placeholder target on non-Windows platforms so |
| 13 # the manifest declarations and dependencies do not need to be inside of OS |
| 14 # conditionals. |
| 15 # |
| 16 # Manifests uses different resource IDs for EXE and DLL targets. You will need |
| 17 # to specify this in the manifest target declaration and only use that manifest |
| 18 # target from the correct type of binary target. |
| 19 # |
| 20 # A binary can depend on only one manifest target, but the manifest target |
| 21 # can depend on many individual .manifest files which will be merged. As a |
| 22 # result, only executables and shared libraries should depend on manifest |
| 23 # targets. If you want to add a manifest to a component, put the dependency |
| 24 # behind a "if (is_component_build)" conditional. |
| 25 # |
| 26 # Generally you will just want the defaults for the Chrome build. In this case |
| 27 # the binary should just depend on one of the targets in //build/win/. There |
| 28 # are also individual manifest files in that directory you can reference via |
| 29 # the *_manifest variables defined below to pick and choose only some defaults. |
| 30 # You might combine these with a custom manifest file to get specific behavior. |
| 31 |
| 32 # Reference this manifest as a source from windows_manifest targets to get |
| 33 # the default Chrome OS compatibility list. |
| 34 default_compatibility_manifest = "//build/win/compatibility.manifest" |
| 35 |
| 36 # Reference this manifest as a source from windows_manifest targets to get |
| 37 # the default Chrome common constrols compatibility. |
| 38 common_controls_manifest = "//build/win/common_controls.manifest" |
| 39 |
| 40 # Reference this manifest to request that Windows not perform any elevation |
| 41 # when running your program. Otherwise, it might do some autodetection and |
| 42 # request elevated privileges from the user. This is normally what you want. |
| 43 as_invoker_manifest = "//build/win/as_invoker.manifest" |
| 44 |
| 45 # Construct a target to combine the given manifest files into a .rc file. |
| 46 # |
| 47 # Variables for the windows_manifest template: |
| 48 # |
| 49 # sources: (required) |
| 50 # List of source .manifest files to add. |
| 51 # |
| 52 # type: "dll" or "exe" (required) |
| 53 # Indicates the type of target that this manifest will be used for. |
| 54 # DLLs and EXEs have different manifest resource IDs. |
| 55 # |
| 56 # deps: (optional) |
| 57 # visibility: (optional) |
| 58 # Normal meaning. |
| 59 # |
| 60 # Example: |
| 61 # |
| 62 # windows_manifest("doom_melon_manifest") { |
| 63 # sources = [ |
| 64 # "doom_melon.manifest", # Custom values in here. |
| 65 # default_compatibility_manifest, # Want the normal OS compat list. |
| 66 # ] |
| 67 # type = "exe" |
| 68 # } |
| 69 # |
| 70 # executable("doom_melon") { |
| 71 # deps = [ ":doom_melon_manifest" ] |
| 72 # ... |
| 73 # } |
| 74 |
| 75 if (is_win) { |
| 76 # This is the environment file that gyp-win-tool will use for the current |
| 77 # toolchain. It is placed in root_build_dir by the toolchain setup. This |
| 78 # variable is the path relative to the root_build_dir which is what |
| 79 # gyp-win-tool expects as an argument. |
| 80 _environment_file = "environment.$current_cpu" |
| 81 |
| 82 template("windows_manifest") { |
| 83 manifest_action_name = "${target_name}__gen_manifest" |
| 84 rc_action_name = "${target_name}__gen_rc" |
| 85 source_set_name = target_name |
| 86 |
| 87 output_manifest = "$target_gen_dir/$source_set_name.manifest" |
| 88 rcfile = "$output_manifest.rc" |
| 89 |
| 90 # Make the final .manifest file. |
| 91 action(manifest_action_name) { |
| 92 visibility = [ ":$source_set_name" ] |
| 93 |
| 94 script = "$root_build_dir/gyp-win-tool" |
| 95 |
| 96 assert(defined(invoker.sources), |
| 97 "\"sources\" must be defined for a windows_manifest target") |
| 98 inputs = invoker.sources |
| 99 |
| 100 outputs = [ |
| 101 output_manifest, |
| 102 ] |
| 103 |
| 104 args = [ |
| 105 "manifest-wrapper", |
| 106 _environment_file, |
| 107 "mt.exe", |
| 108 "-nologo", |
| 109 "-manifest", |
| 110 ] |
| 111 args += rebase_path(invoker.sources, root_build_dir) |
| 112 args += [ "-out:" + rebase_path(output_manifest, root_build_dir) ] |
| 113 |
| 114 # Apply any dependencies from the invoker to this target, since those |
| 115 # dependencies may have created the input manifest files. |
| 116 if (defined(invoker.deps)) { |
| 117 deps = invoker.deps |
| 118 } |
| 119 } |
| 120 |
| 121 # Make the .rc file that references the final manifest file. The manifest |
| 122 # generation doesn't need to be a dependency because it's not actually |
| 123 # needed until the .rc is compiled. |
| 124 # |
| 125 # This could easily be combined into one step, but this current separation |
| 126 # of .manifest and .rc matches GYP and allows us to re-use gyp-win-tool. |
| 127 action(rc_action_name) { |
| 128 visibility = [ ":$source_set_name" ] |
| 129 |
| 130 script = "$root_build_dir/gyp-win-tool" |
| 131 |
| 132 outputs = [ |
| 133 rcfile, |
| 134 ] |
| 135 |
| 136 # EXEs have a resource ID of 1 for their manifest, DLLs use 2. |
| 137 assert(defined(invoker.type), |
| 138 "\"type\" must be defined for a windows_manifest") |
| 139 if (invoker.type == "exe") { |
| 140 manifest_resource_id = "1" |
| 141 } else if (invoker.type == "dll") { |
| 142 manifest_resource_id = "2" |
| 143 } else { |
| 144 assert(false, "Bad value of \"type\", Must be \"exe\" or \"dll\"") |
| 145 } |
| 146 |
| 147 args = [ |
| 148 "manifest-to-rc", |
| 149 "$_environment_file", |
| 150 rebase_path(output_manifest), |
| 151 rebase_path(rcfile, root_build_dir), |
| 152 manifest_resource_id, |
| 153 ] |
| 154 } |
| 155 |
| 156 # This source set only exists to compile and link the resource file. |
| 157 source_set(source_set_name) { |
| 158 if (defined(invoker.visibility)) { |
| 159 visibility = invoker.visibility |
| 160 } |
| 161 sources = [ |
| 162 rcfile, |
| 163 ] |
| 164 deps = [ |
| 165 ":$manifest_action_name", |
| 166 ":$rc_action_name", |
| 167 ] |
| 168 } |
| 169 } |
| 170 } else { |
| 171 # Make a no-op group on non-Windows platforms so windows_manifest |
| 172 # instantiations don't need to be inside windows blocks. |
| 173 template("windows_manifest") { |
| 174 group(target_name) { |
| 175 # Prevent unused variable warnings on non-Windows platforms. |
| 176 assert(invoker.type == "exe" || invoker.type == "dll") |
| 177 assert(invoker.sources != "") |
| 178 assert(!defined(invoker.deps) || invoker.deps != "") |
| 179 assert(!defined(invoker.visibility) || invoker.visibility != "") |
| 180 } |
| 181 } |
| 182 } |
OLD | NEW |