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.
5 # HOW MANIFESTS WORK IN THE GN BUILD
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.
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
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.
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.
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.
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"
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"
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"
45 # Construct a target to combine the given manifest files into a .rc file.
47 # Variables for the windows_manifest template:
50 # List of source .manifest files to add.
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.
57 # visibility: (optional)
62 # windows_manifest("doom_melon_manifest") {
64 # "doom_melon.manifest", # Custom values in here.
65 # default_compatibility_manifest, # Want the normal OS compat list.
70 # executable("doom_melon") {
71 # deps = [ ":doom_melon_manifest" ]
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"
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
87 output_manifest = "$target_gen_dir/$source_set_name.manifest"
88 rcfile = "$output_manifest.rc"
90 # Make the final .manifest file.
91 action(manifest_action_name) {
92 visibility = [ ":$source_set_name" ]
94 script = "$root_build_dir/gyp-win-tool"
96 assert(defined(invoker.sources),
97 "\"sources\" must be defined for a windows_manifest target")
98 inputs = invoker.sources
111 args += rebase_path(invoker.sources, root_build_dir)
112 args += [ "-out:" + rebase_path(output_manifest, root_build_dir) ]
114 # Apply any dependencies from the invoker to this target, since those
115 # dependencies may have created the input manifest files.
116 forward_variables_from(invoker, [ "deps" ])
119 # Make the .rc file that references the final manifest file. The manifest
120 # generation doesn't need to be a dependency because it's not actually
121 # needed until the .rc is compiled.
123 # This could easily be combined into one step, but this current separation
124 # of .manifest and .rc matches GYP and allows us to re-use gyp-win-tool.
125 action(rc_action_name) {
126 visibility = [ ":$source_set_name" ]
128 script = "$root_build_dir/gyp-win-tool"
134 # EXEs have a resource ID of 1 for their manifest, DLLs use 2.
135 assert(defined(invoker.type),
136 "\"type\" must be defined for a windows_manifest")
137 if (invoker.type == "exe") {
138 manifest_resource_id = "1"
139 } else if (invoker.type == "dll") {
140 manifest_resource_id = "2"
142 assert(false, "Bad value of \"type\", Must be \"exe\" or \"dll\"")
147 "$_environment_file",
148 rebase_path(output_manifest),
149 rebase_path(rcfile, root_build_dir),
150 manifest_resource_id,
154 # This source set only exists to compile and link the resource file.
155 source_set(source_set_name) {
156 forward_variables_from(invoker, [ "visibility" ])
161 ":$manifest_action_name",
167 # Make a no-op group on non-Windows platforms so windows_manifest
168 # instantiations don't need to be inside windows blocks.
169 template("windows_manifest") {
171 # Prevent unused variable warnings on non-Windows platforms.
172 assert(invoker.type == "exe" || invoker.type == "dll")
173 assert(invoker.sources != "")
174 assert(!defined(invoker.deps) || invoker.deps != "")
175 assert(!defined(invoker.visibility) || invoker.visibility != "")