1 // Copyright (c) 2013 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 #include "gn/variables.h"
6
7 #include "gn/rust_variables.h"
8
9 namespace variables {
10
11 // Built-in variables ----------------------------------------------------------
12
13 const char kGnVersion[] = "gn_version";
14 const char kGnVersion_HelpShort[] =
15 "gn_version: [number] The version of gn.";
16 const char kGnVersion_Help[] =
17 R"(gn_version: [number] The version of gn.
18
19 Corresponds to the number printed by `gn --version`.
20
21 Example
22
23 assert(gn_version >= 1700, "need GN version 1700 for the frobulate feature")
24 )";
25
26 const char kHostCpu[] = "host_cpu";
27 const char kHostCpu_HelpShort[] =
28 "host_cpu: [string] The processor architecture that GN is running on.";
29 const char kHostCpu_Help[] =
30 R"(host_cpu: The processor architecture that GN is running on.
31
32 This is value is exposed so that cross-compile toolchains can access the host
33 architecture when needed.
34
35 The value should generally be considered read-only, but it can be overriden
36 in order to handle unusual cases where there might be multiple plausible
37 values for the host architecture (e.g., if you can do either 32-bit or 64-bit
38 builds). The value is not used internally by GN for any purpose.
39
40 Some possible values
41
42 - "x64"
43 - "x86"
44 )";
45
46 const char kHostOs[] = "host_os";
47 const char kHostOs_HelpShort[] =
48 "host_os: [string] The operating system that GN is running on.";
49 const char kHostOs_Help[] =
50 R"(host_os: [string] The operating system that GN is running on.
51
52 This value is exposed so that cross-compiles can access the host build
53 system's settings.
54
55 This value should generally be treated as read-only. It, however, is not used
56 internally by GN for any purpose.
57
58 Some possible values
59
60 - "linux"
61 - "mac"
62 - "win"
63 )";
64
65 const char kInvoker[] = "invoker";
66 const char kInvoker_HelpShort[] =
67 "invoker: [string] The invoking scope inside a template.";
68 const char kInvoker_Help[] =
69 R"(invoker: [string] The invoking scope inside a template.
70
71 Inside a template invocation, this variable refers to the scope of the
72 invoker of the template. Outside of template invocations, this variable is
73 undefined.
74
75 All of the variables defined inside the template invocation are accessible as
76 members of the "invoker" scope. This is the way that templates read values
77 set by the callers.
78
79 This is often used with "defined" to see if a value is set on the invoking
80 scope.
81
82 See "gn help template" for more examples.
83
84 Example
85
86 template("my_template") {
87 print(invoker.sources) # Prints [ "a.cc", "b.cc" ]
88 print(defined(invoker.foo)) # Prints false.
89 print(defined(invoker.bar)) # Prints true.
90 }
91
92 my_template("doom_melon") {
93 sources = [ "a.cc", "b.cc" ]
94 bar = 123
95 }
96 )";
97
98 const char kTargetCpu[] = "target_cpu";
99 const char kTargetCpu_HelpShort[] =
100 "target_cpu: [string] The desired cpu architecture for the build.";
101 const char kTargetCpu_Help[] =
102 R"(target_cpu: The desired cpu architecture for the build.
103
104 This value should be used to indicate the desired architecture for the
105 primary objects of the build. It will match the cpu architecture of the
106 default toolchain, but not necessarily the current toolchain.
107
108 In many cases, this is the same as "host_cpu", but in the case of
109 cross-compiles, this can be set to something different. This value is
110 different from "current_cpu" in that it does not change based on the current
111 toolchain. When writing rules, "current_cpu" should be used rather than
112 "target_cpu" most of the time.
113
114 This value is not used internally by GN for any purpose, so it may be set to
115 whatever value is needed for the build. GN defaults this value to the empty
116 string ("") and the configuration files should set it to an appropriate value
117 (e.g., setting it to the value of "host_cpu") if it is not overridden on the
118 command line or in the args.gn file.
119
120 Possible values
121
122 - "x86"
123 - "x64"
124 - "arm"
125 - "arm64"
126 - "mipsel"
127 )";
128
129 const char kTargetName[] = "target_name";
130 const char kTargetName_HelpShort[] =
131 "target_name: [string] The name of the current target.";
132 const char kTargetName_Help[] =
133 R"(target_name: [string] The name of the current target.
134
135 Inside a target or template invocation, this variable refers to the name
136 given to the target or template invocation. Outside of these, this variable
137 is undefined.
138
139 This is most often used in template definitions to name targets defined in
140 the template based on the name of the invocation. This is necessary both to
141 ensure generated targets have unique names and to generate a target with the
142 exact name of the invocation that other targets can depend on.
143
144 Be aware that this value will always reflect the innermost scope. So when
145 defining a target inside a template, target_name will refer to the target
146 rather than the template invocation. To get the name of the template
147 invocation in this case, you should save target_name to a temporary variable
148 outside of any target definitions.
149
150 See "gn help template" for more examples.
151
152 Example
153
154 executable("doom_melon") {
155 print(target_name) # Prints "doom_melon".
156 }
157
158 template("my_template") {
159 print(target_name) # Prints "space_ray" when invoked below.
160
161 executable(target_name + "_impl") {
162 print(target_name) # Prints "space_ray_impl".
163 }
164 }
165
166 my_template("space_ray") {
167 }
168 )";
169
170 const char kTargetOs[] = "target_os";
171 const char kTargetOs_HelpShort[] =
172 "target_os: [string] The desired operating system for the build.";
173 const char kTargetOs_Help[] =
174 R"(target_os: The desired operating system for the build.
175
176 This value should be used to indicate the desired operating system for the
177 primary object(s) of the build. It will match the OS of the default
178 toolchain.
179
180 In many cases, this is the same as "host_os", but in the case of
181 cross-compiles, it may be different. This variable differs from "current_os"
182 in that it can be referenced from inside any toolchain and will always return
183 the initial value.
184
185 This should be set to the most specific value possible. So, "android" or
186 "chromeos" should be used instead of "linux" where applicable, even though
187 Android and ChromeOS are both Linux variants. This can mean that one needs to
188 write
189
190 if (target_os == "android" || target_os == "linux") {
191 # ...
192 }
193
194 and so forth.
195
196 This value is not used internally by GN for any purpose, so it may be set to
197 whatever value is needed for the build. GN defaults this value to the empty
198 string ("") and the configuration files should set it to an appropriate value
199 (e.g., setting it to the value of "host_os") if it is not set via the command
200 line or in the args.gn file.
201
202 Possible values
203
204 - "android"
205 - "chromeos"
206 - "ios"
207 - "linux"
208 - "nacl"
209 - "mac"
210 - "win"
211 )";
212
213 const char kCurrentCpu[] = "current_cpu";
214 const char kCurrentCpu_HelpShort[] =
215 "current_cpu: [string] The processor architecture of the current "
216 "toolchain.";
217 const char kCurrentCpu_Help[] =
218 R"(current_cpu: The processor architecture of the current toolchain.
219
220 The build configuration usually sets this value based on the value of
221 "host_cpu" (see "gn help host_cpu") and then threads this through the
222 toolchain definitions to ensure that it always reflects the appropriate
223 value.
224
225 This value is not used internally by GN for any purpose. It is set to the
226 empty string ("") by default but is declared so that it can be overridden on
227 the command line if so desired.
228
229 See "gn help target_cpu" for a list of common values returned.)";
230
231 const char kCurrentOs[] = "current_os";
232 const char kCurrentOs_HelpShort[] =
233 "current_os: [string] The operating system of the current toolchain.";
234 const char kCurrentOs_Help[] =
235 R"(current_os: The operating system of the current toolchain.
236
237 The build configuration usually sets this value based on the value of
238 "target_os" (see "gn help target_os"), and then threads this through the
239 toolchain definitions to ensure that it always reflects the appropriate
240 value.
241
242 This value is not used internally by GN for any purpose. It is set to the
243 empty string ("") by default but is declared so that it can be overridden on
244 the command line if so desired.
245
246 See "gn help target_os" for a list of common values returned.
247 )";
248
249 const char kCurrentToolchain[] = "current_toolchain";
250 const char kCurrentToolchain_HelpShort[] =
251 "current_toolchain: [string] Label of the current toolchain.";
252 const char kCurrentToolchain_Help[] =
253 R"(current_toolchain: Label of the current toolchain.
254
255 A fully-qualified label representing the current toolchain. You can use this
256 to make toolchain-related decisions in the build. See also
257 "default_toolchain".
258
259 Example
260
261 if (current_toolchain == "//build:64_bit_toolchain") {
262 executable("output_thats_64_bit_only") {
263 ...
264 )";
265
266 const char kDefaultToolchain[] = "default_toolchain";
267 const char kDefaultToolchain_HelpShort[] =
268 "default_toolchain: [string] Label of the default toolchain.";
269 const char kDefaultToolchain_Help[] =
270 R"(default_toolchain: [string] Label of the default toolchain.
271
272 A fully-qualified label representing the default toolchain, which may not
273 necessarily be the current one (see "current_toolchain").
274 )";
275
276 const char kPythonPath[] = "python_path";
277 const char kPythonPath_HelpShort[] =
278 "python_path: [string] Absolute path of Python.";
279 const char kPythonPath_Help[] =
280 R"(python_path: Absolute path of Python.
281
282 Normally used in toolchain definitions if running some command requires
283 Python. You will normally not need this when invoking scripts since GN
284 automatically finds it for you.
285 )";
286
287 const char kRootBuildDir[] = "root_build_dir";
288 const char kRootBuildDir_HelpShort[] =
289 "root_build_dir: [string] Directory where build commands are run.";
290 const char kRootBuildDir_Help[] =
291 R"(root_build_dir: [string] Directory where build commands are run.
292
293 This is the root build output directory which will be the current directory
294 when executing all compilers and scripts.
295
296 Most often this is used with rebase_path (see "gn help rebase_path") to
297 convert arguments to be relative to a script's current directory.
298 )";
299
300 const char kRootGenDir[] = "root_gen_dir";
301 const char kRootGenDir_HelpShort[] =
302 "root_gen_dir: [string] Directory for the toolchain's generated files.";
303 const char kRootGenDir_Help[] =
304 R"(root_gen_dir: Directory for the toolchain's generated files.
305
306 Absolute path to the root of the generated output directory tree for the
307 current toolchain. An example would be "//out/Debug/gen" for the default
308 toolchain, or "//out/Debug/arm/gen" for the "arm" toolchain.
309
310 This is primarily useful for setting up include paths for generated files. If
311 you are passing this to a script, you will want to pass it through
312 rebase_path() (see "gn help rebase_path") to convert it to be relative to the
313 build directory.
314
315 See also "target_gen_dir" which is usually a better location for generated
316 files. It will be inside the root generated dir.
317 )";
318
319 const char kRootOutDir[] = "root_out_dir";
320 const char kRootOutDir_HelpShort[] =
321 "root_out_dir: [string] Root directory for toolchain output files.";
322 const char kRootOutDir_Help[] =
323 R"(root_out_dir: [string] Root directory for toolchain output files.
324
325 Absolute path to the root of the output directory tree for the current
326 toolchain. It will not have a trailing slash.
327
328 For the default toolchain this will be the same as the root_build_dir. An
329 example would be "//out/Debug" for the default toolchain, or
330 "//out/Debug/arm" for the "arm" toolchain.
331
332 This is primarily useful for setting up script calls. If you are passing this
333 to a script, you will want to pass it through rebase_path() (see "gn help
334 rebase_path") to convert it to be relative to the build directory.
335
336 See also "target_out_dir" which is usually a better location for output
337 files. It will be inside the root output dir.
338
339 Example
340
341 action("myscript") {
342 # Pass the output dir to the script.
343 args = [ "-o", rebase_path(root_out_dir, root_build_dir) ]
344 }
345 )";
346
347 const char kTargetGenDir[] = "target_gen_dir";
348 const char kTargetGenDir_HelpShort[] =
349 "target_gen_dir: [string] Directory for a target's generated files.";
350 const char kTargetGenDir_Help[] =
351 R"(target_gen_dir: Directory for a target's generated files.
352
353 Absolute path to the target's generated file directory. This will be the
354 "root_gen_dir" followed by the relative path to the current build file. If
355 your file is in "//tools/doom_melon" then target_gen_dir would be
356 "//out/Debug/gen/tools/doom_melon". It will not have a trailing slash.
357
358 This is primarily useful for setting up include paths for generated files. If
359 you are passing this to a script, you will want to pass it through
360 rebase_path() (see "gn help rebase_path") to convert it to be relative to the
361 build directory.
362
363 See also "gn help root_gen_dir".
364
365 Example
366
367 action("myscript") {
368 # Pass the generated output dir to the script.
369 args = [ "-o", rebase_path(target_gen_dir, root_build_dir) ]"
370 }
371 )";
372
373 const char kTargetOutDir[] = "target_out_dir";
374 const char kTargetOutDir_HelpShort[] =
375 "target_out_dir: [string] Directory for target output files.";
376 const char kTargetOutDir_Help[] =
377 R"(target_out_dir: [string] Directory for target output files.
378
379 Absolute path to the target's generated file directory. If your current
380 target is in "//tools/doom_melon" then this value might be
381 "//out/Debug/obj/tools/doom_melon". It will not have a trailing slash.
382
383 This is primarily useful for setting up arguments for calling scripts. If you
384 are passing this to a script, you will want to pass it through rebase_path()
385 (see "gn help rebase_path") to convert it to be relative to the build
386 directory.
387
388 See also "gn help root_out_dir".
389
390 Example
391
392 action("myscript") {
393 # Pass the output dir to the script.
394 args = [ "-o", rebase_path(target_out_dir, root_build_dir) ]"
395 }
396 )";
397
398 // Target variables ------------------------------------------------------------
399
400 #define COMMON_ORDERING_HELP \
401 "\n" \
402 "Ordering of flags and values\n" \
403 "\n" \
404 " 1. Those set on the current target (not in a config).\n" \
405 " 2. Those set on the \"configs\" on the target in order that the\n" \
406 " configs appear in the list.\n" \
407 " 3. Those set on the \"all_dependent_configs\" on the target in order\n" \
408 " that the configs appear in the list.\n" \
409 " 4. Those set on the \"public_configs\" on the target in order that\n" \
410 " those configs appear in the list.\n" \
411 " 5. all_dependent_configs pulled from dependencies, in the order of\n" \
412 " the \"deps\" list. This is done recursively. If a config appears\n" \
413 " more than once, only the first occurence will be used.\n" \
414 " 6. public_configs pulled from dependencies, in the order of the\n" \
415 " \"deps\" list. If a dependency is public, they will be applied\n" \
416 " recursively.\n"
417
418 const char kAllDependentConfigs[] = "all_dependent_configs";
419 const char kAllDependentConfigs_HelpShort[] =
420 "all_dependent_configs: [label list] Configs to be forced on dependents.";
421 const char kAllDependentConfigs_Help[] =
422 R"(all_dependent_configs: Configs to be forced on dependents.
423
424 A list of config labels.
425
426 All targets depending on this one, and recursively, all targets depending on
427 those, will have the configs listed in this variable added to them. These
428 configs will also apply to the current target.
429
430 This addition happens in a second phase once a target and all of its
431 dependencies have been resolved. Therefore, a target will not see these
432 force-added configs in their "configs" variable while the script is running,
433 and they can not be removed. As a result, this capability should generally
434 only be used to add defines and include directories necessary to compile a
435 target's headers.
436
437 See also "public_configs".
438 )" COMMON_ORDERING_HELP;
439
440 const char kAllowCircularIncludesFrom[] = "allow_circular_includes_from";
441 const char kAllowCircularIncludesFrom_HelpShort[] =
442 "allow_circular_includes_from: [label list] Permit includes from deps.";
443 const char kAllowCircularIncludesFrom_Help[] =
444 R"(allow_circular_includes_from: Permit includes from deps.
445
446 A list of target labels. Must be a subset of the target's "deps". These
447 targets will be permitted to include headers from the current target despite
448 the dependency going in the opposite direction.
449
450 When you use this, both targets must be included in a final binary for it to
451 link. To keep linker errors from happening, it is good practice to have all
452 external dependencies depend only on one of the two targets, and to set the
453 visibility on the other to enforce this. Thus the targets will always be
454 linked together in any output.
455
456 Details
457
458 Normally, for a file in target A to include a file from target B, A must list
459 B as a dependency. This invariant is enforced by the "gn check" command (and
460 the --check flag to "gn gen" -- see "gn help check").
461
462 Sometimes, two targets might be the same unit for linking purposes (two
463 source sets or static libraries that would always be linked together in a
464 final executable or shared library) and they each include headers from the
465 other: you want A to be able to include B's headers, and B to include A's
466 headers. This is not an ideal situation but is sometimes unavoidable.
467
468 This list, if specified, lists which of the dependencies of the current
469 target can include header files from the current target. That is, if A
470 depends on B, B can only include headers from A if it is in A's
471 allow_circular_includes_from list. Normally includes must follow the
472 direction of dependencies, this flag allows them to go in the opposite
473 direction.
474
475 Danger
476
477 In the above example, A's headers are likely to include headers from A's
478 dependencies. Those dependencies may have public_configs that apply flags,
479 defines, and include paths that make those headers work properly.
480
481 With allow_circular_includes_from, B can include A's headers, and
482 transitively from A's dependencies, without having the dependencies that
483 would bring in the public_configs those headers need. The result may be
484 errors or inconsistent builds.
485
486 So when you use allow_circular_includes_from, make sure that any compiler
487 settings, flags, and include directories are the same between both targets
488 (consider putting such things in a shared config they can both reference).
489 Make sure the dependencies are also the same (you might consider a group to
490 collect such dependencies they both depend on).
491
492 Example
493
494 source_set("a") {
495 deps = [ ":b", ":a_b_shared_deps" ]
496 allow_circular_includes_from = [ ":b" ]
497 ...
498 }
499
500 source_set("b") {
501 deps = [ ":a_b_shared_deps" ]
502 # Sources here can include headers from a despite lack of deps.
503 ...
504 }
505
506 group("a_b_shared_deps") {
507 public_deps = [ ":c" ]
508 }
509 )";
510
511 const char kArflags[] = "arflags";
512 const char kArflags_HelpShort[] =
513 "arflags: [string list] Arguments passed to static_library archiver.";
514 const char kArflags_Help[] =
515 R"(arflags: Arguments passed to static_library archiver.
516
517 A list of flags passed to the archive/lib command that creates static
518 libraries.
519
520 arflags are NOT pushed to dependents, so applying arflags to source sets or
521 any other target type will be a no-op. As with ldflags, you could put the
522 arflags in a config and set that as a public or "all dependent" config, but
523 that will likely not be what you want. If you have a chain of static
524 libraries dependent on each other, this can cause the flags to propagate up
525 to other static libraries. Due to the nature of how arflags are typically
526 used, you will normally want to apply them directly on static_library targets
527 themselves.
528 )" COMMON_ORDERING_HELP;
529
530 const char kArgs[] = "args";
531 const char kArgs_HelpShort[] =
532 "args: [string list] Arguments passed to an action.";
533 const char kArgs_Help[] =
534 R"(args: (target variable) Arguments passed to an action.
535
536 For action and action_foreach targets, args is the list of arguments to pass
537 to the script. Typically you would use source expansion (see "gn help
538 source_expansion") to insert the source file names.
539
540 See also "gn help action" and "gn help action_foreach".
541 )";
542
543 const char kAssertNoDeps[] = "assert_no_deps";
544 const char kAssertNoDeps_HelpShort[] =
545 "assert_no_deps: [label pattern list] Ensure no deps on these targets.";
546 const char kAssertNoDeps_Help[] =
547 R"(assert_no_deps: Ensure no deps on these targets.
548
549 A list of label patterns.
550
551 This list is a list of patterns that must not match any of the transitive
552 dependencies of the target. These include all public, private, and data
553 dependencies, and cross shared library boundaries. This allows you to express
554 that undesirable code isn't accidentally added to downstream dependencies in
555 a way that might otherwise be difficult to notice.
556
557 Checking does not cross executable boundaries. If a target depends on an
558 executable, it's assumed that the executable is a tool that is producing part
559 of the build rather than something that is linked and distributed. This
560 allows assert_no_deps to express what is distributed in the final target
561 rather than depend on the internal build steps (which may include
562 non-distributable code).
563
564 See "gn help label_pattern" for the format of the entries in the list. These
565 patterns allow blacklisting individual targets or whole directory
566 hierarchies.
567
568 Sometimes it is desirable to enforce that many targets have no dependencies
569 on a target or set of targets. One efficient way to express this is to create
570 a group with the assert_no_deps rule on it, and make that group depend on all
571 targets you want to apply that assertion to.
572
573 Example
574
575 executable("doom_melon") {
576 deps = [ "//foo:bar" ]
577 ...
578 assert_no_deps = [
579 "//evil/*", # Don't link any code from the evil directory.
580 "//foo:test_support", # This target is also disallowed.
581 ]
582 }
583 )";
584
585 const char kBundleRootDir[] = "bundle_root_dir";
586 const char kBundleRootDir_HelpShort[] =
587 "bundle_root_dir: Expansion of {{bundle_root_dir}} in create_bundle.";
588 const char kBundleRootDir_Help[] =
589 R"(bundle_root_dir: Expansion of {{bundle_root_dir}} in create_bundle.
590
591 A string corresponding to a path in root_build_dir.
592
593 This string is used by the "create_bundle" target to expand the
594 {{bundle_root_dir}} of the "bundle_data" target it depends on. This must
595 correspond to a path under root_build_dir.
596
597 Example
598
599 bundle_data("info_plist") {
600 sources = [ "Info.plist" ]
601 outputs = [ "{{bundle_contents_dir}}/Info.plist" ]
602 }
603
604 create_bundle("doom_melon.app") {
605 deps = [ ":info_plist" ]
606 bundle_root_dir = "${root_build_dir}/doom_melon.app"
607 bundle_contents_dir = "${bundle_root_dir}/Contents"
608 bundle_resources_dir = "${bundle_contents_dir}/Resources"
609 bundle_executable_dir = "${bundle_contents_dir}/MacOS"
610 }
611 )";
612
613 const char kBundleContentsDir[] = "bundle_contents_dir";
614 const char kBundleContentsDir_HelpShort[] =
615 "bundle_contents_dir: "
616 "Expansion of {{bundle_contents_dir}} in create_bundle.";
617 const char kBundleContentsDir_Help[] =
618 R"(bundle_contents_dir: Expansion of {{bundle_contents_dir}} in
619 create_bundle.
620
621 A string corresponding to a path in $root_build_dir.
622
623 This string is used by the "create_bundle" target to expand the
624 {{bundle_contents_dir}} of the "bundle_data" target it depends on. This must
625 correspond to a path under "bundle_root_dir".
626
627 See "gn help bundle_root_dir" for examples.
628 )";
629
630 const char kBundleResourcesDir[] = "bundle_resources_dir";
631 const char kBundleResourcesDir_HelpShort[] =
632 "bundle_resources_dir: "
633 "Expansion of {{bundle_resources_dir}} in create_bundle.";
634 const char kBundleResourcesDir_Help[] =
635 R"(bundle_resources_dir
636
637 bundle_resources_dir: Expansion of {{bundle_resources_dir}} in
638 create_bundle.
639
640 A string corresponding to a path in $root_build_dir.
641
642 This string is used by the "create_bundle" target to expand the
643 {{bundle_resources_dir}} of the "bundle_data" target it depends on. This must
644 correspond to a path under "bundle_root_dir".
645
646 See "gn help bundle_root_dir" for examples.
647 )";
648
649 const char kBundleDepsFilter[] = "bundle_deps_filter";
650 const char kBundleDepsFilter_HelpShort[] =
651 "bundle_deps_filter: [label list] A list of labels that are filtered out.";
652 const char kBundleDepsFilter_Help[] =
653 R"(bundle_deps_filter: [label list] A list of labels that are filtered out.
654
655 A list of target labels.
656
657 This list contains target label patterns that should be filtered out when
658 creating the bundle. Any target matching one of those label will be removed
659 from the dependencies of the create_bundle target.
660
661 This is mostly useful when creating application extension bundle as the
662 application extension has access to runtime resources from the application
663 bundle and thus do not require a second copy.
664
665 See "gn help create_bundle" for more information.
666
667 Example
668
669 create_bundle("today_extension") {
670 deps = [
671 "//base"
672 ]
673 bundle_root_dir = "$root_out_dir/today_extension.appex"
674 bundle_deps_filter = [
675 # The extension uses //base but does not use any function calling into
676 # third_party/icu and thus does not need the icudtl.dat file.
677 "//third_party/icu:icudata",
678 ]
679 }
680 )";
681
682 const char kBundleExecutableDir[] = "bundle_executable_dir";
683 const char kBundleExecutableDir_HelpShort[] =
684 "bundle_executable_dir: "
685 "Expansion of {{bundle_executable_dir}} in create_bundle";
686 const char kBundleExecutableDir_Help[] =
687 R"(bundle_executable_dir
688
689 bundle_executable_dir: Expansion of {{bundle_executable_dir}} in
690 create_bundle.
691
692 A string corresponding to a path in $root_build_dir.
693
694 This string is used by the "create_bundle" target to expand the
695 {{bundle_executable_dir}} of the "bundle_data" target it depends on. This
696 must correspond to a path under "bundle_root_dir".
697
698 See "gn help bundle_root_dir" for examples.
699 )";
700
701 const char kCflags[] = "cflags";
702 const char kCflags_HelpShort[] =
703 "cflags: [string list] Flags passed to all C compiler variants.";
704 const char kCommonCflagsHelp[] =
705 R"(cflags*: Flags passed to the C compiler.
706
707 A list of strings.
708
709 "cflags" are passed to all invocations of the C, C++, Objective C, and
710 Objective C++ compilers.
711
712 To target one of these variants individually, use "cflags_c", "cflags_cc",
713 "cflags_objc", and "cflags_objcc", respectively. These variant-specific
714 versions of cflags* will be appended on the compiler command line after
715 "cflags".
716
717 See also "asmflags" for flags for assembly-language files.
718 )" COMMON_ORDERING_HELP;
719 const char* kCflags_Help = kCommonCflagsHelp;
720
721 const char kAsmflags[] = "asmflags";
722 const char kAsmflags_HelpShort[] =
723 "asmflags: [string list] Flags passed to the assembler.";
724 const char* kAsmflags_Help =
725 R"(asmflags: Flags passed to the assembler.
726
727 A list of strings.
728
729 "asmflags" are passed to any invocation of a tool that takes an .asm or .S
730 file as input.
731 )" COMMON_ORDERING_HELP;
732
733 const char kCflagsC[] = "cflags_c";
734 const char kCflagsC_HelpShort[] =
735 "cflags_c: [string list] Flags passed to the C compiler.";
736 const char* kCflagsC_Help = kCommonCflagsHelp;
737
738 const char kCflagsCC[] = "cflags_cc";
739 const char kCflagsCC_HelpShort[] =
740 "cflags_cc: [string list] Flags passed to the C++ compiler.";
741 const char* kCflagsCC_Help = kCommonCflagsHelp;
742
743 const char kCflagsObjC[] = "cflags_objc";
744 const char kCflagsObjC_HelpShort[] =
745 "cflags_objc: [string list] Flags passed to the Objective C compiler.";
746 const char* kCflagsObjC_Help = kCommonCflagsHelp;
747
748 const char kCflagsObjCC[] = "cflags_objcc";
749 const char kCflagsObjCC_HelpShort[] =
750 "cflags_objcc: [string list] Flags passed to the Objective C++ compiler.";
751 const char* kCflagsObjCC_Help = kCommonCflagsHelp;
752
753 const char kCheckIncludes[] = "check_includes";
754 const char kCheckIncludes_HelpShort[] =
755 "check_includes: [boolean] Controls whether a target's files are checked.";
756 const char kCheckIncludes_Help[] =
757 R"(check_includes: [boolean] Controls whether a target's files are checked.
758
759 When true (the default), the "gn check" command (as well as "gn gen" with the
760 --check flag) will check this target's sources and headers for proper
761 dependencies.
762
763 When false, the files in this target will be skipped by default. This does
764 not affect other targets that depend on the current target, it just skips
765 checking the includes of the current target's files.
766
767 If there are a few conditionally included headers that trip up checking, you
768 can exclude headers individually by annotating them with "nogncheck" (see "gn
769 help nogncheck").
770
771 The topic "gn help check" has general information on how checking works and
772 advice on how to pass a check in problematic cases.
773
774 Example
775
776 source_set("busted_includes") {
777 # This target's includes are messed up, exclude it from checking.
778 check_includes = false
779 ...
780 }
781 )";
782
783 const char kCodeSigningArgs[] = "code_signing_args";
784 const char kCodeSigningArgs_HelpShort[] =
785 "code_signing_args: [string list] Arguments passed to code signing script.";
786 const char kCodeSigningArgs_Help[] =
787 R"(code_signing_args: [string list] Arguments passed to code signing script.
788
789 For create_bundle targets, code_signing_args is the list of arguments to pass
790 to the code signing script. Typically you would use source expansion (see "gn
791 help source_expansion") to insert the source file names.
792
793 See also "gn help create_bundle".
794 )";
795
796 const char kCodeSigningScript[] = "code_signing_script";
797 const char kCodeSigningScript_HelpShort[] =
798 "code_signing_script: [file name] Script for code signing.";
799 const char kCodeSigningScript_Help[] =
800 R"(code_signing_script: [file name] Script for code signing."
801
802 An absolute or buildfile-relative file name of a Python script to run for a
803 create_bundle target to perform code signing step.
804
805 See also "gn help create_bundle".
806 )";
807
808 const char kCodeSigningSources[] = "code_signing_sources";
809 const char kCodeSigningSources_HelpShort[] =
810 "code_signing_sources: [file list] Sources for code signing step.";
811 const char kCodeSigningSources_Help[] =
812 R"(code_signing_sources: [file list] Sources for code signing step.
813
814 A list of files used as input for code signing script step of a create_bundle
815 target. Non-absolute paths will be resolved relative to the current build
816 file.
817
818 See also "gn help create_bundle".
819 )";
820
821 const char kCodeSigningOutputs[] = "code_signing_outputs";
822 const char kCodeSigningOutputs_HelpShort[] =
823 "code_signing_outputs: [file list] Output files for code signing step.";
824 const char kCodeSigningOutputs_Help[] =
825 R"(code_signing_outputs: [file list] Output files for code signing step.
826
827 Outputs from the code signing step of a create_bundle target. Must refer to
828 files in the build directory.
829
830 See also "gn help create_bundle".
831 )";
832
833 const char kCompleteStaticLib[] = "complete_static_lib";
834 const char kCompleteStaticLib_HelpShort[] =
835 "complete_static_lib: [boolean] Links all deps into a static library.";
836 const char kCompleteStaticLib_Help[] =
837 R"(complete_static_lib: [boolean] Links all deps into a static library.
838
839 A static library normally doesn't include code from dependencies, but instead
840 forwards the static libraries and source sets in its deps up the dependency
841 chain until a linkable target (an executable or shared library) is reached.
842 The final linkable target only links each static library once, even if it
843 appears more than once in its dependency graph.
844
845 In some cases the static library might be the final desired output. For
846 example, you may be producing a static library for distribution to third
847 parties. In this case, the static library should include code for all
848 dependencies in one complete package. However, complete static libraries
849 themselves are never linked into other complete static libraries. All
850 complete static libraries are for distribution and linking them in would
851 cause code duplication in this case. If the static library is not for
852 distribution, it should not be complete.
853
854 GN treats non-complete static libraries as source sets when they are linked
855 into complete static libraries. This is done because some tools like AR do
856 not handle dependent static libraries properly. This makes it easier to write
857 "alink" rules.
858
859 In rare cases it makes sense to list a header in more than one target if it
860 could be considered conceptually a member of both. libraries.
861
862 Example
863
864 static_library("foo") {
865 complete_static_lib = true
866 deps = [ "bar" ]
867 }
868 )";
869
870 const char kConfigs[] = "configs";
871 const char kConfigs_HelpShort[] =
872 "configs: [label list] Configs applying to this target or config.";
873 const char kConfigs_Help[] =
874 R"(configs: Configs applying to this target or config.
875
876 A list of config labels.
877
878 Configs on a target
879
880 When used on a target, the include_dirs, defines, etc. in each config are
881 appended in the order they appear to the compile command for each file in the
882 target. They will appear after the include_dirs, defines, etc. that the
883 target sets directly.
884
885 Since configs apply after the values set on a target, directly setting a
886 compiler flag will prepend it to the command line. If you want to append a
887 flag instead, you can put that flag in a one-off config and append that
888 config to the target's configs list.
889
890 The build configuration script will generally set up the default configs
891 applying to a given target type (see "set_defaults"). When a target is being
892 defined, it can add to or remove from this list.
893
894 Configs on a config
895
896 It is possible to create composite configs by specifying configs on a config.
897 One might do this to forward values, or to factor out blocks of settings from
898 very large configs into more manageable named chunks.
899
900 In this case, the composite config is expanded to be the concatenation of its
901 own values, and in order, the values from its sub-configs *before* anything
902 else happens. This has some ramifications:
903
904 - A target has no visibility into a config's sub-configs. Target code only
905 sees the name of the composite config. It can't remove sub-configs or opt
906 in to only parts of it. The composite config may not even be defined
907 before the target is.
908
909 - You can get duplication of values if a config is listed twice, say, on a
910 target and in a sub-config that also applies. In other cases, the configs
911 applying to a target are de-duped. It's expected that if a config is
912 listed as a sub-config that it is only used in that context. (Note that
913 it's possible to fix this and de-dupe, but it's not normally relevant and
914 complicates the implementation.)
915 )" COMMON_ORDERING_HELP
916 R"(
917 Example
918
919 # Configs on a target.
920 source_set("foo") {
921 # Don't use the default RTTI config that BUILDCONFIG applied to us.
922 configs -= [ "//build:no_rtti" ]
923
924 # Add some of our own settings.
925 configs += [ ":mysettings" ]
926 }
927
928 # Create a default_optimization config that forwards to one of a set of more
929 # specialized configs depending on build flags. This pattern is useful
930 # because it allows a target to opt in to either a default set, or a more
931 # specific set, while avoid duplicating the settings in two places.
932 config("super_optimization") {
933 cflags = [ ... ]
934 }
935 config("default_optimization") {
936 if (optimize_everything) {
937 configs = [ ":super_optimization" ]
938 } else {
939 configs = [ ":no_optimization" ]
940 }
941 }
942 )";
943
944 const char kData[] = "data";
945 const char kData_HelpShort[] =
946 "data: [file list] Runtime data file dependencies.";
947 const char kData_Help[] =
948 R"(data: Runtime data file dependencies.
949
950 Lists files or directories required to run the given target. These are
951 typically data files or directories of data files. The paths are interpreted
952 as being relative to the current build file. Since these are runtime
953 dependencies, they do not affect which targets are built or when. To declare
954 input files to a script, use "inputs".
955
956 Appearing in the "data" section does not imply any special handling such as
957 copying them to the output directory. This is just used for declaring runtime
958 dependencies. Runtime dependencies can be queried using the "runtime_deps"
959 category of "gn desc" or written during build generation via
960 "--runtime-deps-list-file".
961
962 GN doesn't require data files to exist at build-time. So actions that produce
963 files that are in turn runtime dependencies can list those generated files
964 both in the "outputs" list as well as the "data" list.
965
966 By convention, directories are listed with a trailing slash:
967 data = [ "test/data/" ]
968 However, no verification is done on these so GN doesn't enforce this. The
969 paths are just rebased and passed along when requested.
970
971 Note: On iOS and macOS, create_bundle targets will not be recursed into when
972 gathering data. See "gn help create_bundle" for details.
973
974 See "gn help runtime_deps" for how these are used.
975 )";
976
977 const char kDataDeps[] = "data_deps";
978 const char kDataDeps_HelpShort[] =
979 "data_deps: [label list] Non-linked dependencies.";
980 const char kDataDeps_Help[] =
981 R"(data_deps: Non-linked dependencies.
982
983 A list of target labels.
984
985 Specifies dependencies of a target that are not actually linked into the
986 current target. Such dependencies will be built and will be available at
987 runtime.
988
989 This is normally used for things like plugins or helper programs that a
990 target needs at runtime.
991
992 Note: On iOS and macOS, create_bundle targets will not be recursed into when
993 gathering data_deps. See "gn help create_bundle" for details.
994
995 See also "gn help deps" and "gn help data".
996
997 Example
998
999 executable("foo") {
1000 deps = [ "//base" ]
1001 data_deps = [ "//plugins:my_runtime_plugin" ]
1002 }
1003 )";
1004
1005 const char kDataKeys[] = "data_keys";
1006 const char kDataKeys_HelpShort[] =
1007 "data_keys: [string list] Keys from which to collect metadata.";
1008 const char kDataKeys_Help[] =
1009 R"(data_keys: Keys from which to collect metadata.
1010
1011 These keys are used to identify metadata to collect. If a walked target
1012 defines this key in its metadata, its value will be appended to the resulting
1013 collection.
1014
1015 See "gn help generated_file".
1016 )";
1017
1018 const char kDefines[] = "defines";
1019 const char kDefines_HelpShort[] =
1020 "defines: [string list] C preprocessor defines.";
1021 const char kDefines_Help[] =
1022 R"(defines: C preprocessor defines.
1023
1024 A list of strings
1025
1026 These strings will be passed to the C/C++ compiler as #defines. The strings
1027 may or may not include an "=" to assign a value.
1028 )" COMMON_ORDERING_HELP
1029 R"(
1030 Example
1031
1032 defines = [ "AWESOME_FEATURE", "LOG_LEVEL=3" ]
1033 )";
1034
1035 const char kDepfile[] = "depfile";
1036 const char kDepfile_HelpShort[] =
1037 "depfile: [string] File name for input dependencies for actions.";
1038 const char kDepfile_Help[] =
1039 R"(depfile: [string] File name for input dependencies for actions.
1040
1041 If nonempty, this string specifies that the current action or action_foreach
1042 target will generate the given ".d" file containing the dependencies of the
1043 input. Empty or unset means that the script doesn't generate the files.
1044
1045 A depfile should be used only when a target depends on files that are not
1046 already specified by a target's inputs and sources. Likewise, depfiles should
1047 specify only those dependencies not already included in sources or inputs.
1048
1049 The .d file should go in the target output directory. If you have more than
1050 one source file that the script is being run over, you can use the output
1051 file expansions described in "gn help action_foreach" to name the .d file
1052 according to the input."
1053
1054 The format is that of a Makefile and all paths must be relative to the root
1055 build directory. Only one output may be listed and it must match the first
1056 output of the action.
1057
1058 Although depfiles are created by an action, they should not be listed in the
1059 action's "outputs" unless another target will use the file as an input.
1060
1061 Example
1062
1063 action_foreach("myscript_target") {
1064 script = "myscript.py"
1065 sources = [ ... ]
1066
1067 # Locate the depfile in the output directory named like the
1068 # inputs but with a ".d" appended.
1069 depfile = "$relative_target_output_dir/{{source_name}}.d"
1070
1071 # Say our script uses "-o <d file>" to indicate the depfile.
1072 args = [ "{{source}}", "-o", depfile ]
1073 }
1074 )";
1075
1076 const char kDeps[] = "deps";
1077 const char kDeps_HelpShort[] =
1078 "deps: [label list] Private linked dependencies.";
1079 const char kDeps_Help[] =
1080 R"(deps: Private linked dependencies.
1081
1082 A list of target labels.
1083
1084 Specifies private dependencies of a target. Private dependencies are
1085 propagated up the dependency tree and linked to dependent targets, but do not
1086 grant the ability to include headers from the dependency. Public configs are
1087 not forwarded.
1088
1089 Details of dependency propagation
1090
1091 Source sets, shared libraries, and non-complete static libraries will be
1092 propagated up the dependency tree across groups, non-complete static
1093 libraries and source sets.
1094
1095 Executables, shared libraries, and complete static libraries will link all
1096 propagated targets and stop propagation. Actions and copy steps also stop
1097 propagation, allowing them to take a library as an input but not force
1098 dependents to link to it.
1099
1100 Propagation of all_dependent_configs and public_configs happens independently
1101 of target type. all_dependent_configs are always propagated across all types
1102 of targets, and public_configs are always propagated across public deps of
1103 all types of targets.
1104
1105 Data dependencies are propagated differently. See "gn help data_deps" and
1106 "gn help runtime_deps".
1107
1108 See also "public_deps".
1109 )";
1110
1111 const char kExterns[] = "externs";
1112 const char kExterns_HelpShort[] =
1113 "externs: [scope] Set of Rust crate-dependency pairs.";
1114 const char kExterns_Help[] =
1115 R"(externs: [scope] Set of Rust crate-dependency pairs.
1116
1117 A list, each value being a scope indicating a pair of crate name and the path
1118 to the Rust library.
1119
1120 These libraries will be passed as `--extern crate_name=path` to compiler
1121 invocation containing the current target.
1122
1123 Examples
1124
1125 executable("foo") {
1126 sources = [ "main.rs" ]
1127 externs = [{
1128 crate_name = "bar",
1129 path = "path/to/bar.rlib"
1130 }]
1131 }
1132
1133 This target would compile the `foo` crate with the following `extern` flag:
1134 `--extern bar=path/to/bar.rlib`.
1135 )";
1136
1137 const char kFriend[] = "friend";
1138 const char kFriend_HelpShort[] =
1139 "friend: [label pattern list] Allow targets to include private headers.";
1140 const char kFriend_Help[] =
1141 R"(friend: Allow targets to include private headers.
1142
1143 A list of label patterns (see "gn help label_pattern") that allow dependent
1144 targets to include private headers. Applies to all binary targets.
1145
1146 Normally if a target lists headers in the "public" list (see "gn help
1147 public"), other headers are implicitly marked as private. Private headers
1148 can not be included by other targets, even with a public dependency path.
1149 The "gn check" function performs this validation.
1150
1151 A friend declaration allows one or more targets to include private headers.
1152 This is useful for things like unit tests that are closely associated with a
1153 target and require internal knowledge without opening up all headers to be
1154 included by all dependents.
1155
1156 A friend target does not allow that target to include headers when no
1157 dependency exists. A public dependency path must still exist between two
1158 targets to include any headers from a destination target. The friend
1159 annotation merely allows the use of headers that would otherwise be
1160 prohibited because they are private.
1161
1162 The friend annotation is matched only against the target containing the file
1163 with the include directive. Friend annotations are not propagated across
1164 public or private dependencies. Friend annotations do not affect visibility.
1165
1166 Example
1167
1168 static_library("lib") {
1169 # This target can include our private headers.
1170 friend = [ ":unit_tests" ]
1171
1172 public = [
1173 "public_api.h", # Normal public API for dependent targets.
1174 ]
1175
1176 # Private API and sources.
1177 sources = [
1178 "a_source_file.cc",
1179
1180 # Normal targets that depend on this one won't be able to include this
1181 # because this target defines a list of "public" headers. Without the
1182 # "public" list, all headers are implicitly public.
1183 "private_api.h",
1184 ]
1185 }
1186
1187 executable("unit_tests") {
1188 sources = [
1189 # This can include "private_api.h" from the :lib target because it
1190 # depends on that target and because of the friend annotation.
1191 "my_test.cc",
1192 ]
1193
1194 deps = [
1195 ":lib", # Required for the include to be allowed.
1196 ]
1197 }
1198 )";
1199
1200 const char kFrameworkDirs[] = "framework_dirs";
1201 const char kFrameworkDirs_HelpShort[] =
1202 "framework_dirs: [directory list] Additional framework search directories.";
1203 const char kFrameworkDirs_Help[] =
1204 R"(framework_dirs: [directory list] Additional framework search directories.
1205
1206 A list of source directories.
1207
1208 The directories in this list will be added to the framework search path for
1209 the files in the affected target.
1210 )" COMMON_ORDERING_HELP
1211 R"(
1212 Example
1213
1214 framework_dirs = [ "src/include", "//third_party/foo" ]
1215 )";
1216
1217 const char kFrameworks[] = "frameworks";
1218 const char kFrameworks_HelpShort[] =
1219 "frameworks: [name list] Name of frameworks that must be linked.";
1220 const char kFrameworks_Help[] =
1221 R"(frameworks: [name list] Name of frameworks that must be linked.
1222
1223 A list of framework names.
1224
1225 The frameworks named in that list will be linked with any dynamic link
1226 type target.
1227 )" COMMON_ORDERING_HELP
1228 R"(
1229 Example
1230
1231 frameworks = [ "Foundation.framework", "Foo.framework" ]
1232 )";
1233
1234 const char kIncludeDirs[] = "include_dirs";
1235 const char kIncludeDirs_HelpShort[] =
1236 "include_dirs: [directory list] Additional include directories.";
1237 const char kIncludeDirs_Help[] =
1238 R"(include_dirs: Additional include directories.
1239
1240 A list of source directories.
1241
1242 The directories in this list will be added to the include path for the files
1243 in the affected target.
1244 )" COMMON_ORDERING_HELP
1245 R"(
1246 Example
1247
1248 include_dirs = [ "src/include", "//third_party/foo" ]
1249 )";
1250
1251 const char kInputs[] = "inputs";
1252 const char kInputs_HelpShort[] =
1253 "inputs: [file list] Additional compile-time dependencies.";
1254 const char kInputs_Help[] =
1255 R"(inputs: Additional compile-time dependencies.
1256
1257 Inputs are compile-time dependencies of the current target. This means that
1258 all inputs must be available before compiling any of the sources or executing
1259 any actions.
1260
1261 Inputs are typically only used for action and action_foreach targets.
1262
1263 Inputs for actions
1264
1265 For action and action_foreach targets, inputs should be the inputs to script
1266 that don't vary. These should be all .py files that the script uses via
1267 imports (the main script itself will be an implicit dependency of the action
1268 so need not be listed).
1269
1270 For action targets, inputs and sources are treated the same, but from a style
1271 perspective, it's recommended to follow the same rule as action_foreach and
1272 put helper files in the inputs, and the data used by the script (if any) in
1273 sources.
1274
1275 Note that another way to declare input dependencies from an action is to have
1276 the action write a depfile (see "gn help depfile"). This allows the script to
1277 dynamically write input dependencies, that might not be known until actually
1278 executing the script. This is more efficient than doing processing while
1279 running GN to determine the inputs, and is easier to keep in-sync than
1280 hardcoding the list.
1281
1282 Script input gotchas
1283
1284 It may be tempting to write a script that enumerates all files in a directory
1285 as inputs. Don't do this! Even if you specify all the files in the inputs or
1286 sources in the GN target (or worse, enumerate the files in an exec_script
1287 call when running GN, which will be slow), the dependencies will be broken.
1288
1289 The problem happens if a file is ever removed because the inputs are not
1290 listed on the command line to the script. Because the script hasn't changed
1291 and all inputs are up to date, the script will not re-run and you will get a
1292 stale build. Instead, either list all inputs on the command line to the
1293 script, or if there are many, create a separate list file that the script
1294 reads. As long as this file is listed in the inputs, the build will detect
1295 when it has changed in any way and the action will re-run.
1296
1297 Inputs for binary targets
1298
1299 Any input dependencies will be resolved before compiling any sources or
1300 linking the target. Normally, all actions that a target depends on will be run
1301 before any files in a target are compiled. So if you depend on generated
1302 headers, you do not typically need to list them in the inputs section.
1303
1304 Inputs for binary targets will be treated as implicit dependencies, meaning
1305 that changes in any of the inputs will force all sources in the target to be
1306 recompiled. If an input only applies to a subset of source files, you may
1307 want to split those into a separate target to avoid unnecessary recompiles.
1308
1309 Example
1310
1311 action("myscript") {
1312 script = "domything.py"
1313 inputs = [ "input.data" ]
1314 }
1315 )";
1316
1317 const char kLdflags[] = "ldflags";
1318 const char kLdflags_HelpShort[] =
1319 "ldflags: [string list] Flags passed to the linker.";
1320 const char kLdflags_Help[] =
1321 R"(ldflags: Flags passed to the linker.
1322
1323 A list of strings.
1324
1325 These flags are passed on the command-line to the linker and generally
1326 specify various linking options. Most targets will not need these and will
1327 use "libs" and "lib_dirs" instead.
1328
1329 ldflags are NOT pushed to dependents, so applying ldflags to source sets or
1330 static libraries will be a no-op. If you want to apply ldflags to dependent
1331 targets, put them in a config and set it in the all_dependent_configs or
1332 public_configs.
1333 )" COMMON_ORDERING_HELP;
1334
1335 #define COMMON_LIB_INHERITANCE_HELP \
1336 "\n" \
1337 " libs and lib_dirs work differently than other flags in two respects.\n" \
1338 " First, they are inherited across static library boundaries until a\n" \
1339 " shared library or executable target is reached. Second, they are\n" \
1340 " uniquified so each one is only passed once (the first instance of it\n" \
1341 " will be the one used).\n"
1342
1343 #define LIBS_AND_LIB_DIRS_ORDERING_HELP \
1344 "\n" \
1345 " For \"libs\" and \"lib_dirs\" only, the values propagated from\n" \
1346 " dependencies (as described above) are applied last assuming they\n" \
1347 " are not already in the list.\n"
1348
1349 const char kLibDirs[] = "lib_dirs";
1350 const char kLibDirs_HelpShort[] =
1351 "lib_dirs: [directory list] Additional library directories.";
1352 const char kLibDirs_Help[] =
1353 R"(lib_dirs: Additional library directories.
1354
1355 A list of directories.
1356
1357 Specifies additional directories passed to the linker for searching for the
1358 required libraries. If an item is not an absolute path, it will be treated as
1359 being relative to the current build file.
1360 )" COMMON_LIB_INHERITANCE_HELP COMMON_ORDERING_HELP
1361 LIBS_AND_LIB_DIRS_ORDERING_HELP
1362 R"(
1363 Example
1364
1365 lib_dirs = [ "/usr/lib/foo", "lib/doom_melon" ]
1366 )";
1367
1368 const char kLibs[] = "libs";
1369 const char kLibs_HelpShort[] =
1370 "libs: [string list] Additional libraries to link.";
1371 const char kLibs_Help[] =
1372 R"(libs: Additional libraries to link.
1373
1374 A list of library names or library paths.
1375
1376 These libraries will be linked into the final binary (executable or shared
1377 library) containing the current target.
1378 )" COMMON_LIB_INHERITANCE_HELP
1379 R"(
1380 Types of libs
1381
1382 There are several different things that can be expressed in libs:
1383
1384 File paths
1385 Values containing '/' will be treated as references to files in the
1386 checkout. They will be rebased to be relative to the build directory and
1387 specified in the "libs" for linker tools. This facility should be used
1388 for libraries that are checked in to the version control. For libraries
1389 that are generated by the build, use normal GN deps to link them.
1390
1391 System libraries
1392 Values not containing '/' will be treated as system library names. These
1393 will be passed unmodified to the linker and prefixed with the
1394 "lib_switch" attribute of the linker tool. Generally you would set the
1395 "lib_dirs" so the given library is found. Your BUILD.gn file should not
1396 specify the switch (like "-l"): this will be encoded in the "lib_switch"
1397 of the tool.
1398
1399 Apple frameworks
1400 System libraries ending in ".framework" will be special-cased: the switch
1401 "-framework" will be prepended instead of the lib_switch, and the
1402 ".framework" suffix will be trimmed. This is to support the way Mac links
1403 framework dependencies.
1404 )" COMMON_ORDERING_HELP LIBS_AND_LIB_DIRS_ORDERING_HELP
1405 R"(
1406 Examples
1407
1408 On Windows:
1409 libs = [ "ctl3d.lib" ]
1410
1411 On Linux:
1412 libs = [ "ld" ]
1413 )";
1414
1415 const char kMetadata[] = "metadata";
1416 const char kMetadata_HelpShort[] = "metadata: [scope] Metadata of this target.";
1417 const char kMetadata_Help[] =
1418 R"(metadata: Metadata of this target.
1419
1420 Metadata is a collection of keys and values relating to a particular target.
1421 Values must be lists, allowing for sane and predictable collection behavior.
1422 Generally, these keys will include three types of lists: lists of ordinary
1423 strings, lists of filenames intended to be rebased according to their
1424 particular source directory, and lists of target labels intended to be used
1425 as barriers to the walk. Verfication of these categories occurs at walk time,
1426 not creation time (since it is not clear until the walk which values are
1427 intended for which purpose).
1428
1429 Example
1430
1431 group("doom_melon") {
1432 metadata = {
1433 # These keys are not built in to GN but are interpreted when consuming
1434 # metadata.
1435 my_barrier = []
1436 my_files = [ "a.txt", "b.txt" ]
1437 }
1438 }
1439 )";
1440
1441 const char kOutputExtension[] = "output_extension";
1442 const char kOutputExtension_HelpShort[] =
1443 "output_extension: [string] Value to use for the output's file extension.";
1444 const char kOutputExtension_Help[] =
1445 R"(output_extension: Value to use for the output's file extension.
1446
1447 Normally the file extension for a target is based on the target type and the
1448 operating system, but in rare cases you will need to override the name (for
1449 example to use "libfreetype.so.6" instead of libfreetype.so on Linux).
1450
1451 This value should not include a leading dot. If undefined, the default
1452 specified on the tool will be used. If set to the empty string, no output
1453 extension will be used.
1454
1455 The output_extension will be used to set the "{{output_extension}}" expansion
1456 which the linker tool will generally use to specify the output file name. See
1457 "gn help tool".
1458
1459 Example
1460
1461 shared_library("freetype") {
1462 if (is_linux) {
1463 # Call the output "libfreetype.so.6"
1464 output_extension = "so.6"
1465 }
1466 ...
1467 }
1468
1469 # On Windows, generate a "mysettings.cpl" control panel applet. Control panel
1470 # applets are actually special shared libraries.
1471 if (is_win) {
1472 shared_library("mysettings") {
1473 output_extension = "cpl"
1474 ...
1475 }
1476 }
1477 )";
1478
1479 const char kOutputDir[] = "output_dir";
1480 const char kOutputDir_HelpShort[] =
1481 "output_dir: [directory] Directory to put output file in.";
1482 const char kOutputDir_Help[] =
1483 R"(output_dir: [directory] Directory to put output file in.
1484
1485 For library and executable targets, overrides the directory for the final
1486 output. This must be in the root_build_dir or a child thereof.
1487
1488 This should generally be in the root_out_dir or a subdirectory thereof (the
1489 root_out_dir will be the same as the root_build_dir for the default
1490 toolchain, and will be a subdirectory for other toolchains). Not putting the
1491 output in a subdirectory of root_out_dir can result in collisions between
1492 different toolchains, so you will need to take steps to ensure that your
1493 target is only present in one toolchain.
1494
1495 Normally the toolchain specifies the output directory for libraries and
1496 executables (see "gn help tool"). You will have to consult that for the
1497 default location. The default location will be used if output_dir is
1498 undefined or empty.
1499
1500 Example
1501
1502 shared_library("doom_melon") {
1503 output_dir = "$root_out_dir/plugin_libs"
1504 ...
1505 }
1506 )";
1507
1508 const char kOutputName[] = "output_name";
1509 const char kOutputName_HelpShort[] =
1510 "output_name: [string] Name for the output file other than the default.";
1511 const char kOutputName_Help[] =
1512 R"(output_name: Define a name for the output file other than the default.
1513
1514 Normally the output name of a target will be based on the target name, so the
1515 target "//foo/bar:bar_unittests" will generate an output file such as
1516 "bar_unittests.exe" (using Windows as an example).
1517
1518 Sometimes you will want an alternate name to avoid collisions or if the
1519 internal name isn't appropriate for public distribution.
1520
1521 The output name should have no extension or prefixes, these will be added
1522 using the default system rules. For example, on Linux an output name of "foo"
1523 will produce a shared library "libfoo.so". There is no way to override the
1524 output prefix of a linker tool on a per- target basis. If you need more
1525 flexibility, create a copy target to produce the file you want.
1526
1527 This variable is valid for all binary output target types.
1528
1529 Example
1530
1531 static_library("doom_melon") {
1532 output_name = "fluffy_bunny"
1533 }
1534 )";
1535
1536 const char kOutputPrefixOverride[] = "output_prefix_override";
1537 const char kOutputPrefixOverride_HelpShort[] =
1538 "output_prefix_override: [boolean] Don't use prefix for output name.";
1539 const char kOutputPrefixOverride_Help[] =
1540 R"(output_prefix_override: Don't use prefix for output name.
1541
1542 A boolean that overrides the output prefix for a target. Defaults to false.
1543
1544 Some systems use prefixes for the names of the final target output file. The
1545 normal example is "libfoo.so" on Linux for a target named "foo".
1546
1547 The output prefix for a given target type is specified on the linker tool
1548 (see "gn help tool"). Sometimes this prefix is undesired.
1549
1550 See also "gn help output_extension".
1551
1552 Example
1553
1554 shared_library("doom_melon") {
1555 # Normally this will produce "libdoom_melon.so" on Linux. Setting this flag
1556 # will produce "doom_melon.so".
1557 output_prefix_override = true
1558 ...
1559 }
1560 )";
1561
1562 const char kPartialInfoPlist[] = "partial_info_plist";
1563 const char kPartialInfoPlist_HelpShort[] =
1564 "partial_info_plist: [filename] Path plist from asset catalog compiler.";
1565 const char kPartialInfoPlist_Help[] =
1566 R"(partial_info_plist: [filename] Path plist from asset catalog compiler.
1567
1568 Valid for create_bundle target, corresponds to the path for the partial
1569 Info.plist created by the asset catalog compiler that needs to be merged
1570 with the application Info.plist (usually done by the code signing script).
1571
1572 The file will be generated regardless of whether the asset compiler has
1573 been invoked or not. See "gn help create_bundle".
1574 )";
1575
1576 const char kOutputs[] = "outputs";
1577 const char kOutputs_HelpShort[] =
1578 "outputs: [file list] Output files for actions and copy targets.";
1579 const char kOutputs_Help[] =
1580 R"(outputs: Output files for actions and copy targets.
1581
1582 Outputs is valid for "copy", "action", and "action_foreach" target types and
1583 indicates the resulting files. Outputs must always refer to files in the
1584 build directory.
1585
1586 copy
1587 Copy targets should have exactly one entry in the outputs list. If there is
1588 exactly one source, this can be a literal file name or a source expansion.
1589 If there is more than one source, this must contain a source expansion to
1590 map a single input name to a single output name. See "gn help copy".
1591
1592 action_foreach
1593 Action_foreach targets must always use source expansions to map input files
1594 to output files. There can be more than one output, which means that each
1595 invocation of the script will produce a set of files (presumably based on
1596 the name of the input file). See "gn help action_foreach".
1597
1598 action
1599 Action targets (excluding action_foreach) must list literal output file(s)
1600 with no source expansions. See "gn help action".
1601 )";
1602
1603 const char kPool[] = "pool";
1604 const char kPool_HelpShort[] =
1605 "pool: [string] Label of the pool used by the action.";
1606 const char kPool_Help[] =
1607 R"(pool: Label of the pool used by the action.
1608
1609 A fully-qualified label representing the pool that will be used for the
1610 action. Pools are defined using the pool() {...} declaration.
1611
1612 Example
1613
1614 action("action") {
1615 pool = "//build:custom_pool"
1616 ...
1617 }
1618 )";
1619
1620 const char kPrecompiledHeader[] = "precompiled_header";
1621 const char kPrecompiledHeader_HelpShort[] =
1622 "precompiled_header: [string] Header file to precompile.";
1623 const char kPrecompiledHeader_Help[] =
1624 R"(precompiled_header: [string] Header file to precompile.
1625
1626 Precompiled headers will be used when a target specifies this value, or a
1627 config applying to this target specifies this value. In addition, the tool
1628 corresponding to the source files must also specify precompiled headers (see
1629 "gn help tool"). The tool will also specify what type of precompiled headers
1630 to use, by setting precompiled_header_type to either "gcc" or "msvc".
1631
1632 The precompiled header/source variables can be specified on a target or a
1633 config, but must be the same for all configs applying to a given target since
1634 a target can only have one precompiled header.
1635
1636 If you use both C and C++ sources, the precompiled header and source file
1637 will be compiled once per language. You will want to make sure to wrap C++
1638 includes in __cplusplus #ifdefs so the file will compile in C mode.
1639
1640 GCC precompiled headers
1641
1642 When using GCC-style precompiled headers, "precompiled_source" contains the
1643 path of a .h file that is precompiled and then included by all source files
1644 in targets that set "precompiled_source".
1645
1646 The value of "precompiled_header" is not used with GCC-style precompiled
1647 headers.
1648
1649 MSVC precompiled headers
1650
1651 When using MSVC-style precompiled headers, the "precompiled_header" value is
1652 a string corresponding to the header. This is NOT a path to a file that GN
1653 recognises, but rather the exact string that appears in quotes after
1654 an #include line in source code. The compiler will match this string against
1655 includes or forced includes (/FI).
1656
1657 MSVC also requires a source file to compile the header with. This must be
1658 specified by the "precompiled_source" value. In contrast to the header value,
1659 this IS a GN-style file name, and tells GN which source file to compile to
1660 make the .pch file used for subsequent compiles.
1661
1662 For example, if the toolchain specifies MSVC headers:
1663
1664 toolchain("vc_x64") {
1665 ...
1666 tool("cxx") {
1667 precompiled_header_type = "msvc"
1668 ...
1669
1670 You might make a config like this:
1671
1672 config("use_precompiled_headers") {
1673 precompiled_header = "build/precompile.h"
1674 precompiled_source = "//build/precompile.cc"
1675
1676 # Either your source files should #include "build/precompile.h"
1677 # first, or you can do this to force-include the header.
1678 cflags = [ "/FI$precompiled_header" ]
1679 }
1680
1681 And then define a target that uses the config:
1682
1683 executable("doom_melon") {
1684 configs += [ ":use_precompiled_headers" ]
1685 ...
1686 )";
1687
1688 const char kPrecompiledHeaderType[] = "precompiled_header_type";
1689 const char kPrecompiledHeaderType_HelpShort[] =
1690 "precompiled_header_type: [string] \"gcc\" or \"msvc\".";
1691 const char kPrecompiledHeaderType_Help[] =
1692 R"(precompiled_header_type: [string] "gcc" or "msvc".
1693
1694 See "gn help precompiled_header".
1695 )";
1696
1697 const char kPrecompiledSource[] = "precompiled_source";
1698 const char kPrecompiledSource_HelpShort[] =
1699 "precompiled_source: [file name] Source file to precompile.";
1700 const char kPrecompiledSource_Help[] =
1701 R"(precompiled_source: [file name] Source file to precompile.
1702
1703 The source file that goes along with the precompiled_header when using
1704 "msvc"-style precompiled headers. It will be implicitly added to the sources
1705 of the target. See "gn help precompiled_header".
1706 )";
1707
1708 const char kProductType[] = "product_type";
1709 const char kProductType_HelpShort[] =
1710 "product_type: [string] Product type for Xcode projects.";
1711 const char kProductType_Help[] =
1712 R"(product_type: Product type for Xcode projects.
1713
1714 Correspond to the type of the product of a create_bundle target. Only
1715 meaningful to Xcode (used as part of the Xcode project generation).
1716
1717 When generating Xcode project files, only create_bundle target with a
1718 non-empty product_type will have a corresponding target in Xcode project.
1719 )";
1720
1721 const char kPublic[] = "public";
1722 const char kPublic_HelpShort[] =
1723 "public: [file list] Declare public header files for a target.";
1724 const char kPublic_Help[] =
1725 R"(public: Declare public header files for a target.
1726
1727 A list of files that other targets can include. These permissions are checked
1728 via the "check" command (see "gn help check").
1729
1730 If no public files are declared, other targets (assuming they have visibility
1731 to depend on this target) can include any file in the sources list. If this
1732 variable is defined on a target, dependent targets may only include files on
1733 this whitelist unless that target is marked as a friend (see "gn help
1734 friend").
1735
1736 Header file permissions are also subject to visibility. A target must be
1737 visible to another target to include any files from it at all and the public
1738 headers indicate which subset of those files are permitted. See "gn help
1739 visibility" for more.
1740
1741 Public files are inherited through the dependency tree. So if there is a
1742 dependency A -> B -> C, then A can include C's public headers. However, the
1743 same is NOT true of visibility, so unless A is in C's visibility list, the
1744 include will be rejected.
1745
1746 GN only knows about files declared in the "sources" and "public" sections of
1747 targets. If a file is included that is not known to the build, it will be
1748 allowed.
1749
1750 It is common for test targets to need to include private headers for their
1751 associated code. In this case, list the test target in the "friend" list of
1752 the target that owns the private header to allow the inclusion. See
1753 "gn help friend" for more.
1754
1755 When a binary target has no explicit or implicit public headers (a "public"
1756 list is defined but is empty), GN assumes that the target can not propagate
1757 any compile-time dependencies up the dependency tree. In this case, the build
1758 can be parallelized more efficiently.
1759 Say there are dependencies:
1760 A (shared library) -> B (shared library) -> C (action).
1761 Normally C must complete before any source files in A can compile (because
1762 there might be generated includes). But when B explicitly declares no public
1763 headers, C can execute in parallel with A's compile steps. C must still be
1764 complete before any dependents link.
1765
1766 Examples
1767
1768 These exact files are public:
1769 public = [ "foo.h", "bar.h" ]
1770
1771 No files are public (no targets may include headers from this one):
1772 # This allows starting compilation in dependent targets earlier.
1773 public = []
1774 )";
1775
1776 const char kPublicConfigs[] = "public_configs";
1777 const char kPublicConfigs_HelpShort[] =
1778 "public_configs: [label list] Configs applied to dependents.";
1779 const char kPublicConfigs_Help[] =
1780 R"(public_configs: Configs to be applied on dependents.
1781
1782 A list of config labels.
1783
1784 Targets directly depending on this one will have the configs listed in this
1785 variable added to them. These configs will also apply to the current target.
1786 Generally, public configs are used to apply defines and include directories
1787 necessary to compile this target's header files.
1788
1789 See also "gn help all_dependent_configs".
1790
1791 Propagation of public configs
1792
1793 Public configs are applied to all targets that depend directly on this one.
1794 These dependant targets can further push this target's public configs
1795 higher in the dependency tree by depending on it via public_deps (see "gn
1796 help public_deps").
1797
1798 static_library("toplevel") {
1799 # This target will get "my_config" applied to it. However, since this
1800 # target uses "deps" and not "public_deps", targets that depend on this
1801 # one won't get it.
1802 deps = [ ":intermediate" ]
1803 }
1804
1805 static_library("intermediate") {
1806 # Depending on "lower" in any way will apply "my_config" to this target.
1807 # Additionall, since this target depends on "lower" via public_deps,
1808 # targets that depend on this one will also get "my_config".
1809 public_deps = [ ":lower" ]
1810 }
1811
1812 static_library("lower") {
1813 # This will get applied to all targets that depend on this one.
1814 public_configs = [ ":my_config" ]
1815 }
1816
1817 Public config propagation happens in a second phase once a target and all of
1818 its dependencies have been resolved. Therefore, a target will not see these
1819 force-added configs in their "configs" variable while the script is running,
1820 and they can not be removed. As a result, this capability should generally
1821 only be used to add defines and include directories rather than setting
1822 complicated flags that some targets may not want.
1823
1824 Public configs may or may not be propagated across toolchain boundaries
1825 depending on the value of the propagates_configs flag (see "gn help
1826 toolchain") on the toolchain of the target declaring the public_config.
1827
1828 Avoiding applying public configs to this target
1829
1830 If you want the config to apply to targets that depend on this one, but NOT
1831 this one, define an extra layer of indirection using a group:
1832
1833 # External targets depend on this group.
1834 group("my_target") {
1835 # Config to apply to all targets that depend on this one.
1836 public_configs = [ ":external_settings" ]
1837 deps = [ ":internal_target" ]
1838 }
1839
1840 # Internal target to actually compile the sources.
1841 static_library("internal_target") {
1842 # Force all external targets to depend on the group instead of directly
1843 # on this so the "external_settings" config will get applied.
1844 visibility = [ ":my_target" ]
1845 ...
1846 }
1847
1848 )" COMMON_ORDERING_HELP;
1849
1850 const char kPublicDeps[] = "public_deps";
1851 const char kPublicDeps_HelpShort[] =
1852 "public_deps: [label list] Declare public dependencies.";
1853 const char kPublicDeps_Help[] =
1854 R"(public_deps: Declare public dependencies.
1855
1856 Public dependencies are like private dependencies (see "gn help deps") but
1857 additionally express that the current target exposes the listed deps as part
1858 of its public API.
1859
1860 This has several ramifications:
1861
1862 - public_configs that are part of the dependency are forwarded to direct
1863 dependents.
1864
1865 - Public headers in the dependency are usable by dependents (includes do
1866 not require a direct dependency or visibility).
1867
1868 - If the current target is a shared library, other shared libraries that it
1869 publicly depends on (directly or indirectly) are propagated up the
1870 dependency tree to dependents for linking.
1871
1872 See also "gn help public_configs".
1873
1874 Discussion
1875
1876 Say you have three targets: A -> B -> C. C's visibility may allow B to depend
1877 on it but not A. Normally, this would prevent A from including any headers
1878 from C, and C's public_configs would apply only to B.
1879
1880 If B lists C in its public_deps instead of regular deps, A will now inherit
1881 C's public_configs and the ability to include C's public headers.
1882
1883 Generally if you are writing a target B and you include C's headers as part
1884 of B's public headers, or targets depending on B should consider B and C to
1885 be part of a unit, you should use public_deps instead of deps.
1886
1887 Example
1888
1889 # This target can include files from "c" but not from
1890 # "super_secret_implementation_details".
1891 executable("a") {
1892 deps = [ ":b" ]
1893 }
1894
1895 shared_library("b") {
1896 deps = [ ":super_secret_implementation_details" ]
1897 public_deps = [ ":c" ]
1898 }
1899 )";
1900
1901 const char kRebase[] = "rebase";
1902 const char kRebase_HelpShort[] =
1903 "rebase: [boolean] Rebase collected metadata as files.";
1904 const char kRebase_Help[] =
1905 R"(rebase: Rebase collected metadata as files.
1906
1907 A boolean that triggers a rebase of collected metadata strings based on their
1908 declared file. Defaults to false.
1909
1910 Metadata generally declares files as strings relative to the local build file.
1911 However, this data is often used in other contexts, and so setting this flag
1912 will force the metadata collection to be rebased according to the local build
1913 file's location and thus allow the filename to be used anywhere.
1914
1915 Setting this flag will raise an error if any target's specified metadata is
1916 not a string value.
1917
1918 See also "gn help generated_file".
1919 )";
1920
1921 const char kResponseFileContents[] = "response_file_contents";
1922 const char kResponseFileContents_HelpShort[] =
1923 "response_file_contents: [string list] Contents of .rsp file for actions.";
1924 const char kResponseFileContents_Help[] =
1925 R"*(response_file_contents: Contents of a response file for actions.
1926
1927 Sometimes the arguments passed to a script can be too long for the system's
1928 command-line capabilities. This is especially the case on Windows where the
1929 maximum command-line length is less than 8K. A response file allows you to
1930 pass an unlimited amount of data to a script in a temporary file for an
1931 action or action_foreach target.
1932
1933 If the response_file_contents variable is defined and non-empty, the list
1934 will be treated as script args (including possibly substitution patterns)
1935 that will be written to a temporary file at build time. The name of the
1936 temporary file will be substituted for "{{response_file_name}}" in the script
1937 args.
1938
1939 The response file contents will always be quoted and escaped according to
1940 Unix shell rules. To parse the response file, the Python script should use
1941 "shlex.split(file_contents)".
1942
1943 Example
1944
1945 action("process_lots_of_files") {
1946 script = "process.py",
1947 inputs = [ ... huge list of files ... ]
1948
1949 # Write all the inputs to a response file for the script. Also,
1950 # make the paths relative to the script working directory.
1951 response_file_contents = rebase_path(inputs, root_build_dir)
1952
1953 # The script expects the name of the response file in --file-list.
1954 args = [
1955 "--enable-foo",
1956 "--file-list={{response_file_name}}",
1957 ]
1958 }
1959 )*";
1960
1961 const char kScript[] = "script";
1962 const char kScript_HelpShort[] = "script: [file name] Script file for actions.";
1963 const char kScript_Help[] =
1964 R"(script: Script file for actions.
1965
1966 An absolute or buildfile-relative file name of a Python script to run for a
1967 action and action_foreach targets (see "gn help action" and "gn help
1968 action_foreach").
1969 )";
1970
1971 const char kSources[] = "sources";
1972 const char kSources_HelpShort[] =
1973 "sources: [file list] Source files for a target.";
1974 const char kSources_Help[] =
1975 R"(sources: Source files for a target
1976
1977 A list of files. Non-absolute paths will be resolved relative to the current
1978 build file.
1979
1980 Sources for binary targets
1981
1982 For binary targets (source sets, executables, and libraries), the known file
1983 types will be compiled with the associated tools. Unknown file types and
1984 headers will be skipped. However, you should still list all C/C+ header files
1985 so GN knows about the existence of those files for the purposes of include
1986 checking.
1987
1988 As a special case, a file ending in ".def" will be treated as a Windows
1989 module definition file. It will be appended to the link line with a
1990 preceding "/DEF:" string. There must be at most one .def file in a target
1991 and they do not cross dependency boundaries (so specifying a .def file in a
1992 static library or source set will have no effect on the executable or shared
1993 library they're linked into).
1994
1995 For Rust targets that do not specify a crate_root, then the crate_root will
1996 look for a lib.rs file (or main.rs for executable) or a single file in
1997 sources, if sources contains only one file.
1998
1999 Sources for non-binary targets
2000
2001 action_foreach
2002 The sources are the set of files that the script will be executed over. The
2003 script will run once per file.
2004
2005 action
2006 The sources will be treated the same as inputs. See "gn help inputs" for
2007 more information and usage advice.
2008
2009 copy
2010 The source are the source files to copy.
2011 )";
2012
2013 const char kXcodeTestApplicationName[] = "xcode_test_application_name";
2014 const char kXcodeTestApplicationName_HelpShort[] =
2015 "xcode_test_application_name: [string] Name for Xcode test target.";
2016 const char kXcodeTestApplicationName_Help[] =
2017 R"(xcode_test_application_name: Name for Xcode test target.
2018
2019 Each unit and ui test target must have a test application target, and this
2020 value is used to specify the relationship. Only meaningful to Xcode (used as
2021 part of the Xcode project generation).
2022
2023 See "gn help create_bundle" for more information.
2024
2025 Example
2026
2027 create_bundle("chrome_xctest") {
2028 test_application_name = "chrome"
2029 ...
2030 }
2031 )";
2032
2033 const char kTestonly[] = "testonly";
2034 const char kTestonly_HelpShort[] =
2035 "testonly: [boolean] Declares a target must only be used for testing.";
2036 const char kTestonly_Help[] =
2037 R"(testonly: Declares a target must only be used for testing.
2038
2039 Boolean. Defaults to false.
2040
2041 When a target is marked "testonly = true", it must only be depended on by
2042 other test-only targets. Otherwise, GN will issue an error that the
2043 depenedency is not allowed.
2044
2045 This feature is intended to prevent accidentally shipping test code in a
2046 final product.
2047
2048 Example
2049
2050 source_set("test_support") {
2051 testonly = true
2052 ...
2053 }
2054 )";
2055
2056 const char kVisibility[] = "visibility";
2057 const char kVisibility_HelpShort[] =
2058 "visibility: [label list] A list of labels that can depend on a target.";
2059 const char kVisibility_Help[] =
2060 R"(visibility: A list of labels that can depend on a target.
2061
2062 A list of labels and label patterns that define which targets can depend on
2063 the current one. These permissions are checked via the "check" command (see
2064 "gn help check").
2065
2066 If visibility is not defined, it defaults to public ("*").
2067
2068 If visibility is defined, only the targets with labels that match it can
2069 depend on the current target. The empty list means no targets can depend on
2070 the current target.
2071
2072 Tip: Often you will want the same visibility for all targets in a BUILD file.
2073 In this case you can just put the definition at the top, outside of any
2074 target, and the targets will inherit that scope and see the definition.
2075
2076 Patterns
2077
2078 See "gn help label_pattern" for more details on what types of patterns are
2079 supported. If a toolchain is specified, only targets in that toolchain will
2080 be matched. If a toolchain is not specified on a pattern, targets in all
2081 toolchains will be matched.
2082
2083 Examples
2084
2085 Only targets in the current buildfile ("private"):
2086 visibility = [ ":*" ]
2087
2088 No targets (used for targets that should be leaf nodes):
2089 visibility = []
2090
2091 Any target ("public", the default):
2092 visibility = [ "*" ]
2093
2094 All targets in the current directory and any subdirectory:
2095 visibility = [ "./*" ]
2096
2097 Any target in "//bar/BUILD.gn":
2098 visibility = [ "//bar:*" ]
2099
2100 Any target in "//bar/" or any subdirectory thereof:
2101 visibility = [ "//bar/*" ]
2102
2103 Just these specific targets:
2104 visibility = [ ":mything", "//foo:something_else" ]
2105
2106 Any target in the current directory and any subdirectory thereof, plus
2107 any targets in "//bar/" and any subdirectory thereof.
2108 visibility = [ "./*", "//bar/*" ]
2109 )";
2110
2111 const char kWalkKeys[] = "walk_keys";
2112 const char kWalkKeys_HelpShort[] =
2113 "walk_keys: [string list] Key(s) for managing the metadata collection "
2114 "walk.";
2115 const char kWalkKeys_Help[] =
2116 R"(walk_keys: Key(s) for managing the metadata collection walk.
2117
2118 Defaults to [""].
2119
2120 These keys are used to control the next step in a collection walk, acting as
2121 barriers. If a specified key is defined in a target's metadata, the walk will
2122 use the targets listed in that value to determine which targets are walked.
2123
2124 If no walk_keys are specified for a generated_file target (i.e. "[""]"), the
2125 walk will touch all deps and data_deps of the specified target recursively.
2126
2127 See "gn help generated_file".
2128 )";
2129
2130 const char kWriteValueContents[] = "contents";
2131 const char kWriteValueContents_HelpShort[] =
2132 "contents: Contents to write to file.";
2133 const char kWriteValueContents_Help[] =
2134 R"(contents: Contents to write to file.
2135
2136 The contents of the file for a generated_file target.
2137 See "gn help generated_file".
2138 )";
2139
2140 const char kWriteOutputConversion[] = "output_conversion";
2141 const char kWriteOutputConversion_HelpShort[] =
2142 "output_conversion: Data format for generated_file targets.";
2143 const char kWriteOutputConversion_Help[] =
2144 R"(output_conversion: Data format for generated_file targets.
2145
2146 Controls how the "contents" of a generated_file target is formatted.
2147 See "gn help io_conversion".
2148 )";
2149
2150 const char kWriteRuntimeDeps[] = "write_runtime_deps";
2151 const char kWriteRuntimeDeps_HelpShort[] =
2152 "write_runtime_deps: Writes the target's runtime_deps to the given path.";
2153 const char kWriteRuntimeDeps_Help[] =
2154 R"(write_runtime_deps: Writes the target's runtime_deps to the given path.
2155
2156 Does not synchronously write the file, but rather schedules it to be written
2157 at the end of generation.
2158
2159 If the file exists and the contents are identical to that being written, the
2160 file will not be updated. This will prevent unnecessary rebuilds of targets
2161 that depend on this file.
2162
2163 Path must be within the output directory.
2164
2165 See "gn help runtime_deps" for how the runtime dependencies are computed.
2166
2167 The format of this file will list one file per line with no escaping. The
2168 files will be relative to the root_build_dir. The first line of the file will
2169 be the main output file of the target itself. The file contents will be the
2170 same as requesting the runtime deps be written on the command line (see "gn
2171 help --runtime-deps-list-file").
2172 )";
2173
2174 const char kXcodeExtraAttributes[] = "xcode_extra_attributes";
2175 const char kXcodeExtraAttributes_HelpShort[] =
2176 "xcode_extra_attributes: [scope] Extra attributes for Xcode projects.";
2177 const char kXcodeExtraAttributes_Help[] =
2178 R"(xcode_extra_attributes: [scope] Extra attributes for Xcode projects.
2179
2180 The value defined in this scope will be copied to the EXTRA_ATTRIBUTES
2181 property of the generated Xcode project. They are only meaningful when
2182 generating with --ide=xcode.
2183
2184 See "gn help create_bundle" for more information.
2185 )";
2186
2187 // -----------------------------------------------------------------------------
2188
VariableInfo()2189 VariableInfo::VariableInfo() : help_short(""), help("") {}
2190
2191 VariableInfo::VariableInfo(const char* in_help_short, const char* in_help)
2192 : help_short(in_help_short), help(in_help) {}
2193
2194 #define INSERT_VARIABLE(var) \
2195 info_map[k##var] = VariableInfo(k##var##_HelpShort, k##var##_Help);
2196
2197 const VariableInfoMap& GetBuiltinVariables() {
2198 static VariableInfoMap info_map;
2199 if (info_map.empty()) {
2200 INSERT_VARIABLE(CurrentCpu)
2201 INSERT_VARIABLE(CurrentOs)
2202 INSERT_VARIABLE(CurrentToolchain)
2203 INSERT_VARIABLE(DefaultToolchain)
2204 INSERT_VARIABLE(GnVersion)
2205 INSERT_VARIABLE(HostCpu)
2206 INSERT_VARIABLE(HostOs)
2207 INSERT_VARIABLE(Invoker)
2208 INSERT_VARIABLE(PythonPath)
2209 INSERT_VARIABLE(RootBuildDir)
2210 INSERT_VARIABLE(RootGenDir)
2211 INSERT_VARIABLE(RootOutDir)
2212 INSERT_VARIABLE(TargetCpu)
2213 INSERT_VARIABLE(TargetGenDir)
2214 INSERT_VARIABLE(TargetName)
2215 INSERT_VARIABLE(TargetOs)
2216 INSERT_VARIABLE(TargetOutDir)
2217 }
2218 return info_map;
2219 }
2220
2221 const VariableInfoMap& GetTargetVariables() {
2222 static VariableInfoMap info_map;
2223 if (info_map.empty()) {
2224 INSERT_VARIABLE(AllDependentConfigs)
2225 INSERT_VARIABLE(AllowCircularIncludesFrom)
2226 INSERT_VARIABLE(Arflags)
2227 INSERT_VARIABLE(Args)
2228 INSERT_VARIABLE(Asmflags)
2229 INSERT_VARIABLE(AssertNoDeps)
2230 INSERT_VARIABLE(BundleRootDir)
2231 INSERT_VARIABLE(BundleContentsDir)
2232 INSERT_VARIABLE(BundleResourcesDir)
2233 INSERT_VARIABLE(BundleDepsFilter)
2234 INSERT_VARIABLE(BundleExecutableDir)
2235 INSERT_VARIABLE(Cflags)
2236 INSERT_VARIABLE(CflagsC)
2237 INSERT_VARIABLE(CflagsCC)
2238 INSERT_VARIABLE(CflagsObjC)
2239 INSERT_VARIABLE(CflagsObjCC)
2240 INSERT_VARIABLE(CheckIncludes)
2241 INSERT_VARIABLE(CodeSigningArgs)
2242 INSERT_VARIABLE(CodeSigningScript)
2243 INSERT_VARIABLE(CodeSigningSources)
2244 INSERT_VARIABLE(CodeSigningOutputs)
2245 INSERT_VARIABLE(CompleteStaticLib)
2246 INSERT_VARIABLE(Configs)
2247 INSERT_VARIABLE(Data)
2248 INSERT_VARIABLE(DataDeps)
2249 INSERT_VARIABLE(DataKeys)
2250 INSERT_VARIABLE(Defines)
2251 INSERT_VARIABLE(Depfile)
2252 INSERT_VARIABLE(Deps)
2253 INSERT_VARIABLE(Externs)
2254 INSERT_VARIABLE(Friend)
2255 INSERT_VARIABLE(FrameworkDirs)
2256 INSERT_VARIABLE(Frameworks)
2257 INSERT_VARIABLE(IncludeDirs)
2258 INSERT_VARIABLE(Inputs)
2259 INSERT_VARIABLE(Ldflags)
2260 INSERT_VARIABLE(Libs)
2261 INSERT_VARIABLE(LibDirs)
2262 INSERT_VARIABLE(Metadata)
2263 INSERT_VARIABLE(OutputDir)
2264 INSERT_VARIABLE(OutputExtension)
2265 INSERT_VARIABLE(OutputName)
2266 INSERT_VARIABLE(OutputPrefixOverride)
2267 INSERT_VARIABLE(Outputs)
2268 INSERT_VARIABLE(PartialInfoPlist)
2269 INSERT_VARIABLE(Pool)
2270 INSERT_VARIABLE(PrecompiledHeader)
2271 INSERT_VARIABLE(PrecompiledHeaderType)
2272 INSERT_VARIABLE(PrecompiledSource)
2273 INSERT_VARIABLE(ProductType)
2274 INSERT_VARIABLE(Public)
2275 INSERT_VARIABLE(PublicConfigs)
2276 INSERT_VARIABLE(PublicDeps)
2277 INSERT_VARIABLE(Rebase)
2278 INSERT_VARIABLE(ResponseFileContents)
2279 INSERT_VARIABLE(Script)
2280 INSERT_VARIABLE(Sources)
2281 INSERT_VARIABLE(XcodeTestApplicationName)
2282 INSERT_VARIABLE(Testonly)
2283 INSERT_VARIABLE(Visibility)
2284 INSERT_VARIABLE(WalkKeys)
2285 INSERT_VARIABLE(WriteOutputConversion)
2286 INSERT_VARIABLE(WriteValueContents)
2287 INSERT_VARIABLE(WriteRuntimeDeps)
2288 INSERT_VARIABLE(XcodeExtraAttributes)
2289 InsertRustVariables(&info_map);
2290 }
2291 return info_map;
2292 }
2293
2294 #undef INSERT_VARIABLE
2295
2296 } // namespace variables
2297