OLD | NEW |
1 # GN Reference | 1 # GN Reference |
2 | 2 |
3 *This page is automatically generated from* `gn help --markdown all`. | 3 *This page is automatically generated from* `gn help --markdown all`. |
4 | 4 |
5 ## **--args**: Specifies build arguments overrides. | 5 ## **--args**: Specifies build arguments overrides. |
6 | 6 |
7 ``` | 7 ``` |
8 See "gn help buildargs" for an overview of how build arguments work. | 8 See "gn help buildargs" for an overview of how build arguments work. |
9 | 9 |
10 Most operations take a build directory. The build arguments are taken | 10 Most operations take a build directory. The build arguments are taken |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 tree in the order that the targets appear in "deps". | 1004 tree in the order that the targets appear in "deps". |
1005 4. All dependent configs from a breadth-first traversal of the | 1005 4. All dependent configs from a breadth-first traversal of the |
1006 dependency tree in the order that the targets appear in "deps". | 1006 dependency tree in the order that the targets appear in "deps". |
1007 | 1007 |
1008 ``` | 1008 ``` |
1009 | 1009 |
1010 ### **Variables valid in a config definition**: | 1010 ### **Variables valid in a config definition**: |
1011 ``` | 1011 ``` |
1012 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1012 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1013 defines, include_dirs, ldflags, lib_dirs, libs | 1013 defines, include_dirs, ldflags, lib_dirs, libs |
| 1014 precompiled_header, precompiled_source |
1014 | 1015 |
1015 ``` | 1016 ``` |
1016 | 1017 |
1017 ### **Variables on a target used to apply configs**: | 1018 ### **Variables on a target used to apply configs**: |
1018 ``` | 1019 ``` |
1019 all_dependent_configs, configs, public_configs, | 1020 all_dependent_configs, configs, public_configs, |
1020 forward_dependent_configs_from | 1021 forward_dependent_configs_from |
1021 | 1022 |
1022 ``` | 1023 ``` |
1023 | 1024 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 | 1203 |
1203 | 1204 |
1204 ``` | 1205 ``` |
1205 ## **executable**: Declare an executable target. | 1206 ## **executable**: Declare an executable target. |
1206 | 1207 |
1207 ### **Variables** | 1208 ### **Variables** |
1208 | 1209 |
1209 ``` | 1210 ``` |
1210 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1211 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1211 defines, include_dirs, ldflags, lib_dirs, libs | 1212 defines, include_dirs, ldflags, lib_dirs, libs |
| 1213 precompiled_header, precompiled_source |
1212 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 1214 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
1213 Dependent configs: all_dependent_configs, public_configs | 1215 Dependent configs: all_dependent_configs, public_configs |
1214 General: check_includes, configs, data, inputs, output_name, | 1216 General: check_includes, configs, data, inputs, output_name, |
1215 output_extension, public, sources, testonly, visibility | 1217 output_extension, public, sources, testonly, visibility |
1216 | 1218 |
1217 | 1219 |
1218 ``` | 1220 ``` |
1219 ## **foreach**: Iterate over a list. | 1221 ## **foreach**: Iterate over a list. |
1220 | 1222 |
1221 ``` | 1223 ``` |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 (say you dynamically load the library at runtime), then you should | 1915 (say you dynamically load the library at runtime), then you should |
1914 depend on the shared library via "data_deps" instead. | 1916 depend on the shared library via "data_deps" instead. |
1915 | 1917 |
1916 ``` | 1918 ``` |
1917 | 1919 |
1918 ### **Variables** | 1920 ### **Variables** |
1919 | 1921 |
1920 ``` | 1922 ``` |
1921 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1923 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1922 defines, include_dirs, ldflags, lib_dirs, libs | 1924 defines, include_dirs, ldflags, lib_dirs, libs |
| 1925 precompiled_header, precompiled_source |
1923 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 1926 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
1924 Dependent configs: all_dependent_configs, public_configs | 1927 Dependent configs: all_dependent_configs, public_configs |
1925 General: check_includes, configs, data, inputs, output_name, | 1928 General: check_includes, configs, data, inputs, output_name, |
1926 output_extension, public, sources, testonly, visibility | 1929 output_extension, public, sources, testonly, visibility |
1927 | 1930 |
1928 | 1931 |
1929 ``` | 1932 ``` |
1930 ## **source_set**: Declare a source set target. | 1933 ## **source_set**: Declare a source set target. |
1931 | 1934 |
1932 ``` | 1935 ``` |
(...skipping 20 matching lines...) Expand all Loading... |
1953 no way to express this concept when linking multiple static libraries | 1956 no way to express this concept when linking multiple static libraries |
1954 into a shared library. | 1957 into a shared library. |
1955 | 1958 |
1956 ``` | 1959 ``` |
1957 | 1960 |
1958 ### **Variables** | 1961 ### **Variables** |
1959 | 1962 |
1960 ``` | 1963 ``` |
1961 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1964 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1962 defines, include_dirs, ldflags, lib_dirs, libs | 1965 defines, include_dirs, ldflags, lib_dirs, libs |
| 1966 precompiled_header, precompiled_source |
1963 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 1967 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
1964 Dependent configs: all_dependent_configs, public_configs | 1968 Dependent configs: all_dependent_configs, public_configs |
1965 General: check_includes, configs, data, inputs, output_name, | 1969 General: check_includes, configs, data, inputs, output_name, |
1966 output_extension, public, sources, testonly, visibility | 1970 output_extension, public, sources, testonly, visibility |
1967 | 1971 |
1968 | 1972 |
1969 ``` | 1973 ``` |
1970 ## **static_library**: Declare a static library target. | 1974 ## **static_library**: Declare a static library target. |
1971 | 1975 |
1972 ``` | 1976 ``` |
1973 Make a ".a" / ".lib" file. | 1977 Make a ".a" / ".lib" file. |
1974 | 1978 |
1975 If you only need the static library for intermediate results in the | 1979 If you only need the static library for intermediate results in the |
1976 build, you should consider a source_set instead since it will skip | 1980 build, you should consider a source_set instead since it will skip |
1977 the (potentially slow) step of creating the intermediate library file. | 1981 the (potentially slow) step of creating the intermediate library file. |
1978 | 1982 |
1979 ``` | 1983 ``` |
1980 | 1984 |
1981 ### **Variables** | 1985 ### **Variables** |
1982 | 1986 |
1983 ``` | 1987 ``` |
1984 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1988 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1985 defines, include_dirs, ldflags, lib_dirs, libs | 1989 defines, include_dirs, ldflags, lib_dirs, libs |
| 1990 precompiled_header, precompiled_source |
1986 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 1991 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
1987 Dependent configs: all_dependent_configs, public_configs | 1992 Dependent configs: all_dependent_configs, public_configs |
1988 General: check_includes, configs, data, inputs, output_name, | 1993 General: check_includes, configs, data, inputs, output_name, |
1989 output_extension, public, sources, testonly, visibility | 1994 output_extension, public, sources, testonly, visibility |
1990 | 1995 |
1991 | 1996 |
1992 ``` | 1997 ``` |
1993 ## **template**: Define a template rule. | 1998 ## **template**: Define a template rule. |
1994 | 1999 |
1995 ``` | 2000 ``` |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 Prefix to use for the output name. Defaults to empty. This | 2290 Prefix to use for the output name. Defaults to empty. This |
2286 prefix will be prepended to the name of the target (or the | 2291 prefix will be prepended to the name of the target (or the |
2287 output_name if one is manually specified for it) if the prefix | 2292 output_name if one is manually specified for it) if the prefix |
2288 is not already there. The result will show up in the | 2293 is not already there. The result will show up in the |
2289 {{output_name}} substitution pattern. | 2294 {{output_name}} substitution pattern. |
2290 | 2295 |
2291 This is typically used to prepend "lib" to libraries on | 2296 This is typically used to prepend "lib" to libraries on |
2292 Posix systems: | 2297 Posix systems: |
2293 output_prefix = "lib" | 2298 output_prefix = "lib" |
2294 | 2299 |
| 2300 precompiled_header_type [string] |
| 2301 Valid for: "cc", "cxx", "objc", "objcxx" |
| 2302 |
| 2303 Type of precompiled headers. If undefined or the empty string, |
| 2304 precompiled headers will not be used for this tool. Otherwise |
| 2305 use "msvc" which is the only currently supported value. |
| 2306 |
| 2307 For precompiled headers to be used for a given target, the |
| 2308 target (or a config applied to it) must also specify a |
| 2309 "precompiled_header" and, for "msvc"-style headers, a |
| 2310 "precompiled_source" value. |
| 2311 |
| 2312 See "gn help precompiled_header" for more. |
| 2313 |
2295 restat [boolean] | 2314 restat [boolean] |
2296 Valid for: all tools (optional, defaults to false) | 2315 Valid for: all tools (optional, defaults to false) |
2297 | 2316 |
2298 Requests that Ninja check the file timestamp after this tool has | 2317 Requests that Ninja check the file timestamp after this tool has |
2299 run to determine if anything changed. Set this if your tool has | 2318 run to determine if anything changed. Set this if your tool has |
2300 the ability to skip writing output if the output file has not | 2319 the ability to skip writing output if the output file has not |
2301 changed. | 2320 changed. |
2302 | 2321 |
2303 Normally, Ninja will assume that when a tool runs the output | 2322 Normally, Ninja will assume that when a tool runs the output |
2304 be new and downstream dependents must be rebuild. When this is | 2323 be new and downstream dependents must be rebuild. When this is |
(...skipping 20 matching lines...) Expand all Loading... |
2325 but passes the linker flags directly on the command line: | 2344 but passes the linker flags directly on the command line: |
2326 tool("link") { | 2345 tool("link") { |
2327 command = "link -o {{output}} {{ldflags}} @{{output}}.rsp" | 2346 command = "link -o {{output}} {{ldflags}} @{{output}}.rsp" |
2328 rspfile = "{{output}}.rsp" | 2347 rspfile = "{{output}}.rsp" |
2329 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" | 2348 rspfile_content = "{{inputs}} {{solibs}} {{libs}}" |
2330 } | 2349 } |
2331 | 2350 |
2332 ``` | 2351 ``` |
2333 | 2352 |
2334 ### **Expansions for tool variables** | 2353 ### **Expansions for tool variables** |
| 2354 |
2335 ``` | 2355 ``` |
2336 All paths are relative to the root build directory, which is the | 2356 All paths are relative to the root build directory, which is the |
2337 current directory for running all tools. These expansions are | 2357 current directory for running all tools. These expansions are |
2338 available to all tools: | 2358 available to all tools: |
2339 | 2359 |
2340 {{label}} | 2360 {{label}} |
2341 The label of the current target. This is typically used in the | 2361 The label of the current target. This is typically used in the |
2342 "description" field for link tools. The toolchain will be | 2362 "description" field for link tools. The toolchain will be |
2343 omitted from the label for targets in the default toolchain, and | 2363 omitted from the label for targets in the default toolchain, and |
2344 will be included for targets in other toolchains. | 2364 will be included for targets in other toolchains. |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3235 When true (the default), the "gn check" command (as well as | 3255 When true (the default), the "gn check" command (as well as |
3236 "gn gen" with the --check flag) will check this target's sources | 3256 "gn gen" with the --check flag) will check this target's sources |
3237 and headers for proper dependencies. | 3257 and headers for proper dependencies. |
3238 | 3258 |
3239 When false, the files in this target will be skipped by default. | 3259 When false, the files in this target will be skipped by default. |
3240 This does not affect other targets that depend on the current target, | 3260 This does not affect other targets that depend on the current target, |
3241 it just skips checking the includes of the current target's files. | 3261 it just skips checking the includes of the current target's files. |
3242 | 3262 |
3243 ``` | 3263 ``` |
3244 | 3264 |
| 3265 ### **Controlling includes individually** |
| 3266 |
| 3267 ``` |
| 3268 If only certain includes are problematic, you can annotate them |
| 3269 individually rather than disabling header checking on an entire |
| 3270 target. Add the string "nogncheck" to the include line: |
| 3271 |
| 3272 #include "foo/something_weird.h" // nogncheck (bug 12345) |
| 3273 |
| 3274 It is good form to include a reference to a bug (if the include is |
| 3275 improper, or some other comment expressing why the header checker |
| 3276 doesn't work for this particular case. |
| 3277 |
| 3278 The most common reason to need "nogncheck" is conditional includes. |
| 3279 The header checker does not understand the preprocessor, so may flag |
| 3280 some includes as improper even if the dependencies and #defines are |
| 3281 always matched correctly: |
| 3282 |
| 3283 #if defined(ENABLE_DOOM_MELON) |
| 3284 #include "doom_melon/beam_controller.h" // nogncheck |
| 3285 #endif |
| 3286 |
| 3287 ``` |
| 3288 |
3245 ### **Example** | 3289 ### **Example** |
3246 | 3290 |
3247 ``` | 3291 ``` |
3248 source_set("busted_includes") { | 3292 source_set("busted_includes") { |
3249 # This target's includes are messed up, exclude it from checking. | 3293 # This target's includes are messed up, exclude it from checking. |
3250 check_includes = false | 3294 check_includes = false |
3251 ... | 3295 ... |
3252 } | 3296 } |
3253 | 3297 |
3254 | 3298 |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3765 target types and indicates the resulting files. The values may contain | 3809 target types and indicates the resulting files. The values may contain |
3766 source expansions to generate the output names from the sources (see | 3810 source expansions to generate the output names from the sources (see |
3767 "gn help source_expansion"). | 3811 "gn help source_expansion"). |
3768 | 3812 |
3769 For copy targets, the outputs is the destination for the copied | 3813 For copy targets, the outputs is the destination for the copied |
3770 file(s). For actions, the outputs should be the list of files | 3814 file(s). For actions, the outputs should be the list of files |
3771 generated by the script. | 3815 generated by the script. |
3772 | 3816 |
3773 | 3817 |
3774 ``` | 3818 ``` |
| 3819 ## **precompiled_header**: [string] Header file to precompile. |
| 3820 |
| 3821 ``` |
| 3822 Precompiled headers will be used when a target specifies this |
| 3823 value, or a config applying to this target specifies this value. |
| 3824 In addition, the tool corresponding to the source files must also |
| 3825 specify precompiled headers (see "gn help tool"). The tool |
| 3826 will also specify what type of precompiled headers to use. |
| 3827 |
| 3828 The precompiled header/source variables can be specified on a target |
| 3829 or a config, but must be the same for all configs applying to a given |
| 3830 target since a target can only have one precompiled header. |
| 3831 |
| 3832 ``` |
| 3833 |
| 3834 ### **MSVC precompiled headers** |
| 3835 |
| 3836 ``` |
| 3837 When using MSVC-style precompiled headers, the "precompiled_header" |
| 3838 value is a string corresponding to the header. This is NOT a path |
| 3839 to a file that GN recognises, but rather the exact string that appears |
| 3840 in quotes after an #include line in source code. The compiler will |
| 3841 match this string against includes or forced includes (/FI). |
| 3842 |
| 3843 MSVC also requires a source file to compile the header with. This must |
| 3844 be specified by the "precompiled_source" value. In contrast to the |
| 3845 header value, this IS a GN-style file name, and tells GN which source |
| 3846 file to compile to make the .pch file used for subsequent compiles. |
| 3847 |
| 3848 If you use both C and C++ sources, the precompiled header and source |
| 3849 file will be compiled using both tools. You will want to make sure |
| 3850 to wrap C++ includes in __cplusplus #ifdefs so the file will compile |
| 3851 in C mode. |
| 3852 |
| 3853 For example, if the toolchain specifies MSVC headers: |
| 3854 |
| 3855 toolchain("vc_x64") { |
| 3856 ... |
| 3857 tool("cxx") { |
| 3858 precompiled_header_type = "msvc" |
| 3859 ... |
| 3860 |
| 3861 You might make a config like this: |
| 3862 |
| 3863 config("use_precompiled_headers") { |
| 3864 precompiled_header = "build/precompile.h" |
| 3865 precompiled_source = "//build/precompile.cc" |
| 3866 |
| 3867 # Either your source files should #include "build/precompile.h" |
| 3868 # first, or you can do this to force-include the header. |
| 3869 cflags = [ "/FI$precompiled_header" ] |
| 3870 } |
| 3871 |
| 3872 And then define a target that uses the config: |
| 3873 |
| 3874 executable("doom_melon") { |
| 3875 configs += [ ":use_precompiled_headers" ] |
| 3876 ... |
| 3877 |
| 3878 |
| 3879 |
| 3880 ``` |
| 3881 ## **precompiled_source**: [file name] Source file to precompile. |
| 3882 |
| 3883 ``` |
| 3884 The source file that goes along with the precompiled_header when |
| 3885 using "msvc"-style precompiled headers. It will be implicitly added |
| 3886 to the sources of the target. See "gn help precompiled_header". |
| 3887 |
| 3888 |
| 3889 ``` |
3775 ## **public**: Declare public header files for a target. | 3890 ## **public**: Declare public header files for a target. |
3776 | 3891 |
3777 ``` | 3892 ``` |
3778 A list of files that other targets can include. These permissions are | 3893 A list of files that other targets can include. These permissions are |
3779 checked via the "check" command (see "gn help check"). | 3894 checked via the "check" command (see "gn help check"). |
3780 | 3895 |
3781 If no public files are declared, other targets (assuming they have | 3896 If no public files are declared, other targets (assuming they have |
3782 visibility to depend on this target can include any file in the | 3897 visibility to depend on this target can include any file in the |
3783 sources list. If this variable is defined on a target, dependent | 3898 sources list. If this variable is defined on a target, dependent |
3784 targets may only include files on this whitelist. | 3899 targets may only include files on this whitelist. |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4556 ** --nocolor**: Force non-colored output. | 4671 ** --nocolor**: Force non-colored output. |
4557 ** -q**: Quiet mode. Don't print output on success. | 4672 ** -q**: Quiet mode. Don't print output on success. |
4558 ** --root**: Explicitly specify source root. | 4673 ** --root**: Explicitly specify source root. |
4559 ** --runtime-deps-list-file**: Save runtime dependencies for targets in file. | 4674 ** --runtime-deps-list-file**: Save runtime dependencies for targets in file. |
4560 ** --time**: Outputs a summary of how long everything took. | 4675 ** --time**: Outputs a summary of how long everything took. |
4561 ** --tracelog**: Writes a Chrome-compatible trace log to the given file. | 4676 ** --tracelog**: Writes a Chrome-compatible trace log to the given file. |
4562 ** -v**: Verbose logging. | 4677 ** -v**: Verbose logging. |
4563 ** --version**: Prints the GN version number and exits. | 4678 ** --version**: Prints the GN version number and exits. |
4564 | 4679 |
4565 ``` | 4680 ``` |
OLD | NEW |