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 if (defined(invoker.deps)) {
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.
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" ]
130 script = "$root_build_dir/gyp-win-tool"
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"
144 assert(false, "Bad value of \"type\", Must be \"exe\" or \"dll\"")
149 "$_environment_file",
150 rebase_path(output_manifest),
151 rebase_path(rcfile, root_build_dir),
152 manifest_resource_id,
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
165 ":$manifest_action_name",
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") {
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 != "")