blob: 3dcaddfb3bccd8369ddc1b044dac95ee3c5771b2 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# 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.
34default_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.
38common_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.
43as_invoker_manifest = "//build/win/as_invoker.manifest"
44
45# An alternative to as_invoker_manifest when you want the application to always
46# elevate.
47require_administrator_manifest = "//build/win/require_administrator.manifest"
48
49# Construct a target to combine the given manifest files into a .rc file.
50#
51# Variables for the windows_manifest template:
52#
53# sources: (required)
54# List of source .manifest files to add.
55#
56# type: "dll" or "exe" (required)
57# Indicates the type of target that this manifest will be used for.
58# DLLs and EXEs have different manifest resource IDs.
59#
60# deps: (optional)
61# visibility: (optional)
62# Normal meaning.
63#
64# Example:
65#
66# windows_manifest("doom_melon_manifest") {
67# sources = [
68# "doom_melon.manifest", # Custom values in here.
69# default_compatibility_manifest, # Want the normal OS compat list.
70# ]
71# type = "exe"
72# }
73#
74# executable("doom_melon") {
75# deps = [ ":doom_melon_manifest" ]
76# ...
77# }
78
79if (is_win) {
80 # This is the environment file that gyp-win-tool will use for the current
81 # toolchain. It is placed in root_build_dir by the toolchain setup. This
82 # variable is the path relative to the root_build_dir which is what
83 # gyp-win-tool expects as an argument.
84 _environment_file = "environment.$current_cpu"
85
86 template("windows_manifest") {
87 manifest_action_name = "${target_name}__gen_manifest"
88 rc_action_name = "${target_name}__gen_rc"
89 source_set_name = target_name
90
91 output_manifest = "$target_gen_dir/$source_set_name.manifest"
92 rcfile = "$output_manifest.rc"
93
94 # Make the final .manifest file.
95 action(manifest_action_name) {
96 visibility = [
97 ":$source_set_name",
98 ":$rc_action_name",
99 ]
100
101 script = "$root_build_dir/gyp-win-tool"
102
103 assert(defined(invoker.sources),
104 "\"sources\" must be defined for a windows_manifest target")
105 inputs = invoker.sources
106
107 outputs = [
108 output_manifest,
109 ]
110
111 args = [
112 "manifest-wrapper",
113 _environment_file,
114 "mt.exe",
115 "-nologo",
116 "-manifest",
117 ]
118 args += rebase_path(invoker.sources, root_build_dir)
119 args += [ "-out:" + rebase_path(output_manifest, root_build_dir) ]
120
121 # Apply any dependencies from the invoker to this target, since those
122 # dependencies may have created the input manifest files.
123 forward_variables_from(invoker, [ "deps" ])
124 }
125
126 # Make the .rc file that references the final manifest file.
127 #
128 # This could easily be combined into one step, but this current separation
129 # of .manifest and .rc matches GYP and allows us to re-use gyp-win-tool.
130 action(rc_action_name) {
131 visibility = [ ":$source_set_name" ]
132
133 script = "$root_build_dir/gyp-win-tool"
134
135 outputs = [
136 rcfile,
137 ]
138
139 # EXEs have a resource ID of 1 for their manifest, DLLs use 2.
140 assert(defined(invoker.type),
141 "\"type\" must be defined for a windows_manifest")
142 if (invoker.type == "exe") {
143 manifest_resource_id = "1"
144 } else if (invoker.type == "dll") {
145 manifest_resource_id = "2"
146 } else {
147 assert(false, "Bad value of \"type\", Must be \"exe\" or \"dll\"")
148 }
149
150 args = [
151 "manifest-to-rc",
152 "$_environment_file",
153 rebase_path(output_manifest),
154 rebase_path(rcfile, root_build_dir),
155 manifest_resource_id,
156 ]
157
158 # Although generating this file doesn't technically depend on the
159 # generated manifest, this dependency causes the .rc timestamp to be
160 # updated every time the manifest is updated. Otherwise, updating the
161 # manifest will not cause a recompilation of the .rc file.
162 deps = [
163 ":$manifest_action_name",
164 ]
165 }
166
167 # This source set only exists to compile and link the resource file.
168 source_set(source_set_name) {
169 forward_variables_from(invoker, [ "visibility" ])
170 sources = [
171 rcfile,
172 ]
173 deps = [
174 ":$manifest_action_name",
175 ":$rc_action_name",
176 ]
177 }
178 }
179} else {
180 # Make a no-op group on non-Windows platforms so windows_manifest
181 # instantiations don't need to be inside windows blocks.
182 template("windows_manifest") {
183 group(target_name) {
184 # Prevent unused variable warnings on non-Windows platforms.
185 assert(invoker.type == "exe" || invoker.type == "dll")
186 assert(invoker.sources != "")
187 assert(!defined(invoker.deps) || invoker.deps != "")
188 assert(!defined(invoker.visibility) || invoker.visibility != "")
189 }
190 }
191}