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 kCpuArch
[] = "cpu_arch";
12 const char kCpuArch_HelpShort
[] =
13 "cpu_arch: [string] Current processor architecture.";
14 const char kCpuArch_Help
[] =
15 "cpu_arch: Current processor architecture.\n"
17 " The initial value is based on the current architecture of the host\n"
18 " system. However, the build configuration can set this to any value.\n"
20 " This value is not used internally by GN for any purpose, so you can\n"
21 " set it to whatever value is relevant to your build.\n"
23 "Possible initial values set by GN:\n"
29 const char kCurrentToolchain
[] = "current_toolchain";
30 const char kCurrentToolchain_HelpShort
[] =
31 "current_toolchain: [string] Label of the current toolchain.";
32 const char kCurrentToolchain_Help
[] =
33 "current_toolchain: Label of the current toolchain.\n"
35 " A fully-qualified label representing the current toolchain. You can\n"
36 " use this to make toolchain-related decisions in the build. See also\n"
37 " \"default_toolchain\".\n"
41 " if (current_toolchain == \"//build:64_bit_toolchain\") {\n"
42 " executable(\"output_thats_64_bit_only\") {\n"
45 const char kBuildCpuArch
[] = "build_cpu_arch";
46 const char kBuildCpuArch_HelpShort
[] =
47 "build_cpu_arch: [string] The default value for the \"cpu_arch\" "
49 const char kBuildCpuArch_Help
[] =
50 "build_cpu_arch: The default value for the \"cpu_arch\" variable.\n"
52 " This value has the same definition as \"cpu_arch\" (see\n"
53 " \"gn help cpu_arch\") but should be treated as read-only. This is so\n"
54 " the build can override the \"cpu_arch\" variable for doing\n"
55 " cross-compiles, but can still access the host build system's CPU\n"
58 const char kBuildOs
[] = "build_os";
59 const char kBuildOs_HelpShort
[] =
60 "build_os: [string] The default value for the \"os\" variable.";
61 const char kBuildOs_Help
[] =
62 "build_os: [string] The default value for the \"os\" variable.\n"
64 " This value has the same definition as \"os\" (see \"gn help os\") but\n"
65 " should be treated as read-only. This is so the build can override\n"
66 " the \"os\" variable for doing cross-compiles, but can still access\n"
67 " the host build system's operating system type.\n";
69 const char kDefaultToolchain
[] = "default_toolchain";
70 const char kDefaultToolchain_HelpShort
[] =
71 "default_toolchain: [string] Label of the default toolchain.";
72 const char kDefaultToolchain_Help
[] =
73 "default_toolchain: [string] Label of the default toolchain.\n"
75 " A fully-qualified label representing the default toolchain, which may\n"
76 " not necessarily be the current one (see \"current_toolchain\").\n";
78 const char kOs
[] = "os";
79 const char kOs_HelpShort
[] =
80 "os: [string] Indicates the operating system of the current build.";
81 const char kOs_Help
[] =
82 "os: Indicates the operating system of the current build."
84 " This value is set by default based on the current host operating\n"
85 " system. The build configuration can override the value to anything\n"
86 " it wants, or it can be set via the build arguments on the command\n"
89 " If you want to know the default value without any overrides, you can\n"
90 " use \"default_os\" (see \"gn help default_os\").\n"
92 " Note that this returns the most specific value. So even though\n"
93 " Android and ChromeOS are both Linux, the more specific value will\n"
96 "Some possible values:\n"
105 const char kPythonPath
[] = "python_path";
106 const char kPythonPath_HelpShort
[] =
107 "python_path: [string] Absolute path of Python.";
108 const char kPythonPath_Help
[] =
109 "python_path: Absolute path of Python.\n"
111 " Normally used in toolchain definitions if running some command\n"
112 " requires Python. You will normally not need this when invoking scripts\n"
113 " since GN automatically finds it for you.\n";
115 const char kRootBuildDir
[] = "root_build_dir";
116 const char kRootBuildDir_HelpShort
[] =
117 "root_build_dir: [string] Directory where build commands are run.";
118 const char kRootBuildDir_Help
[] =
119 "root_build_dir: [string] Directory where build commands are run.\n"
121 " This is the root build output directory which will be the current\n"
122 " directory when executing all compilers and scripts.\n"
124 " Most often this is used with rebase_path (see \"gn help rebase_path\")\n"
125 " to convert arguments to be relative to a script's current directory.\n";
127 const char kRootGenDir
[] = "root_gen_dir";
128 const char kRootGenDir_HelpShort
[] =
129 "root_gen_dir: [string] Directory for the toolchain's generated files.";
130 const char kRootGenDir_Help
[] =
131 "root_gen_dir: Directory for the toolchain's generated files.\n"
133 " Absolute path to the root of the generated output directory tree for\n"
134 " the current toolchain. An example value might be \"//out/Debug/gen\".\n"
135 " It will not have a trailing slash.\n"
137 " This is primarily useful for setting up include paths for generated\n"
138 " files. If you are passing this to a script, you will want to pass it\n"
139 " through rebase_path() (see \"gn help rebase_path\") to convert it\n"
140 " to be relative to the build directory.\n"
142 " See also \"target_gen_dir\" which is usually a better location for\n"
143 " generated files. It will be inside the root generated dir.\n";
145 const char kRootOutDir
[] = "root_out_dir";
146 const char kRootOutDir_HelpShort
[] =
147 "root_out_dir: [string] Root directory for toolchain output files.";
148 const char kRootOutDir_Help
[] =
149 "root_out_dir: [string] Root directory for toolchain output files.\n"
151 " Absolute path to the root of the output directory tree for the current\n"
152 " toolchain. An example value might be \"//out/Debug/gen\". It will not\n"
153 " have a trailing slash.\n"
155 " This is primarily useful for setting up script calls. If you are\n"
156 " passing this to a script, you will want to pass it through\n"
157 " rebase_path() (see \"gn help rebase_path\") to convert it\n"
158 " to be relative to the build directory.\n"
160 " See also \"target_out_dir\" which is usually a better location for\n"
161 " output files. It will be inside the root output dir.\n"
165 " action(\"myscript\") {\n"
166 " # Pass the output dir to the script.\n"
167 " args = [ \"-o\", rebase_path(root_out_dir, root_build_dir) ]\n"
170 const char kTargetGenDir
[] = "target_gen_dir";
171 const char kTargetGenDir_HelpShort
[] =
172 "target_gen_dir: [string] Directory for a target's generated files.";
173 const char kTargetGenDir_Help
[] =
174 "target_gen_dir: Directory for a target's generated files.\n"
176 " Absolute path to the target's generated file directory. If your\n"
177 " current target is in \"//tools/doom_melon\" then this value might be\n"
178 " \"//out/Debug/gen/tools/doom_melon\". It will not have a trailing\n"
181 " This is primarily useful for setting up include paths for generated\n"
182 " files. If you are passing this to a script, you will want to pass it\n"
183 " through rebase_path() (see \"gn help rebase_path\") to convert it\n"
184 " to be relative to the build directory.\n"
186 " See also \"gn help root_gen_dir\".\n"
190 " action(\"myscript\") {\n"
191 " # Pass the generated output dir to the script.\n"
192 " args = [ \"-o\", rebase_path(target_gen_dir, root_build_dir) ]"
196 const char kTargetOutDir
[] = "target_out_dir";
197 const char kTargetOutDir_HelpShort
[] =
198 "target_out_dir: [string] Directory for target output files.";
199 const char kTargetOutDir_Help
[] =
200 "target_out_dir: [string] Directory for target output files.\n"
202 " Absolute path to the target's generated file directory. If your\n"
203 " current target is in \"//tools/doom_melon\" then this value might be\n"
204 " \"//out/Debug/obj/tools/doom_melon\". It will not have a trailing\n"
207 " This is primarily useful for setting up arguments for calling\n"
208 " scripts. If you are passing this to a script, you will want to pass it\n"
209 " through rebase_path() (see \"gn help rebase_path\") to convert it\n"
210 " to be relative to the build directory.\n"
212 " See also \"gn help root_out_dir\".\n"
216 " action(\"myscript\") {\n"
217 " # Pass the output dir to the script.\n"
218 " args = [ \"-o\", rebase_path(target_out_dir, root_build_dir) ]"
222 // Target variables ------------------------------------------------------------
224 #define COMMON_ORDERING_HELP \
226 "Ordering of flags and values:\n" \
228 " 1. Those set on the current target (not in a config).\n" \
229 " 2. Those set on the \"configs\" on the target in order that the\n" \
230 " configs appear in the list.\n" \
231 " 3. Those set on the \"all_dependent_configs\" on the target in order\n" \
232 " that the configs appear in the list.\n" \
233 " 4. Those set on the \"public_configs\" on the target in order that\n" \
234 " those configs appear in the list.\n" \
235 " 5. all_dependent_configs pulled from dependencies, in the order of\n" \
236 " the \"deps\" list. This is done recursively. If a config appears\n" \
237 " more than once, only the first occurance will be used.\n" \
238 " 6. public_configs pulled from dependencies, in the order of the\n" \
239 " \"deps\" list. If a dependency has " \
240 "\"forward_dependent_configs_from\",\n" \
241 " or are public dependencies, they will be applied recursively.\n"
243 const char kAllDependentConfigs
[] = "all_dependent_configs";
244 const char kAllDependentConfigs_HelpShort
[] =
245 "all_dependent_configs: [label list] Configs to be forced on dependents.";
246 const char kAllDependentConfigs_Help
[] =
247 "all_dependent_configs: Configs to be forced on dependents.\n"
249 " A list of config labels.\n"
251 " All targets depending on this one, and recursively, all targets\n"
252 " depending on those, will have the configs listed in this variable\n"
253 " added to them. These configs will also apply to the current target.\n"
255 " This addition happens in a second phase once a target and all of its\n"
256 " dependencies have been resolved. Therefore, a target will not see\n"
257 " these force-added configs in their \"configs\" variable while the\n"
258 " script is running, and then can not be removed. As a result, this\n"
259 " capability should generally only be used to add defines and include\n"
260 " directories necessary to compile a target's headers.\n"
262 " See also \"public_configs\".\n"
263 COMMON_ORDERING_HELP
;
265 const char kAllowCircularIncludesFrom
[] = "allow_circular_includes_from";
266 const char kAllowCircularIncludesFrom_HelpShort
[] =
267 "allow_circular_includes_from: [label list] Permit includes from deps.";
268 const char kAllowCircularIncludesFrom_Help
[] =
269 "allow_circular_includes_from: Permit includes from deps.\n"
271 " A list of target labels. Must be a subset of the target's \"deps\".\n"
272 " These targets will be permitted to include headers from the current\n"
273 " target despite the dependency going in the opposite direction.\n"
275 "Tedious exposition\n"
277 " Normally, for a file in target A to include a file from target B,\n"
278 " A must list B as a dependency. This invariant is enforced by the\n"
279 " \"gn check\" command (and the --check flag to \"gn gen\").\n"
281 " Sometimes, two targets might be the same unit for linking purposes\n"
282 " (two source sets or static libraries that would always be linked\n"
283 " together in a final executable or shared library). In this case,\n"
284 " you want A to be able to include B's headers, and B to include A's\n"
287 " This list, if specified, lists which of the dependencies of the\n"
288 " current target can include header files from the current target.\n"
289 " That is, if A depends on B, B can only include headers from A if it is\n"
290 " in A's allow_circular_includes_from list.\n"
294 " source_set(\"a\") {\n"
295 " deps = [ \":b\", \":c\" ]\n"
296 " allow_circular_includes_from = [ \":b\" ]\n"
300 const char kArgs
[] = "args";
301 const char kArgs_HelpShort
[] =
302 "args: [string list] Arguments passed to an action.";
303 const char kArgs_Help
[] =
304 "args: Arguments passed to an action.\n"
306 " For action and action_foreach targets, args is the list of arguments\n"
307 " to pass to the script. Typically you would use source expansion (see\n"
308 " \"gn help source_expansion\") to insert the source file names.\n"
310 " See also \"gn help action\" and \"gn help action_foreach\".\n";
312 const char kCflags
[] = "cflags";
313 const char kCflags_HelpShort
[] =
314 "cflags: [string list] Flags passed to all C compiler variants.";
315 const char kCommonCflagsHelp
[] =
316 "cflags*: Flags passed to the C compiler.\n"
318 " A list of strings.\n"
320 " \"cflags\" are passed to all invocations of the C, C++, Objective C,\n"
321 " and Objective C++ compilers.\n"
323 " To target one of these variants individually, use \"cflags_c\",\n"
324 " \"cflags_cc\", \"cflags_objc\", and \"cflags_objcc\", respectively.\n"
325 " These variant-specific versions will be appended to the \"cflags\".\n"
326 COMMON_ORDERING_HELP
;
327 const char* kCflags_Help
= kCommonCflagsHelp
;
329 const char kCflagsC
[] = "cflags_c";
330 const char kCflagsC_HelpShort
[] =
331 "cflags_c: [string list] Flags passed to the C compiler.";
332 const char* kCflagsC_Help
= kCommonCflagsHelp
;
334 const char kCflagsCC
[] = "cflags_cc";
335 const char kCflagsCC_HelpShort
[] =
336 "cflags_cc: [string list] Flags passed to the C++ compiler.";
337 const char* kCflagsCC_Help
= kCommonCflagsHelp
;
339 const char kCflagsObjC
[] = "cflags_objc";
340 const char kCflagsObjC_HelpShort
[] =
341 "cflags_objc: [string list] Flags passed to the Objective C compiler.";
342 const char* kCflagsObjC_Help
= kCommonCflagsHelp
;
344 const char kCflagsObjCC
[] = "cflags_objcc";
345 const char kCflagsObjCC_HelpShort
[] =
346 "cflags_objcc: [string list] Flags passed to the Objective C++ compiler.";
347 const char* kCflagsObjCC_Help
= kCommonCflagsHelp
;
349 const char kCheckIncludes
[] = "check_includes";
350 const char kCheckIncludes_HelpShort
[] =
351 "check_includes: [boolean] Controls whether a target's files are checked.";
352 const char kCheckIncludes_Help
[] =
353 "check_includes: [boolean] Controls whether a target's files are checked.\n"
355 " When true (the default), the \"gn check\" command (as well as\n"
356 " \"gn gen\" with the --check flag) will check this target's sources\n"
357 " and headers for proper dependencies.\n"
359 " When false, the files in this target will be skipped by default.\n"
360 " This does not affect other targets that depend on the current target,\n"
361 " it just skips checking the includes of the current target's files.\n"
365 " source_set(\"busted_includes\") {\n"
366 " # This target's includes are messed up, exclude it from checking.\n"
367 " check_includes = false\n"
371 const char kCompleteStaticLib
[] = "complete_static_lib";
372 const char kCompleteStaticLib_HelpShort
[] =
373 "complete_static_lib: [boolean] Links all deps into a static library.";
374 const char kCompleteStaticLib_Help
[] =
375 "complete_static_lib: [boolean] Links all deps into a static library.\n"
377 " A static library normally doesn't include code from dependencies, but\n"
378 " instead forwards the static libraries and source sets in its deps up\n"
379 " the dependency chain until a linkable target (an executable or shared\n"
380 " library) is reached. The final linkable target only links each static\n"
381 " library once, even if it appears more than once in its dependency\n"
384 " In some cases the static library might be the final desired output.\n"
385 " For example, you may be producing a static library for distribution to\n"
386 " third parties. In this case, the static library should include code\n"
387 " for all dependencies in one complete package. Since GN does not unpack\n"
388 " static libraries to forward their contents up the dependency chain,\n"
389 " it is an error for complete static libraries to depend on other static\n"
394 " static_library(\"foo\") {\n"
395 " complete_static_lib = true\n"
396 " deps = [ \"bar\" ]\n"
399 const char kConfigs
[] = "configs";
400 const char kConfigs_HelpShort
[] =
401 "configs: [label list] Configs applying to this target.";
402 const char kConfigs_Help
[] =
403 "configs: Configs applying to this target.\n"
405 " A list of config labels.\n"
407 " The include_dirs, defines, etc. in each config are appended in the\n"
408 " order they appear to the compile command for each file in the target.\n"
409 " They will appear after the include_dirs, defines, etc. that the target\n"
412 " The build configuration script will generally set up the default\n"
413 " configs applying to a given target type (see \"set_defaults\").\n"
414 " When a target is being defined, it can add to or remove from this\n"
419 " static_library(\"foo\") {\n"
420 " configs -= \"//build:no_rtti\" # Don't use the default RTTI config.\n"
421 " configs += \":mysettings\" # Add some of our own settings.\n"
424 const char kData
[] = "data";
425 const char kData_HelpShort
[] =
426 "data: [file list] Runtime data file dependencies.";
427 const char kData_Help
[] =
428 "data: Runtime data file dependencies.\n"
430 " Lists files required to run the given target. These are typically\n"
433 " Appearing in the \"data\" section does not imply any special handling\n"
434 " such as copying them to the output directory. This is just used for\n"
435 " declaring runtime dependencies. There currently isn't a good use for\n"
436 " these but it is envisioned that test data can be listed here for use\n"
437 " running automated tests.\n"
439 " See also \"gn help inputs\" and \"gn help data_deps\", both of\n"
440 " which actually affect the build in concrete ways.\n";
442 const char kDataDeps
[] = "data_deps";
443 const char kDataDeps_HelpShort
[] =
444 "data_deps: [label list] Non-linked dependencies.";
445 const char kDataDeps_Help
[] =
446 "data_deps: Non-linked dependencies.\n"
448 " A list of target labels.\n"
450 " Specifies dependencies of a target that are not actually linked into\n"
451 " the current target. Such dependencies will built and will be available\n"
454 " This is normally used for things like plugins or helper programs that\n"
455 " a target needs at runtime.\n"
457 " See also \"gn help deps\" and \"gn help data\".\n"
460 " executable(\"foo\") {\n"
461 " deps = [ \"//base\" ]\n"
462 " data_deps = [ \"//plugins:my_runtime_plugin\" ]\n"
465 const char kDefines
[] = "defines";
466 const char kDefines_HelpShort
[] =
467 "defines: [string list] C preprocessor defines.";
468 const char kDefines_Help
[] =
469 "defines: C preprocessor defines.\n"
471 " A list of strings\n"
473 " These strings will be passed to the C/C++ compiler as #defines. The\n"
474 " strings may or may not include an \"=\" to assign a value.\n"
478 " defines = [ \"AWESOME_FEATURE\", \"LOG_LEVEL=3\" ]\n";
480 const char kDepfile
[] = "depfile";
481 const char kDepfile_HelpShort
[] =
482 "depfile: [string] File name for input dependencies for actions.";
483 const char kDepfile_Help
[] =
484 "depfile: [string] File name for input dependencies for actions.\n"
486 " If nonempty, this string specifies that the current action or\n"
487 " action_foreach target will generate the given \".d\" file containing\n"
488 " the dependencies of the input. Empty or unset means that the script\n"
489 " doesn't generate the files.\n"
491 " The .d file should go in the target output directory. If you have more\n"
492 " than one source file that the script is being run over, you can use\n"
493 " the output file expansions described in \"gn help action_foreach\" to\n"
494 " name the .d file according to the input."
496 " The format is that of a Makefile, and all of the paths should be\n"
497 " relative to the root build directory.\n"
500 " action_foreach(\"myscript_target\") {\n"
501 " script = \"myscript.py\"\n"
502 " sources = [ ... ]\n"
504 " # Locate the depfile in the output directory named like the\n"
505 " # inputs but with a \".d\" appended.\n"
506 " depfile = \"$relative_target_output_dir/{{source_name}}.d\"\n"
508 " # Say our script uses \"-o <d file>\" to indicate the depfile.\n"
509 " args = [ \"{{source}}\", \"-o\", depfile ]\n"
512 const char kDeps
[] = "deps";
513 const char kDeps_HelpShort
[] =
514 "deps: [label list] Private linked dependencies.";
515 const char kDeps_Help
[] =
516 "deps: Private linked dependencies.\n"
518 " A list of target labels.\n"
520 " Specifies private dependencies of a target. Shared and dynamic\n"
521 " libraries will be linked into the current target. Other target types\n"
522 " that can't be linked (like actions and groups) listed in \"deps\" will\n"
523 " be treated as \"data_deps\". Likewise, if the current target isn't\n"
524 " linkable, then all deps will be treated as \"data_deps\".\n"
526 " These dependencies are private in that it does not grant dependent\n"
527 " targets the ability to include headers from the dependency, and direct\n"
528 " dependent configs are not forwarded.\n"
530 " See also \"public_deps\" and \"data_deps\".\n";
532 const char kForwardDependentConfigsFrom
[] = "forward_dependent_configs_from";
533 const char kForwardDependentConfigsFrom_HelpShort
[] =
534 "forward_dependent_configs_from: [label list] Forward dependent's configs.";
535 const char kForwardDependentConfigsFrom_Help
[] =
536 "forward_dependent_configs_from\n"
538 " A list of target labels.\n"
540 " Exposes the public_configs from a private dependent target as\n"
541 " public_configs of the current one. Each label in this list\n"
542 " must also be in the deps.\n"
544 " Generally you should use public_deps instead of this variable to\n"
545 " express the concept of exposing a dependency as part of a target's\n"
546 " public API. We're considering removing this variable.\n"
550 " Sometimes you depend on a child library that exports some necessary\n"
551 " configuration via public_configs. If your target in turn exposes the\n"
552 " child library's headers in its public headers, it might mean that\n"
553 " targets that depend on you won't work: they'll be seeing the child\n"
554 " library's code but not the necessary configuration. This list\n"
555 " specifies which of your deps' direct dependent configs to expose as\n"
560 " If we use a given library \"a\" from our public headers:\n"
562 " deps = [ \":a\", \":b\", ... ]\n"
563 " forward_dependent_configs_from = [ \":a\" ]\n"
565 " This example makes a \"transparent\" target that forwards a dependency\n"
568 " group(\"frob\") {\n"
569 " if (use_system_frob) {\n"
570 " deps = \":system_frob\"\n"
572 " deps = \"//third_party/fallback_frob\"\n"
574 " forward_dependent_configs_from = deps\n"
577 const char kIncludeDirs
[] = "include_dirs";
578 const char kIncludeDirs_HelpShort
[] =
579 "include_dirs: [directory list] Additional include directories.";
580 const char kIncludeDirs_Help
[] =
581 "include_dirs: Additional include directories.\n"
583 " A list of source directories.\n"
585 " The directories in this list will be added to the include path for\n"
586 " the files in the affected target.\n"
590 " include_dirs = [ \"src/include\", \"//third_party/foo\" ]\n";
592 const char kInputs
[] = "inputs";
593 const char kInputs_HelpShort
[] =
594 "inputs: [file list] Additional compile-time dependencies.";
595 const char kInputs_Help
[] =
596 "inputs: Additional compile-time dependencies.\n"
598 " Inputs are compile-time dependencies of the current target. This means\n"
599 " that all inputs must be available before compiling any of the sources\n"
600 " or executing any actions.\n"
602 " Inputs are typically only used for action and action_foreach targets.\n"
604 "Inputs for actions\n"
606 " For action and action_foreach targets, inputs should be the inputs to\n"
607 " script that don't vary. These should be all .py files that the script\n"
608 " uses via imports (the main script itself will be an implcit dependency\n"
609 " of the action so need not be listed).\n"
611 " For action targets, inputs should be the entire set of inputs the\n"
612 " script needs. For action_foreach targets, inputs should be the set of\n"
613 " dependencies that don't change. These will be applied to each script\n"
614 " invocation over the sources.\n"
616 " Note that another way to declare input dependencies from an action\n"
617 " is to have the action write a depfile (see \"gn help depfile\"). This\n"
618 " allows the script to dynamically write input dependencies, that might\n"
619 " not be known until actually executing the script. This is more\n"
620 " efficient than doing processing while running GN to determine the\n"
621 " inputs, and is easier to keep in-sync than hardcoding the list.\n"
623 "Inputs for binary targets\n"
625 " Any input dependencies will be resolved before compiling any sources.\n"
626 " Normally, all actions that a target depends on will be run before any\n"
627 " files in a target are compiled. So if you depend on generated headers,\n"
628 " you do not typically need to list them in the inputs section.\n"
632 " action(\"myscript\") {\n"
633 " script = \"domything.py\"\n"
634 " inputs = [ \"input.data\" ]\n"
637 const char kLdflags
[] = "ldflags";
638 const char kLdflags_HelpShort
[] =
639 "ldflags: [string list] Flags passed to the linker.";
640 const char kLdflags_Help
[] =
641 "ldflags: Flags passed to the linker.\n"
643 " A list of strings.\n"
645 " These flags are passed on the command-line to the linker and generally\n"
646 " specify various linking options. Most targets will not need these and\n"
647 " will use \"libs\" and \"lib_dirs\" instead.\n"
649 " ldflags are NOT pushed to dependents, so applying ldflags to source\n"
650 " sets or static libraries will be a no-op. If you want to apply ldflags\n"
651 " to dependent targets, put them in a config and set it in the\n"
652 " all_dependent_configs or public_configs.\n";
654 #define COMMON_LIB_INHERITANCE_HELP \
656 " libs and lib_dirs work differently than other flags in two respects.\n" \
657 " First, then are inherited across static library boundaries until a\n" \
658 " shared library or executable target is reached. Second, they are\n" \
659 " uniquified so each one is only passed once (the first instance of it\n" \
660 " will be the one used).\n"
662 const char kLibDirs
[] = "lib_dirs";
663 const char kLibDirs_HelpShort
[] =
664 "lib_dirs: [directory list] Additional library directories.";
665 const char kLibDirs_Help
[] =
666 "lib_dirs: Additional library directories.\n"
668 " A list of directories.\n"
670 " Specifies additional directories passed to the linker for searching\n"
671 " for the required libraries. If an item is not an absolute path, it\n"
672 " will be treated as being relative to the current build file.\n"
673 COMMON_LIB_INHERITANCE_HELP
677 " lib_dirs = [ \"/usr/lib/foo\", \"lib/doom_melon\" ]\n";
679 const char kLibs
[] = "libs";
680 const char kLibs_HelpShort
[] =
681 "libs: [string list] Additional libraries to link.";
682 const char kLibs_Help
[] =
683 "libs: Additional libraries to link.\n"
685 " A list of strings.\n"
687 " These files will be passed to the linker, which will generally search\n"
688 " the library include path. Unlike a normal list of files, they will be\n"
689 " passed to the linker unmodified rather than being treated as file\n"
690 " names relative to the current build file. Generally you would set\n"
691 " the \"lib_dirs\" so your library is found. If you need to specify\n"
692 " a path, you can use \"rebase_path\" to convert a path to be relative\n"
693 " to the build directory.\n"
695 " When constructing the linker command, the \"lib_prefix\" attribute of\n"
696 " the linker tool in the current toolchain will be prepended to each\n"
697 " library. So your BUILD file should not specify the switch prefix\n"
698 " (like \"-l\"). On Mac, libraries ending in \".framework\" will be\n"
699 " special-cased: the switch \"-framework\" will be prepended instead of\n"
700 " the lib_prefix, and the \".framework\" suffix will be trimmed.\n"
701 COMMON_LIB_INHERITANCE_HELP
706 " libs = [ \"ctl3d.lib\" ]\n"
708 " libs = [ \"ld\" ]\n";
710 const char kOutputExtension
[] = "output_extension";
711 const char kOutputExtension_HelpShort
[] =
712 "output_extension: [string] Value to use for the output's file extension.";
713 const char kOutputExtension_Help
[] =
714 "output_extension: Value to use for the output's file extension.\n"
716 " Normally the file extension for a target is based on the target\n"
717 " type and the operating system, but in rare cases you will need to\n"
718 " override the name (for example to use \"libfreetype.so.6\" instead\n"
719 " of libfreetype.so on Linux).";
721 const char kOutputName
[] = "output_name";
722 const char kOutputName_HelpShort
[] =
723 "output_name: [string] Name for the output file other than the default.";
724 const char kOutputName_Help
[] =
725 "output_name: Define a name for the output file other than the default.\n"
727 " Normally the output name of a target will be based on the target name,\n"
728 " so the target \"//foo/bar:bar_unittests\" will generate an output\n"
729 " file such as \"bar_unittests.exe\" (using Windows as an example).\n"
731 " Sometimes you will want an alternate name to avoid collisions or\n"
732 " if the internal name isn't appropriate for public distribution.\n"
734 " The output name should have no extension or prefixes, these will be\n"
735 " added using the default system rules. For example, on Linux an output\n"
736 " name of \"foo\" will produce a shared library \"libfoo.so\".\n"
738 " This variable is valid for all binary output target types.\n"
741 " static_library(\"doom_melon\") {\n"
742 " output_name = \"fluffy_bunny\"\n"
745 const char kOutputs
[] = "outputs";
746 const char kOutputs_HelpShort
[] =
747 "outputs: [file list] Output files for actions and copy targets.";
748 const char kOutputs_Help
[] =
749 "outputs: Output files for actions and copy targets.\n"
751 " Outputs is valid for \"copy\", \"action\", and \"action_foreach\"\n"
752 " target types and indicates the resulting files. The values may contain\n"
753 " source expansions to generate the output names from the sources (see\n"
754 " \"gn help source_expansion\").\n"
756 " For copy targets, the outputs is the destination for the copied\n"
757 " file(s). For actions, the outputs should be the list of files\n"
758 " generated by the script.\n";
760 const char kPublic
[] = "public";
761 const char kPublic_HelpShort
[] =
762 "public: [file list] Declare public header files for a target.";
763 const char kPublic_Help
[] =
764 "public: Declare public header files for a target.\n"
766 " A list of files that other targets can include. These permissions are\n"
767 " checked via the \"check\" command (see \"gn help check\").\n"
769 " If no public files are declared, other targets (assuming they have\n"
770 " visibility to depend on this target can include any file in the\n"
771 " sources list. If this variable is defined on a target, dependent\n"
772 " targets may only include files on this whitelist.\n"
774 " Header file permissions are also subject to visibility. A target\n"
775 " must be visible to another target to include any files from it at all\n"
776 " and the public headers indicate which subset of those files are\n"
777 " permitted. See \"gn help visibility\" for more.\n"
779 " Public files are inherited through the dependency tree. So if there is\n"
780 " a dependency A -> B -> C, then A can include C's public headers.\n"
781 " However, the same is NOT true of visibility, so unless A is in C's\n"
782 " visibility list, the include will be rejected.\n"
784 " GN only knows about files declared in the \"sources\" and \"public\"\n"
785 " sections of targets. If a file is included that is not known to the\n"
786 " build, it will be allowed.\n"
789 " These exact files are public:\n"
790 " public = [ \"foo.h\", \"bar.h\" ]\n"
792 " No files are public (no targets may include headers from this one):\n"
795 const char kPublicConfigs
[] = "public_configs";
796 const char kPublicConfigs_HelpShort
[] =
797 "public_configs: [label list] Configs applied to dependents.";
798 const char kPublicConfigs_Help
[] =
799 "public_configs: Configs to be applied on dependents.\n"
801 " A list of config labels.\n"
803 " Targets directly depending on this one will have the configs listed in\n"
804 " this variable added to them. These configs will also apply to the\n"
807 " This addition happens in a second phase once a target and all of its\n"
808 " dependencies have been resolved. Therefore, a target will not see\n"
809 " these force-added configs in their \"configs\" variable while the\n"
810 " script is running, and then can not be removed. As a result, this\n"
811 " capability should generally only be used to add defines and include\n"
812 " directories necessary to compile a target's headers.\n"
814 " See also \"all_dependent_configs\".\n"
815 COMMON_ORDERING_HELP
;
817 const char kPublicDeps
[] = "public_deps";
818 const char kPublicDeps_HelpShort
[] =
819 "public_deps: [label list] Declare public dependencies.";
820 const char kPublicDeps_Help
[] =
821 "public_deps: Declare public dependencies.\n"
823 " Public dependencies are like private dependencies (\"deps\") but\n"
824 " additionally express that the current target exposes the listed deps\n"
825 " as part of its public API.\n"
827 " This has two ramifications:\n"
829 " - public_configs that are part of the dependency are forwarded\n"
830 " to direct dependents (this is the same as using\n"
831 " forward_dependent_configs_from).\n"
833 " - public headers in the dependency are usable by dependents\n"
834 " (includes do not require a direct dependency or visibility).\n"
838 " Say you have three targets: A -> B -> C. C's visibility may allow\n"
839 " B to depend on it but not A. Normally, this would prevent A from\n"
840 " including any headers from C, and C's public_configs would apply\n"
843 " If B lists C in its public_deps instead of regular deps, A will now\n"
844 " inherit C's public_configs and the ability to include C's public\n"
847 " Generally if you are writing a target B and you include C's headers\n"
848 " as part of B's public headers, or targets depending on B should\n"
849 " consider B and C to be part of a unit, you should use public_deps\n"
850 " instead of deps.\n"
854 " # This target can include files from \"c\" but not from\n"
855 " # \"super_secret_implementation_details\".\n"
856 " executable(\"a\") {\n"
857 " deps = [ \":b\" ]\n"
860 " shared_library(\"b\") {\n"
861 " deps = [ \":super_secret_implementation_details\" ]\n"
862 " public_deps = [ \":c\" ]\n"
865 const char kScript
[] = "script";
866 const char kScript_HelpShort
[] =
867 "script: [file name] Script file for actions.";
868 const char kScript_Help
[] =
869 "script: Script file for actions.\n"
871 " An absolute or buildfile-relative file name of a Python script to run\n"
872 " for a action and action_foreach targets (see \"gn help action\" and\n"
873 " \"gn help action_foreach\").\n";
875 const char kSources
[] = "sources";
876 const char kSources_HelpShort
[] =
877 "sources: [file list] Source files for a target.";
878 const char kSources_Help
[] =
879 "sources: Source files for a target\n"
881 " A list of files relative to the current buildfile.\n";
883 const char kTestonly
[] = "testonly";
884 const char kTestonly_HelpShort
[] =
885 "testonly: [boolean] Declares a target must only be used for testing.";
886 const char kTestonly_Help
[] =
887 "testonly: Declares a target must only be used for testing.\n"
889 " Boolean. Defaults to false.\n"
891 " When a target is marked \"testonly = true\", it must only be depended\n"
892 " on by other test-only targets. Otherwise, GN will issue an error\n"
893 " that the depenedency is not allowed.\n"
895 " This feature is intended to prevent accidentally shipping test code\n"
896 " in a final product.\n"
900 " source_set(\"test_support\") {\n"
905 const char kVisibility
[] = "visibility";
906 const char kVisibility_HelpShort
[] =
907 "visibility: [label list] A list of labels that can depend on a target.";
908 const char kVisibility_Help
[] =
909 "visibility: A list of labels that can depend on a target.\n"
911 " A list of labels and label patterns that define which targets can\n"
912 " depend on the current one. These permissions are checked via the\n"
913 " \"check\" command (see \"gn help check\").\n"
915 " If visibility is not defined, it defaults to public (\"*\").\n"
917 " If visibility is defined, only the targets with labels that match it\n"
918 " can depend on the current target. The empty list means no targets\n"
919 " can depend on the current target.\n"
921 " Tip: Often you will want the same visibility for all targets in a\n"
922 " BUILD file. In this case you can just put the definition at the top,\n"
923 " outside of any target, and the targets will inherit that scope and see\n"
928 " See \"gn help label_pattern\" for more details on what types of\n"
929 " patterns are supported. If a toolchain is specified, only targets\n"
930 " in that toolchain will be matched. If a toolchain is not specified on\n"
931 " a pattern, targets in all toolchains will be matched.\n"
935 " Only targets in the current buildfile (\"private\"):\n"
936 " visibility = [ \":*\" ]\n"
938 " No targets (used for targets that should be leaf nodes):\n"
941 " Any target (\"public\", the default):\n"
942 " visibility = [ \"*\" ]\n"
944 " All targets in the current directory and any subdirectory:\n"
945 " visibility = [ \"./*\" ]\n"
947 " Any target in \"//bar/BUILD.gn\":\n"
948 " visibility = [ \"//bar:*\" ]\n"
950 " Any target in \"//bar/\" or any subdirectory thereof:\n"
951 " visibility = [ \"//bar/*\" ]\n"
953 " Just these specific targets:\n"
954 " visibility = [ \":mything\", \"//foo:something_else\" ]\n"
956 " Any target in the current directory and any subdirectory thereof, plus\n"
957 " any targets in \"//bar/\" and any subdirectory thereof.\n"
958 " visibility = [ \"./*\", \"//bar/*\" ]\n";
960 // -----------------------------------------------------------------------------
962 VariableInfo::VariableInfo()
967 VariableInfo::VariableInfo(const char* in_help_short
, const char* in_help
)
968 : help_short(in_help_short
),
972 #define INSERT_VARIABLE(var) \
973 info_map[k##var] = VariableInfo(k##var##_HelpShort, k##var##_Help);
975 const VariableInfoMap
& GetBuiltinVariables() {
976 static VariableInfoMap info_map
;
977 if (info_map
.empty()) {
978 INSERT_VARIABLE(BuildCpuArch
)
979 INSERT_VARIABLE(BuildOs
)
980 INSERT_VARIABLE(CpuArch
)
981 INSERT_VARIABLE(CurrentToolchain
)
982 INSERT_VARIABLE(DefaultToolchain
)
984 INSERT_VARIABLE(PythonPath
)
985 INSERT_VARIABLE(RootBuildDir
)
986 INSERT_VARIABLE(RootGenDir
)
987 INSERT_VARIABLE(RootOutDir
)
988 INSERT_VARIABLE(TargetGenDir
)
989 INSERT_VARIABLE(TargetOutDir
)
994 const VariableInfoMap
& GetTargetVariables() {
995 static VariableInfoMap info_map
;
996 if (info_map
.empty()) {
997 INSERT_VARIABLE(AllDependentConfigs
)
998 INSERT_VARIABLE(AllowCircularIncludesFrom
)
999 INSERT_VARIABLE(Args
)
1000 INSERT_VARIABLE(Cflags
)
1001 INSERT_VARIABLE(CflagsC
)
1002 INSERT_VARIABLE(CflagsCC
)
1003 INSERT_VARIABLE(CflagsObjC
)
1004 INSERT_VARIABLE(CflagsObjCC
)
1005 INSERT_VARIABLE(CheckIncludes
)
1006 INSERT_VARIABLE(CompleteStaticLib
)
1007 INSERT_VARIABLE(Configs
)
1008 INSERT_VARIABLE(Data
)
1009 INSERT_VARIABLE(DataDeps
)
1010 INSERT_VARIABLE(Defines
)
1011 INSERT_VARIABLE(Depfile
)
1012 INSERT_VARIABLE(Deps
)
1013 INSERT_VARIABLE(ForwardDependentConfigsFrom
)
1014 INSERT_VARIABLE(IncludeDirs
)
1015 INSERT_VARIABLE(Inputs
)
1016 INSERT_VARIABLE(Ldflags
)
1017 INSERT_VARIABLE(Libs
)
1018 INSERT_VARIABLE(LibDirs
)
1019 INSERT_VARIABLE(OutputExtension
)
1020 INSERT_VARIABLE(OutputName
)
1021 INSERT_VARIABLE(Outputs
)
1022 INSERT_VARIABLE(Public
)
1023 INSERT_VARIABLE(PublicConfigs
)
1024 INSERT_VARIABLE(PublicDeps
)
1025 INSERT_VARIABLE(Script
)
1026 INSERT_VARIABLE(Sources
)
1027 INSERT_VARIABLE(Testonly
)
1028 INSERT_VARIABLE(Visibility
)
1033 #undef INSERT_VARIABLE
1035 } // namespace variables