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.
5 #include "tools/gn/variables.h"
9 // Built-in variables ----------------------------------------------------------
11 const char kHostCpu
[] = "host_cpu";
12 const char kHostCpu_HelpShort
[] =
13 "host_cpu: [string] The processor architecture that GN is running on.";
14 const char kHostCpu_Help
[] =
15 "host_cpu: The processor architecture that GN is running on.\n"
17 " This is value is exposed so that cross-compile toolchains can\n"
18 " access the host architecture when needed.\n"
20 " The value should generally be considered read-only, but it can be\n"
21 " overriden in order to handle unusual cases where there might\n"
22 " be multiple plausible values for the host architecture (e.g., if\n"
23 " you can do either 32-bit or 64-bit builds). The value is not used\n"
24 " internally by GN for any purpose.\n"
26 "Some possible values:\n"
30 const char kHostOs
[] = "host_os";
31 const char kHostOs_HelpShort
[] =
32 "host_os: [string] The operating system that GN is running on.";
33 const char kHostOs_Help
[] =
34 "host_os: [string] The operating system that GN is running on.\n"
36 " This value is exposed so that cross-compiles can access the host\n"
37 " build system's settings.\n"
39 " This value should generally be treated as read-only. It, however,\n"
40 " is not used internally by GN for any purpose.\n"
42 "Some possible values:\n"
47 const char kTargetCpu
[] = "target_cpu";
48 const char kTargetCpu_HelpShort
[] =
49 "target_cpu: [string] The desired cpu architecture for the build.";
50 const char kTargetCpu_Help
[] =
51 "target_cpu: The desired cpu architecture for the build.\n"
53 " This value should be used to indicate the desired architecture for\n"
54 " the primary objects of the build. It will match the cpu architecture\n"
55 " of the default toolchain.\n"
57 " In many cases, this is the same as \"host_cpu\", but in the case\n"
58 " of cross-compiles, this can be set to something different. This \n"
59 " value is different from \"current_cpu\" in that it can be referenced\n"
60 " from inside any toolchain. This value can also be ignored if it is\n"
61 " not needed or meaningful for a project.\n"
63 " This value is not used internally by GN for any purpose, so it\n"
64 " may be set to whatever value is needed for the build.\n"
65 " GN defaults this value to the empty string (\"\") and the\n"
66 " configuration files should set it to an appropriate value\n"
67 " (e.g., setting it to the value of \"host_cpu\") if it is not\n"
68 " overridden on the command line or in the args.gn file.\n"
70 " Where practical, use one of the following list of common values:\n"
79 const char kTargetOs
[] = "target_os";
80 const char kTargetOs_HelpShort
[] =
81 "target_os: [string] The desired operating system for the build.";
82 const char kTargetOs_Help
[] =
83 "target_os: The desired operating system for the build.\n"
85 " This value should be used to indicate the desired operating system\n"
86 " for the primary object(s) of the build. It will match the OS of\n"
87 " the default toolchain.\n"
89 " In many cases, this is the same as \"host_os\", but in the case of\n"
90 " cross-compiles, it may be different. This variable differs from\n"
91 " \"current_os\" in that it can be referenced from inside any\n"
92 " toolchain and will always return the initial value.\n"
94 " This should be set to the most specific value possible. So,\n"
95 " \"android\" or \"chromeos\" should be used instead of \"linux\"\n"
96 " where applicable, even though Android and ChromeOS are both Linux\n"
97 " variants. This can mean that one needs to write\n"
99 " if (target_os == \"android\" || target_os == \"linux\") {\n"
105 " This value is not used internally by GN for any purpose, so it\n"
106 " may be set to whatever value is needed for the build.\n"
107 " GN defaults this value to the empty string (\"\") and the\n"
108 " configuration files should set it to an appropriate value\n"
109 " (e.g., setting it to the value of \"host_os\") if it is not\n"
110 " set via the command line or in the args.gn file.\n"
112 " Where practical, use one of the following list of common values:\n"
123 const char kCurrentCpu
[] = "current_cpu";
124 const char kCurrentCpu_HelpShort
[] =
125 "current_cpu: [string] The processor architecture of the current "
127 const char kCurrentCpu_Help
[] =
128 "current_cpu: The processor architecture of the current toolchain.\n"
130 " The build configuration usually sets this value based on the value\n"
131 " of \"host_cpu\" (see \"gn help host_cpu\") and then threads\n"
132 " this through the toolchain definitions to ensure that it always\n"
133 " reflects the appropriate value.\n"
135 " This value is not used internally by GN for any purpose. It is\n"
136 " set it to the empty string (\"\") by default but is declared so\n"
137 " that it can be overridden on the command line if so desired.\n"
139 " See \"gn help target_cpu\" for a list of common values returned.\n";
141 const char kCurrentOs
[] = "current_os";
142 const char kCurrentOs_HelpShort
[] =
143 "current_os: [string] The operating system of the current toolchain.";
144 const char kCurrentOs_Help
[] =
145 "current_os: The operating system of the current toolchain.\n"
147 " The build configuration usually sets this value based on the value\n"
148 " of \"target_os\" (see \"gn help target_os\"), and then threads this\n"
149 " through the toolchain definitions to ensure that it always reflects\n"
150 " the appropriate value.\n"
152 " This value is not used internally by GN for any purpose. It is\n"
153 " set it to the empty string (\"\") by default but is declared so\n"
154 " that it can be overridden on the command line if so desired.\n"
156 " See \"gn help target_os\" for a list of common values returned.\n";
158 const char kCurrentToolchain
[] = "current_toolchain";
159 const char kCurrentToolchain_HelpShort
[] =
160 "current_toolchain: [string] Label of the current toolchain.";
161 const char kCurrentToolchain_Help
[] =
162 "current_toolchain: Label of the current toolchain.\n"
164 " A fully-qualified label representing the current toolchain. You can\n"
165 " use this to make toolchain-related decisions in the build. See also\n"
166 " \"default_toolchain\".\n"
170 " if (current_toolchain == \"//build:64_bit_toolchain\") {\n"
171 " executable(\"output_thats_64_bit_only\") {\n"
174 const char kDefaultToolchain
[] = "default_toolchain";
175 const char kDefaultToolchain_HelpShort
[] =
176 "default_toolchain: [string] Label of the default toolchain.";
177 const char kDefaultToolchain_Help
[] =
178 "default_toolchain: [string] Label of the default toolchain.\n"
180 " A fully-qualified label representing the default toolchain, which may\n"
181 " not necessarily be the current one (see \"current_toolchain\").\n";
183 const char kPythonPath
[] = "python_path";
184 const char kPythonPath_HelpShort
[] =
185 "python_path: [string] Absolute path of Python.";
186 const char kPythonPath_Help
[] =
187 "python_path: Absolute path of Python.\n"
189 " Normally used in toolchain definitions if running some command\n"
190 " requires Python. You will normally not need this when invoking scripts\n"
191 " since GN automatically finds it for you.\n";
193 const char kRootBuildDir
[] = "root_build_dir";
194 const char kRootBuildDir_HelpShort
[] =
195 "root_build_dir: [string] Directory where build commands are run.";
196 const char kRootBuildDir_Help
[] =
197 "root_build_dir: [string] Directory where build commands are run.\n"
199 " This is the root build output directory which will be the current\n"
200 " directory when executing all compilers and scripts.\n"
202 " Most often this is used with rebase_path (see \"gn help rebase_path\")\n"
203 " to convert arguments to be relative to a script's current directory.\n";
205 const char kRootGenDir
[] = "root_gen_dir";
206 const char kRootGenDir_HelpShort
[] =
207 "root_gen_dir: [string] Directory for the toolchain's generated files.";
208 const char kRootGenDir_Help
[] =
209 "root_gen_dir: Directory for the toolchain's generated files.\n"
211 " Absolute path to the root of the generated output directory tree for\n"
212 " the current toolchain. An example value might be \"//out/Debug/gen\".\n"
213 " It will not have a trailing slash.\n"
215 " This is primarily useful for setting up include paths for generated\n"
216 " files. If you are passing this to a script, you will want to pass it\n"
217 " through rebase_path() (see \"gn help rebase_path\") to convert it\n"
218 " to be relative to the build directory.\n"
220 " See also \"target_gen_dir\" which is usually a better location for\n"
221 " generated files. It will be inside the root generated dir.\n";
223 const char kRootOutDir
[] = "root_out_dir";
224 const char kRootOutDir_HelpShort
[] =
225 "root_out_dir: [string] Root directory for toolchain output files.";
226 const char kRootOutDir_Help
[] =
227 "root_out_dir: [string] Root directory for toolchain output files.\n"
229 " Absolute path to the root of the output directory tree for the current\n"
230 " toolchain. An example value might be \"//out/Debug/gen\". It will not\n"
231 " have a trailing slash.\n"
233 " This is primarily useful for setting up script calls. If you are\n"
234 " passing this to a script, you will want to pass it through\n"
235 " rebase_path() (see \"gn help rebase_path\") to convert it\n"
236 " to be relative to the build directory.\n"
238 " See also \"target_out_dir\" which is usually a better location for\n"
239 " output files. It will be inside the root output dir.\n"
243 " action(\"myscript\") {\n"
244 " # Pass the output dir to the script.\n"
245 " args = [ \"-o\", rebase_path(root_out_dir, root_build_dir) ]\n"
248 const char kTargetGenDir
[] = "target_gen_dir";
249 const char kTargetGenDir_HelpShort
[] =
250 "target_gen_dir: [string] Directory for a target's generated files.";
251 const char kTargetGenDir_Help
[] =
252 "target_gen_dir: Directory for a target's generated files.\n"
254 " Absolute path to the target's generated file directory. If your\n"
255 " current target is in \"//tools/doom_melon\" then this value might be\n"
256 " \"//out/Debug/gen/tools/doom_melon\". It will not have a trailing\n"
259 " This is primarily useful for setting up include paths for generated\n"
260 " files. If you are passing this to a script, you will want to pass it\n"
261 " through rebase_path() (see \"gn help rebase_path\") to convert it\n"
262 " to be relative to the build directory.\n"
264 " See also \"gn help root_gen_dir\".\n"
268 " action(\"myscript\") {\n"
269 " # Pass the generated output dir to the script.\n"
270 " args = [ \"-o\", rebase_path(target_gen_dir, root_build_dir) ]"
274 const char kTargetOutDir
[] = "target_out_dir";
275 const char kTargetOutDir_HelpShort
[] =
276 "target_out_dir: [string] Directory for target output files.";
277 const char kTargetOutDir_Help
[] =
278 "target_out_dir: [string] Directory for target output files.\n"
280 " Absolute path to the target's generated file directory. If your\n"
281 " current target is in \"//tools/doom_melon\" then this value might be\n"
282 " \"//out/Debug/obj/tools/doom_melon\". It will not have a trailing\n"
285 " This is primarily useful for setting up arguments for calling\n"
286 " scripts. If you are passing this to a script, you will want to pass it\n"
287 " through rebase_path() (see \"gn help rebase_path\") to convert it\n"
288 " to be relative to the build directory.\n"
290 " See also \"gn help root_out_dir\".\n"
294 " action(\"myscript\") {\n"
295 " # Pass the output dir to the script.\n"
296 " args = [ \"-o\", rebase_path(target_out_dir, root_build_dir) ]"
300 // Target variables ------------------------------------------------------------
302 #define COMMON_ORDERING_HELP \
304 "Ordering of flags and values:\n" \
306 " 1. Those set on the current target (not in a config).\n" \
307 " 2. Those set on the \"configs\" on the target in order that the\n" \
308 " configs appear in the list.\n" \
309 " 3. Those set on the \"all_dependent_configs\" on the target in order\n" \
310 " that the configs appear in the list.\n" \
311 " 4. Those set on the \"public_configs\" on the target in order that\n" \
312 " those configs appear in the list.\n" \
313 " 5. all_dependent_configs pulled from dependencies, in the order of\n" \
314 " the \"deps\" list. This is done recursively. If a config appears\n" \
315 " more than once, only the first occurance will be used.\n" \
316 " 6. public_configs pulled from dependencies, in the order of the\n" \
317 " \"deps\" list. If a dependency has " \
318 "\"forward_dependent_configs_from\",\n" \
319 " or are public dependencies, they will be applied recursively.\n"
321 const char kAllDependentConfigs
[] = "all_dependent_configs";
322 const char kAllDependentConfigs_HelpShort
[] =
323 "all_dependent_configs: [label list] Configs to be forced on dependents.";
324 const char kAllDependentConfigs_Help
[] =
325 "all_dependent_configs: Configs to be forced on dependents.\n"
327 " A list of config labels.\n"
329 " All targets depending on this one, and recursively, all targets\n"
330 " depending on those, will have the configs listed in this variable\n"
331 " added to them. These configs will also apply to the current target.\n"
333 " This addition happens in a second phase once a target and all of its\n"
334 " dependencies have been resolved. Therefore, a target will not see\n"
335 " these force-added configs in their \"configs\" variable while the\n"
336 " script is running, and then can not be removed. As a result, this\n"
337 " capability should generally only be used to add defines and include\n"
338 " directories necessary to compile a target's headers.\n"
340 " See also \"public_configs\".\n"
341 COMMON_ORDERING_HELP
;
343 const char kAllowCircularIncludesFrom
[] = "allow_circular_includes_from";
344 const char kAllowCircularIncludesFrom_HelpShort
[] =
345 "allow_circular_includes_from: [label list] Permit includes from deps.";
346 const char kAllowCircularIncludesFrom_Help
[] =
347 "allow_circular_includes_from: Permit includes from deps.\n"
349 " A list of target labels. Must be a subset of the target's \"deps\".\n"
350 " These targets will be permitted to include headers from the current\n"
351 " target despite the dependency going in the opposite direction.\n"
353 "Tedious exposition\n"
355 " Normally, for a file in target A to include a file from target B,\n"
356 " A must list B as a dependency. This invariant is enforced by the\n"
357 " \"gn check\" command (and the --check flag to \"gn gen\").\n"
359 " Sometimes, two targets might be the same unit for linking purposes\n"
360 " (two source sets or static libraries that would always be linked\n"
361 " together in a final executable or shared library). In this case,\n"
362 " you want A to be able to include B's headers, and B to include A's\n"
365 " This list, if specified, lists which of the dependencies of the\n"
366 " current target can include header files from the current target.\n"
367 " That is, if A depends on B, B can only include headers from A if it is\n"
368 " in A's allow_circular_includes_from list.\n"
372 " source_set(\"a\") {\n"
373 " deps = [ \":b\", \":c\" ]\n"
374 " allow_circular_includes_from = [ \":b\" ]\n"
378 const char kArgs
[] = "args";
379 const char kArgs_HelpShort
[] =
380 "args: [string list] Arguments passed to an action.";
381 const char kArgs_Help
[] =
382 "args: Arguments passed to an action.\n"
384 " For action and action_foreach targets, args is the list of arguments\n"
385 " to pass to the script. Typically you would use source expansion (see\n"
386 " \"gn help source_expansion\") to insert the source file names.\n"
388 " See also \"gn help action\" and \"gn help action_foreach\".\n";
390 const char kCflags
[] = "cflags";
391 const char kCflags_HelpShort
[] =
392 "cflags: [string list] Flags passed to all C compiler variants.";
393 const char kCommonCflagsHelp
[] =
394 "cflags*: Flags passed to the C compiler.\n"
396 " A list of strings.\n"
398 " \"cflags\" are passed to all invocations of the C, C++, Objective C,\n"
399 " and Objective C++ compilers.\n"
401 " To target one of these variants individually, use \"cflags_c\",\n"
402 " \"cflags_cc\", \"cflags_objc\", and \"cflags_objcc\", respectively.\n"
403 " These variant-specific versions will be appended to the \"cflags\".\n"
404 COMMON_ORDERING_HELP
;
405 const char* kCflags_Help
= kCommonCflagsHelp
;
407 const char kCflagsC
[] = "cflags_c";
408 const char kCflagsC_HelpShort
[] =
409 "cflags_c: [string list] Flags passed to the C compiler.";
410 const char* kCflagsC_Help
= kCommonCflagsHelp
;
412 const char kCflagsCC
[] = "cflags_cc";
413 const char kCflagsCC_HelpShort
[] =
414 "cflags_cc: [string list] Flags passed to the C++ compiler.";
415 const char* kCflagsCC_Help
= kCommonCflagsHelp
;
417 const char kCflagsObjC
[] = "cflags_objc";
418 const char kCflagsObjC_HelpShort
[] =
419 "cflags_objc: [string list] Flags passed to the Objective C compiler.";
420 const char* kCflagsObjC_Help
= kCommonCflagsHelp
;
422 const char kCflagsObjCC
[] = "cflags_objcc";
423 const char kCflagsObjCC_HelpShort
[] =
424 "cflags_objcc: [string list] Flags passed to the Objective C++ compiler.";
425 const char* kCflagsObjCC_Help
= kCommonCflagsHelp
;
427 const char kCheckIncludes
[] = "check_includes";
428 const char kCheckIncludes_HelpShort
[] =
429 "check_includes: [boolean] Controls whether a target's files are checked.";
430 const char kCheckIncludes_Help
[] =
431 "check_includes: [boolean] Controls whether a target's files are checked.\n"
433 " When true (the default), the \"gn check\" command (as well as\n"
434 " \"gn gen\" with the --check flag) will check this target's sources\n"
435 " and headers for proper dependencies.\n"
437 " When false, the files in this target will be skipped by default.\n"
438 " This does not affect other targets that depend on the current target,\n"
439 " it just skips checking the includes of the current target's files.\n"
443 " source_set(\"busted_includes\") {\n"
444 " # This target's includes are messed up, exclude it from checking.\n"
445 " check_includes = false\n"
449 const char kCompleteStaticLib
[] = "complete_static_lib";
450 const char kCompleteStaticLib_HelpShort
[] =
451 "complete_static_lib: [boolean] Links all deps into a static library.";
452 const char kCompleteStaticLib_Help
[] =
453 "complete_static_lib: [boolean] Links all deps into a static library.\n"
455 " A static library normally doesn't include code from dependencies, but\n"
456 " instead forwards the static libraries and source sets in its deps up\n"
457 " the dependency chain until a linkable target (an executable or shared\n"
458 " library) is reached. The final linkable target only links each static\n"
459 " library once, even if it appears more than once in its dependency\n"
462 " In some cases the static library might be the final desired output.\n"
463 " For example, you may be producing a static library for distribution to\n"
464 " third parties. In this case, the static library should include code\n"
465 " for all dependencies in one complete package. Since GN does not unpack\n"
466 " static libraries to forward their contents up the dependency chain,\n"
467 " it is an error for complete static libraries to depend on other static\n"
472 " static_library(\"foo\") {\n"
473 " complete_static_lib = true\n"
474 " deps = [ \"bar\" ]\n"
477 const char kConfigs
[] = "configs";
478 const char kConfigs_HelpShort
[] =
479 "configs: [label list] Configs applying to this target.";
480 const char kConfigs_Help
[] =
481 "configs: Configs applying to this target.\n"
483 " A list of config labels.\n"
485 " The include_dirs, defines, etc. in each config are appended in the\n"
486 " order they appear to the compile command for each file in the target.\n"
487 " They will appear after the include_dirs, defines, etc. that the target\n"
490 " The build configuration script will generally set up the default\n"
491 " configs applying to a given target type (see \"set_defaults\").\n"
492 " When a target is being defined, it can add to or remove from this\n"
497 " static_library(\"foo\") {\n"
498 " configs -= \"//build:no_rtti\" # Don't use the default RTTI config.\n"
499 " configs += \":mysettings\" # Add some of our own settings.\n"
502 const char kData
[] = "data";
503 const char kData_HelpShort
[] =
504 "data: [file list] Runtime data file dependencies.";
505 const char kData_Help
[] =
506 "data: Runtime data file dependencies.\n"
508 " Lists files required to run the given target. These are typically\n"
511 " Appearing in the \"data\" section does not imply any special handling\n"
512 " such as copying them to the output directory. This is just used for\n"
513 " declaring runtime dependencies. There currently isn't a good use for\n"
514 " these but it is envisioned that test data can be listed here for use\n"
515 " running automated tests.\n"
517 " See also \"gn help inputs\" and \"gn help data_deps\", both of\n"
518 " which actually affect the build in concrete ways.\n";
520 const char kDataDeps
[] = "data_deps";
521 const char kDataDeps_HelpShort
[] =
522 "data_deps: [label list] Non-linked dependencies.";
523 const char kDataDeps_Help
[] =
524 "data_deps: Non-linked dependencies.\n"
526 " A list of target labels.\n"
528 " Specifies dependencies of a target that are not actually linked into\n"
529 " the current target. Such dependencies will built and will be available\n"
532 " This is normally used for things like plugins or helper programs that\n"
533 " a target needs at runtime.\n"
535 " See also \"gn help deps\" and \"gn help data\".\n"
538 " executable(\"foo\") {\n"
539 " deps = [ \"//base\" ]\n"
540 " data_deps = [ \"//plugins:my_runtime_plugin\" ]\n"
543 const char kDefines
[] = "defines";
544 const char kDefines_HelpShort
[] =
545 "defines: [string list] C preprocessor defines.";
546 const char kDefines_Help
[] =
547 "defines: C preprocessor defines.\n"
549 " A list of strings\n"
551 " These strings will be passed to the C/C++ compiler as #defines. The\n"
552 " strings may or may not include an \"=\" to assign a value.\n"
556 " defines = [ \"AWESOME_FEATURE\", \"LOG_LEVEL=3\" ]\n";
558 const char kDepfile
[] = "depfile";
559 const char kDepfile_HelpShort
[] =
560 "depfile: [string] File name for input dependencies for actions.";
561 const char kDepfile_Help
[] =
562 "depfile: [string] File name for input dependencies for actions.\n"
564 " If nonempty, this string specifies that the current action or\n"
565 " action_foreach target will generate the given \".d\" file containing\n"
566 " the dependencies of the input. Empty or unset means that the script\n"
567 " doesn't generate the files.\n"
569 " The .d file should go in the target output directory. If you have more\n"
570 " than one source file that the script is being run over, you can use\n"
571 " the output file expansions described in \"gn help action_foreach\" to\n"
572 " name the .d file according to the input."
574 " The format is that of a Makefile, and all of the paths should be\n"
575 " relative to the root build directory.\n"
578 " action_foreach(\"myscript_target\") {\n"
579 " script = \"myscript.py\"\n"
580 " sources = [ ... ]\n"
582 " # Locate the depfile in the output directory named like the\n"
583 " # inputs but with a \".d\" appended.\n"
584 " depfile = \"$relative_target_output_dir/{{source_name}}.d\"\n"
586 " # Say our script uses \"-o <d file>\" to indicate the depfile.\n"
587 " args = [ \"{{source}}\", \"-o\", depfile ]\n"
590 const char kDeps
[] = "deps";
591 const char kDeps_HelpShort
[] =
592 "deps: [label list] Private linked dependencies.";
593 const char kDeps_Help
[] =
594 "deps: Private linked dependencies.\n"
596 " A list of target labels.\n"
598 " Specifies private dependencies of a target. Shared and dynamic\n"
599 " libraries will be linked into the current target. Other target types\n"
600 " that can't be linked (like actions and groups) listed in \"deps\" will\n"
601 " be treated as \"data_deps\". Likewise, if the current target isn't\n"
602 " linkable, then all deps will be treated as \"data_deps\".\n"
604 " These dependencies are private in that it does not grant dependent\n"
605 " targets the ability to include headers from the dependency, and direct\n"
606 " dependent configs are not forwarded.\n"
608 " See also \"public_deps\" and \"data_deps\".\n";
610 const char kForwardDependentConfigsFrom
[] = "forward_dependent_configs_from";
611 const char kForwardDependentConfigsFrom_HelpShort
[] =
612 "forward_dependent_configs_from: [label list] Forward dependent's configs.";
613 const char kForwardDependentConfigsFrom_Help
[] =
614 "forward_dependent_configs_from\n"
616 " A list of target labels.\n"
618 " Exposes the public_configs from a private dependent target as\n"
619 " public_configs of the current one. Each label in this list\n"
620 " must also be in the deps.\n"
622 " Generally you should use public_deps instead of this variable to\n"
623 " express the concept of exposing a dependency as part of a target's\n"
624 " public API. We're considering removing this variable.\n"
628 " Sometimes you depend on a child library that exports some necessary\n"
629 " configuration via public_configs. If your target in turn exposes the\n"
630 " child library's headers in its public headers, it might mean that\n"
631 " targets that depend on you won't work: they'll be seeing the child\n"
632 " library's code but not the necessary configuration. This list\n"
633 " specifies which of your deps' direct dependent configs to expose as\n"
638 " If we use a given library \"a\" from our public headers:\n"
640 " deps = [ \":a\", \":b\", ... ]\n"
641 " forward_dependent_configs_from = [ \":a\" ]\n"
643 " This example makes a \"transparent\" target that forwards a dependency\n"
646 " group(\"frob\") {\n"
647 " if (use_system_frob) {\n"
648 " deps = \":system_frob\"\n"
650 " deps = \"//third_party/fallback_frob\"\n"
652 " forward_dependent_configs_from = deps\n"
655 const char kIncludeDirs
[] = "include_dirs";
656 const char kIncludeDirs_HelpShort
[] =
657 "include_dirs: [directory list] Additional include directories.";
658 const char kIncludeDirs_Help
[] =
659 "include_dirs: Additional include directories.\n"
661 " A list of source directories.\n"
663 " The directories in this list will be added to the include path for\n"
664 " the files in the affected target.\n"
668 " include_dirs = [ \"src/include\", \"//third_party/foo\" ]\n";
670 const char kInputs
[] = "inputs";
671 const char kInputs_HelpShort
[] =
672 "inputs: [file list] Additional compile-time dependencies.";
673 const char kInputs_Help
[] =
674 "inputs: Additional compile-time dependencies.\n"
676 " Inputs are compile-time dependencies of the current target. This means\n"
677 " that all inputs must be available before compiling any of the sources\n"
678 " or executing any actions.\n"
680 " Inputs are typically only used for action and action_foreach targets.\n"
682 "Inputs for actions\n"
684 " For action and action_foreach targets, inputs should be the inputs to\n"
685 " script that don't vary. These should be all .py files that the script\n"
686 " uses via imports (the main script itself will be an implcit dependency\n"
687 " of the action so need not be listed).\n"
689 " For action targets, inputs should be the entire set of inputs the\n"
690 " script needs. For action_foreach targets, inputs should be the set of\n"
691 " dependencies that don't change. These will be applied to each script\n"
692 " invocation over the sources.\n"
694 " Note that another way to declare input dependencies from an action\n"
695 " is to have the action write a depfile (see \"gn help depfile\"). This\n"
696 " allows the script to dynamically write input dependencies, that might\n"
697 " not be known until actually executing the script. This is more\n"
698 " efficient than doing processing while running GN to determine the\n"
699 " inputs, and is easier to keep in-sync than hardcoding the list.\n"
701 "Inputs for binary targets\n"
703 " Any input dependencies will be resolved before compiling any sources.\n"
704 " Normally, all actions that a target depends on will be run before any\n"
705 " files in a target are compiled. So if you depend on generated headers,\n"
706 " you do not typically need to list them in the inputs section.\n"
710 " action(\"myscript\") {\n"
711 " script = \"domything.py\"\n"
712 " inputs = [ \"input.data\" ]\n"
715 const char kLdflags
[] = "ldflags";
716 const char kLdflags_HelpShort
[] =
717 "ldflags: [string list] Flags passed to the linker.";
718 const char kLdflags_Help
[] =
719 "ldflags: Flags passed to the linker.\n"
721 " A list of strings.\n"
723 " These flags are passed on the command-line to the linker and generally\n"
724 " specify various linking options. Most targets will not need these and\n"
725 " will use \"libs\" and \"lib_dirs\" instead.\n"
727 " ldflags are NOT pushed to dependents, so applying ldflags to source\n"
728 " sets or static libraries will be a no-op. If you want to apply ldflags\n"
729 " to dependent targets, put them in a config and set it in the\n"
730 " all_dependent_configs or public_configs.\n";
732 #define COMMON_LIB_INHERITANCE_HELP \
734 " libs and lib_dirs work differently than other flags in two respects.\n" \
735 " First, then are inherited across static library boundaries until a\n" \
736 " shared library or executable target is reached. Second, they are\n" \
737 " uniquified so each one is only passed once (the first instance of it\n" \
738 " will be the one used).\n"
740 const char kLibDirs
[] = "lib_dirs";
741 const char kLibDirs_HelpShort
[] =
742 "lib_dirs: [directory list] Additional library directories.";
743 const char kLibDirs_Help
[] =
744 "lib_dirs: Additional library directories.\n"
746 " A list of directories.\n"
748 " Specifies additional directories passed to the linker for searching\n"
749 " for the required libraries. If an item is not an absolute path, it\n"
750 " will be treated as being relative to the current build file.\n"
751 COMMON_LIB_INHERITANCE_HELP
755 " lib_dirs = [ \"/usr/lib/foo\", \"lib/doom_melon\" ]\n";
757 const char kLibs
[] = "libs";
758 const char kLibs_HelpShort
[] =
759 "libs: [string list] Additional libraries to link.";
760 const char kLibs_Help
[] =
761 "libs: Additional libraries to link.\n"
763 " A list of strings.\n"
765 " These files will be passed to the linker, which will generally search\n"
766 " the library include path. Unlike a normal list of files, they will be\n"
767 " passed to the linker unmodified rather than being treated as file\n"
768 " names relative to the current build file. Generally you would set\n"
769 " the \"lib_dirs\" so your library is found. If you need to specify\n"
770 " a path, you can use \"rebase_path\" to convert a path to be relative\n"
771 " to the build directory.\n"
773 " When constructing the linker command, the \"lib_prefix\" attribute of\n"
774 " the linker tool in the current toolchain will be prepended to each\n"
775 " library. So your BUILD file should not specify the switch prefix\n"
776 " (like \"-l\"). On Mac, libraries ending in \".framework\" will be\n"
777 " special-cased: the switch \"-framework\" will be prepended instead of\n"
778 " the lib_prefix, and the \".framework\" suffix will be trimmed.\n"
779 COMMON_LIB_INHERITANCE_HELP
784 " libs = [ \"ctl3d.lib\" ]\n"
786 " libs = [ \"ld\" ]\n";
788 const char kOutputExtension
[] = "output_extension";
789 const char kOutputExtension_HelpShort
[] =
790 "output_extension: [string] Value to use for the output's file extension.";
791 const char kOutputExtension_Help
[] =
792 "output_extension: Value to use for the output's file extension.\n"
794 " Normally the file extension for a target is based on the target\n"
795 " type and the operating system, but in rare cases you will need to\n"
796 " override the name (for example to use \"libfreetype.so.6\" instead\n"
797 " of libfreetype.so on Linux).";
799 const char kOutputName
[] = "output_name";
800 const char kOutputName_HelpShort
[] =
801 "output_name: [string] Name for the output file other than the default.";
802 const char kOutputName_Help
[] =
803 "output_name: Define a name for the output file other than the default.\n"
805 " Normally the output name of a target will be based on the target name,\n"
806 " so the target \"//foo/bar:bar_unittests\" will generate an output\n"
807 " file such as \"bar_unittests.exe\" (using Windows as an example).\n"
809 " Sometimes you will want an alternate name to avoid collisions or\n"
810 " if the internal name isn't appropriate for public distribution.\n"
812 " The output name should have no extension or prefixes, these will be\n"
813 " added using the default system rules. For example, on Linux an output\n"
814 " name of \"foo\" will produce a shared library \"libfoo.so\".\n"
816 " This variable is valid for all binary output target types.\n"
819 " static_library(\"doom_melon\") {\n"
820 " output_name = \"fluffy_bunny\"\n"
823 const char kOutputs
[] = "outputs";
824 const char kOutputs_HelpShort
[] =
825 "outputs: [file list] Output files for actions and copy targets.";
826 const char kOutputs_Help
[] =
827 "outputs: Output files for actions and copy targets.\n"
829 " Outputs is valid for \"copy\", \"action\", and \"action_foreach\"\n"
830 " target types and indicates the resulting files. The values may contain\n"
831 " source expansions to generate the output names from the sources (see\n"
832 " \"gn help source_expansion\").\n"
834 " For copy targets, the outputs is the destination for the copied\n"
835 " file(s). For actions, the outputs should be the list of files\n"
836 " generated by the script.\n";
838 const char kPublic
[] = "public";
839 const char kPublic_HelpShort
[] =
840 "public: [file list] Declare public header files for a target.";
841 const char kPublic_Help
[] =
842 "public: Declare public header files for a target.\n"
844 " A list of files that other targets can include. These permissions are\n"
845 " checked via the \"check\" command (see \"gn help check\").\n"
847 " If no public files are declared, other targets (assuming they have\n"
848 " visibility to depend on this target can include any file in the\n"
849 " sources list. If this variable is defined on a target, dependent\n"
850 " targets may only include files on this whitelist.\n"
852 " Header file permissions are also subject to visibility. A target\n"
853 " must be visible to another target to include any files from it at all\n"
854 " and the public headers indicate which subset of those files are\n"
855 " permitted. See \"gn help visibility\" for more.\n"
857 " Public files are inherited through the dependency tree. So if there is\n"
858 " a dependency A -> B -> C, then A can include C's public headers.\n"
859 " However, the same is NOT true of visibility, so unless A is in C's\n"
860 " visibility list, the include will be rejected.\n"
862 " GN only knows about files declared in the \"sources\" and \"public\"\n"
863 " sections of targets. If a file is included that is not known to the\n"
864 " build, it will be allowed.\n"
867 " These exact files are public:\n"
868 " public = [ \"foo.h\", \"bar.h\" ]\n"
870 " No files are public (no targets may include headers from this one):\n"
873 const char kPublicConfigs
[] = "public_configs";
874 const char kPublicConfigs_HelpShort
[] =
875 "public_configs: [label list] Configs applied to dependents.";
876 const char kPublicConfigs_Help
[] =
877 "public_configs: Configs to be applied on dependents.\n"
879 " A list of config labels.\n"
881 " Targets directly depending on this one will have the configs listed in\n"
882 " this variable added to them. These configs will also apply to the\n"
885 " This addition happens in a second phase once a target and all of its\n"
886 " dependencies have been resolved. Therefore, a target will not see\n"
887 " these force-added configs in their \"configs\" variable while the\n"
888 " script is running, and then can not be removed. As a result, this\n"
889 " capability should generally only be used to add defines and include\n"
890 " directories necessary to compile a target's headers.\n"
892 " See also \"all_dependent_configs\".\n"
893 COMMON_ORDERING_HELP
;
895 const char kPublicDeps
[] = "public_deps";
896 const char kPublicDeps_HelpShort
[] =
897 "public_deps: [label list] Declare public dependencies.";
898 const char kPublicDeps_Help
[] =
899 "public_deps: Declare public dependencies.\n"
901 " Public dependencies are like private dependencies (\"deps\") but\n"
902 " additionally express that the current target exposes the listed deps\n"
903 " as part of its public API.\n"
905 " This has two ramifications:\n"
907 " - public_configs that are part of the dependency are forwarded\n"
908 " to direct dependents (this is the same as using\n"
909 " forward_dependent_configs_from).\n"
911 " - public headers in the dependency are usable by dependents\n"
912 " (includes do not require a direct dependency or visibility).\n"
916 " Say you have three targets: A -> B -> C. C's visibility may allow\n"
917 " B to depend on it but not A. Normally, this would prevent A from\n"
918 " including any headers from C, and C's public_configs would apply\n"
921 " If B lists C in its public_deps instead of regular deps, A will now\n"
922 " inherit C's public_configs and the ability to include C's public\n"
925 " Generally if you are writing a target B and you include C's headers\n"
926 " as part of B's public headers, or targets depending on B should\n"
927 " consider B and C to be part of a unit, you should use public_deps\n"
928 " instead of deps.\n"
932 " # This target can include files from \"c\" but not from\n"
933 " # \"super_secret_implementation_details\".\n"
934 " executable(\"a\") {\n"
935 " deps = [ \":b\" ]\n"
938 " shared_library(\"b\") {\n"
939 " deps = [ \":super_secret_implementation_details\" ]\n"
940 " public_deps = [ \":c\" ]\n"
943 const char kScript
[] = "script";
944 const char kScript_HelpShort
[] =
945 "script: [file name] Script file for actions.";
946 const char kScript_Help
[] =
947 "script: Script file for actions.\n"
949 " An absolute or buildfile-relative file name of a Python script to run\n"
950 " for a action and action_foreach targets (see \"gn help action\" and\n"
951 " \"gn help action_foreach\").\n";
953 const char kSources
[] = "sources";
954 const char kSources_HelpShort
[] =
955 "sources: [file list] Source files for a target.";
956 const char kSources_Help
[] =
957 "sources: Source files for a target\n"
959 " A list of files relative to the current buildfile.\n";
961 const char kTestonly
[] = "testonly";
962 const char kTestonly_HelpShort
[] =
963 "testonly: [boolean] Declares a target must only be used for testing.";
964 const char kTestonly_Help
[] =
965 "testonly: Declares a target must only be used for testing.\n"
967 " Boolean. Defaults to false.\n"
969 " When a target is marked \"testonly = true\", it must only be depended\n"
970 " on by other test-only targets. Otherwise, GN will issue an error\n"
971 " that the depenedency is not allowed.\n"
973 " This feature is intended to prevent accidentally shipping test code\n"
974 " in a final product.\n"
978 " source_set(\"test_support\") {\n"
983 const char kVisibility
[] = "visibility";
984 const char kVisibility_HelpShort
[] =
985 "visibility: [label list] A list of labels that can depend on a target.";
986 const char kVisibility_Help
[] =
987 "visibility: A list of labels that can depend on a target.\n"
989 " A list of labels and label patterns that define which targets can\n"
990 " depend on the current one. These permissions are checked via the\n"
991 " \"check\" command (see \"gn help check\").\n"
993 " If visibility is not defined, it defaults to public (\"*\").\n"
995 " If visibility is defined, only the targets with labels that match it\n"
996 " can depend on the current target. The empty list means no targets\n"
997 " can depend on the current target.\n"
999 " Tip: Often you will want the same visibility for all targets in a\n"
1000 " BUILD file. In this case you can just put the definition at the top,\n"
1001 " outside of any target, and the targets will inherit that scope and see\n"
1002 " the definition.\n"
1006 " See \"gn help label_pattern\" for more details on what types of\n"
1007 " patterns are supported. If a toolchain is specified, only targets\n"
1008 " in that toolchain will be matched. If a toolchain is not specified on\n"
1009 " a pattern, targets in all toolchains will be matched.\n"
1013 " Only targets in the current buildfile (\"private\"):\n"
1014 " visibility = [ \":*\" ]\n"
1016 " No targets (used for targets that should be leaf nodes):\n"
1017 " visibility = []\n"
1019 " Any target (\"public\", the default):\n"
1020 " visibility = [ \"*\" ]\n"
1022 " All targets in the current directory and any subdirectory:\n"
1023 " visibility = [ \"./*\" ]\n"
1025 " Any target in \"//bar/BUILD.gn\":\n"
1026 " visibility = [ \"//bar:*\" ]\n"
1028 " Any target in \"//bar/\" or any subdirectory thereof:\n"
1029 " visibility = [ \"//bar/*\" ]\n"
1031 " Just these specific targets:\n"
1032 " visibility = [ \":mything\", \"//foo:something_else\" ]\n"
1034 " Any target in the current directory and any subdirectory thereof, plus\n"
1035 " any targets in \"//bar/\" and any subdirectory thereof.\n"
1036 " visibility = [ \"./*\", \"//bar/*\" ]\n";
1038 // -----------------------------------------------------------------------------
1040 VariableInfo::VariableInfo()
1045 VariableInfo::VariableInfo(const char* in_help_short
, const char* in_help
)
1046 : help_short(in_help_short
),
1050 #define INSERT_VARIABLE(var) \
1051 info_map[k##var] = VariableInfo(k##var##_HelpShort, k##var##_Help);
1053 const VariableInfoMap
& GetBuiltinVariables() {
1054 static VariableInfoMap info_map
;
1055 if (info_map
.empty()) {
1056 INSERT_VARIABLE(CurrentCpu
)
1057 INSERT_VARIABLE(CurrentOs
)
1058 INSERT_VARIABLE(CurrentToolchain
)
1059 INSERT_VARIABLE(DefaultToolchain
)
1060 INSERT_VARIABLE(HostCpu
)
1061 INSERT_VARIABLE(HostOs
)
1062 INSERT_VARIABLE(PythonPath
)
1063 INSERT_VARIABLE(RootBuildDir
)
1064 INSERT_VARIABLE(RootGenDir
)
1065 INSERT_VARIABLE(RootOutDir
)
1066 INSERT_VARIABLE(TargetCpu
)
1067 INSERT_VARIABLE(TargetOs
)
1068 INSERT_VARIABLE(TargetGenDir
)
1069 INSERT_VARIABLE(TargetOutDir
)
1074 const VariableInfoMap
& GetTargetVariables() {
1075 static VariableInfoMap info_map
;
1076 if (info_map
.empty()) {
1077 INSERT_VARIABLE(AllDependentConfigs
)
1078 INSERT_VARIABLE(AllowCircularIncludesFrom
)
1079 INSERT_VARIABLE(Args
)
1080 INSERT_VARIABLE(Cflags
)
1081 INSERT_VARIABLE(CflagsC
)
1082 INSERT_VARIABLE(CflagsCC
)
1083 INSERT_VARIABLE(CflagsObjC
)
1084 INSERT_VARIABLE(CflagsObjCC
)
1085 INSERT_VARIABLE(CheckIncludes
)
1086 INSERT_VARIABLE(CompleteStaticLib
)
1087 INSERT_VARIABLE(Configs
)
1088 INSERT_VARIABLE(Data
)
1089 INSERT_VARIABLE(DataDeps
)
1090 INSERT_VARIABLE(Defines
)
1091 INSERT_VARIABLE(Depfile
)
1092 INSERT_VARIABLE(Deps
)
1093 INSERT_VARIABLE(ForwardDependentConfigsFrom
)
1094 INSERT_VARIABLE(IncludeDirs
)
1095 INSERT_VARIABLE(Inputs
)
1096 INSERT_VARIABLE(Ldflags
)
1097 INSERT_VARIABLE(Libs
)
1098 INSERT_VARIABLE(LibDirs
)
1099 INSERT_VARIABLE(OutputExtension
)
1100 INSERT_VARIABLE(OutputName
)
1101 INSERT_VARIABLE(Outputs
)
1102 INSERT_VARIABLE(Public
)
1103 INSERT_VARIABLE(PublicConfigs
)
1104 INSERT_VARIABLE(PublicDeps
)
1105 INSERT_VARIABLE(Script
)
1106 INSERT_VARIABLE(Sources
)
1107 INSERT_VARIABLE(Testonly
)
1108 INSERT_VARIABLE(Visibility
)
1113 #undef INSERT_VARIABLE
1115 } // namespace variables