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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 This is probably not useful; the use-case for this feature is | 147 This is probably not useful; the use-case for this feature is |
148 generally executable targets. | 148 generally executable targets. |
149 | 149 |
150 The runtime dependency file will list one file per line, with no | 150 The runtime dependency file will list one file per line, with no |
151 escaping. The files will be relative to the root_build_dir. The first | 151 escaping. The files will be relative to the root_build_dir. The first |
152 line of the file will be the main output file of the target itself | 152 line of the file will be the main output file of the target itself |
153 (in the above example, "bar.so"). | 153 (in the above example, "bar.so"). |
154 | 154 |
155 | 155 |
156 ``` | 156 ``` |
| 157 ## **\--threads**: Specify number of worker threads. |
| 158 |
| 159 ``` |
| 160 GN runs many threads to load and run build files. This can make |
| 161 debugging challenging. Or you may want to experiment with different |
| 162 values to see how it affects performance. |
| 163 |
| 164 The parameter is the number of worker threads. This does not count the |
| 165 main thread (so there are always at least two). |
| 166 |
| 167 ``` |
| 168 |
| 169 ### **Examples** |
| 170 |
| 171 ``` |
| 172 gen gen out/Default --threads=1 |
| 173 |
| 174 |
| 175 ``` |
157 ## **\--time**: Outputs a summary of how long everything took. | 176 ## **\--time**: Outputs a summary of how long everything took. |
158 | 177 |
159 ``` | 178 ``` |
160 Hopefully self-explanatory. | 179 Hopefully self-explanatory. |
161 | 180 |
162 ``` | 181 ``` |
163 | 182 |
164 ### **Examples** | 183 ### **Examples** |
165 | 184 |
166 ``` | 185 ``` |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 3. Public_configs from a breadth-first traversal of the dependency | 1022 3. Public_configs from a breadth-first traversal of the dependency |
1004 tree in the order that the targets appear in "deps". | 1023 tree in the order that the targets appear in "deps". |
1005 4. All dependent configs from a breadth-first traversal of the | 1024 4. All dependent configs from a breadth-first traversal of the |
1006 dependency tree in the order that the targets appear in "deps". | 1025 dependency tree in the order that the targets appear in "deps". |
1007 | 1026 |
1008 ``` | 1027 ``` |
1009 | 1028 |
1010 ### **Variables valid in a config definition**: | 1029 ### **Variables valid in a config definition**: |
1011 ``` | 1030 ``` |
1012 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1031 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1013 defines, include_dirs, ldflags, lib_dirs, libs | 1032 defines, include_dirs, ldflags, lib_dirs, libs, |
1014 precompiled_header, precompiled_source | 1033 precompiled_header, precompiled_source |
1015 | 1034 |
1016 ``` | 1035 ``` |
1017 | 1036 |
1018 ### **Variables on a target used to apply configs**: | 1037 ### **Variables on a target used to apply configs**: |
1019 ``` | 1038 ``` |
1020 all_dependent_configs, configs, public_configs, | 1039 all_dependent_configs, configs, public_configs, |
1021 forward_dependent_configs_from | 1040 forward_dependent_configs_from |
1022 | 1041 |
1023 ``` | 1042 ``` |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 exec_script("//foo/bar/myscript.py") | 1221 exec_script("//foo/bar/myscript.py") |
1203 | 1222 |
1204 | 1223 |
1205 ``` | 1224 ``` |
1206 ## **executable**: Declare an executable target. | 1225 ## **executable**: Declare an executable target. |
1207 | 1226 |
1208 ### **Variables** | 1227 ### **Variables** |
1209 | 1228 |
1210 ``` | 1229 ``` |
1211 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 1230 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1212 defines, include_dirs, ldflags, lib_dirs, libs | 1231 defines, include_dirs, ldflags, lib_dirs, libs, |
1213 precompiled_header, precompiled_source | 1232 precompiled_header, precompiled_source |
1214 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 1233 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
1215 Dependent configs: all_dependent_configs, public_configs | 1234 Dependent configs: all_dependent_configs, public_configs |
1216 General: check_includes, configs, data, inputs, output_name, | 1235 General: check_includes, configs, data, inputs, output_name, |
1217 output_extension, public, sources, testonly, visibility | 1236 output_extension, public, sources, testonly, visibility |
1218 | 1237 |
1219 | 1238 |
1220 ``` | 1239 ``` |
1221 ## **foreach**: Iterate over a list. | 1240 ## **foreach**: Iterate over a list. |
1222 | 1241 |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 listing the shared library in its "deps". If you don't want this | 1996 listing the shared library in its "deps". If you don't want this |
1978 (say you dynamically load the library at runtime), then you should | 1997 (say you dynamically load the library at runtime), then you should |
1979 depend on the shared library via "data_deps" instead. | 1998 depend on the shared library via "data_deps" instead. |
1980 | 1999 |
1981 ``` | 2000 ``` |
1982 | 2001 |
1983 ### **Variables** | 2002 ### **Variables** |
1984 | 2003 |
1985 ``` | 2004 ``` |
1986 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 2005 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
1987 defines, include_dirs, ldflags, lib_dirs, libs | 2006 defines, include_dirs, ldflags, lib_dirs, libs, |
1988 precompiled_header, precompiled_source | 2007 precompiled_header, precompiled_source |
1989 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 2008 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
1990 Dependent configs: all_dependent_configs, public_configs | 2009 Dependent configs: all_dependent_configs, public_configs |
1991 General: check_includes, configs, data, inputs, output_name, | 2010 General: check_includes, configs, data, inputs, output_name, |
1992 output_extension, public, sources, testonly, visibility | 2011 output_extension, public, sources, testonly, visibility |
1993 | 2012 |
1994 | 2013 |
1995 ``` | 2014 ``` |
1996 ## **source_set**: Declare a source set target. | 2015 ## **source_set**: Declare a source set target. |
1997 | 2016 |
(...skipping 20 matching lines...) Expand all Loading... |
2018 final shared library and not from the intermediate targets." There is | 2037 final shared library and not from the intermediate targets." There is |
2019 no way to express this concept when linking multiple static libraries | 2038 no way to express this concept when linking multiple static libraries |
2020 into a shared library. | 2039 into a shared library. |
2021 | 2040 |
2022 ``` | 2041 ``` |
2023 | 2042 |
2024 ### **Variables** | 2043 ### **Variables** |
2025 | 2044 |
2026 ``` | 2045 ``` |
2027 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 2046 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
2028 defines, include_dirs, ldflags, lib_dirs, libs | 2047 defines, include_dirs, ldflags, lib_dirs, libs, |
2029 precompiled_header, precompiled_source | 2048 precompiled_header, precompiled_source |
2030 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 2049 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
2031 Dependent configs: all_dependent_configs, public_configs | 2050 Dependent configs: all_dependent_configs, public_configs |
2032 General: check_includes, configs, data, inputs, output_name, | 2051 General: check_includes, configs, data, inputs, output_name, |
2033 output_extension, public, sources, testonly, visibility | 2052 output_extension, public, sources, testonly, visibility |
2034 | 2053 |
2035 | 2054 |
2036 ``` | 2055 ``` |
2037 ## **static_library**: Declare a static library target. | 2056 ## **static_library**: Declare a static library target. |
2038 | 2057 |
2039 ``` | 2058 ``` |
2040 Make a ".a" / ".lib" file. | 2059 Make a ".a" / ".lib" file. |
2041 | 2060 |
2042 If you only need the static library for intermediate results in the | 2061 If you only need the static library for intermediate results in the |
2043 build, you should consider a source_set instead since it will skip | 2062 build, you should consider a source_set instead since it will skip |
2044 the (potentially slow) step of creating the intermediate library file. | 2063 the (potentially slow) step of creating the intermediate library file. |
2045 | 2064 |
2046 ``` | 2065 ``` |
2047 | 2066 |
2048 ### **Variables** | 2067 ### **Variables** |
2049 | 2068 |
2050 ``` | 2069 ``` |
2051 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, | 2070 Flags: cflags, cflags_c, cflags_cc, cflags_objc, cflags_objcc, |
2052 defines, include_dirs, ldflags, lib_dirs, libs | 2071 defines, include_dirs, ldflags, lib_dirs, libs, |
2053 precompiled_header, precompiled_source | 2072 precompiled_header, precompiled_source |
2054 Deps: data_deps, deps, forward_dependent_configs_from, public_deps | 2073 Deps: data_deps, deps, forward_dependent_configs_from, public_deps |
2055 Dependent configs: all_dependent_configs, public_configs | 2074 Dependent configs: all_dependent_configs, public_configs |
2056 General: check_includes, configs, data, inputs, output_name, | 2075 General: check_includes, configs, data, inputs, output_name, |
2057 output_extension, public, sources, testonly, visibility | 2076 output_extension, public, sources, testonly, visibility |
2058 | 2077 |
2059 | 2078 |
2060 ``` | 2079 ``` |
2061 ## **target**: Declare an target with the given programmatic type. | 2080 ## **target**: Declare an target with the given programmatic type. |
2062 | 2081 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2406 | 2425 |
2407 This is typically used to prepend "lib" to libraries on | 2426 This is typically used to prepend "lib" to libraries on |
2408 Posix systems: | 2427 Posix systems: |
2409 output_prefix = "lib" | 2428 output_prefix = "lib" |
2410 | 2429 |
2411 precompiled_header_type [string] | 2430 precompiled_header_type [string] |
2412 Valid for: "cc", "cxx", "objc", "objcxx" | 2431 Valid for: "cc", "cxx", "objc", "objcxx" |
2413 | 2432 |
2414 Type of precompiled headers. If undefined or the empty string, | 2433 Type of precompiled headers. If undefined or the empty string, |
2415 precompiled headers will not be used for this tool. Otherwise | 2434 precompiled headers will not be used for this tool. Otherwise |
2416 use "msvc" which is the only currently supported value. | 2435 use "gcc" or "msvc". |
2417 | 2436 |
2418 For precompiled headers to be used for a given target, the | 2437 For precompiled headers to be used for a given target, the |
2419 target (or a config applied to it) must also specify a | 2438 target (or a config applied to it) must also specify a |
2420 "precompiled_header" and, for "msvc"-style headers, a | 2439 "precompiled_header" and, for "msvc"-style headers, a |
2421 "precompiled_source" value. | 2440 "precompiled_source" value. If the type is "gcc", then both |
2422 | 2441 "precompiled_header" and "precompiled_source" must resolve |
| 2442 to the same file, despite the different formats required for each. |
2423 See "gn help precompiled_header" for more. | 2443 See "gn help precompiled_header" for more. |
2424 | 2444 |
2425 restat [boolean] | 2445 restat [boolean] |
2426 Valid for: all tools (optional, defaults to false) | 2446 Valid for: all tools (optional, defaults to false) |
2427 | 2447 |
2428 Requests that Ninja check the file timestamp after this tool has | 2448 Requests that Ninja check the file timestamp after this tool has |
2429 run to determine if anything changed. Set this if your tool has | 2449 run to determine if anything changed. Set this if your tool has |
2430 the ability to skip writing output if the output file has not | 2450 the ability to skip writing output if the output file has not |
2431 changed. | 2451 changed. |
2432 | 2452 |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3118 dependencies have been resolved. Therefore, a target will not see | 3138 dependencies have been resolved. Therefore, a target will not see |
3119 these force-added configs in their "configs" variable while the | 3139 these force-added configs in their "configs" variable while the |
3120 script is running, and then can not be removed. As a result, this | 3140 script is running, and then can not be removed. As a result, this |
3121 capability should generally only be used to add defines and include | 3141 capability should generally only be used to add defines and include |
3122 directories necessary to compile a target's headers. | 3142 directories necessary to compile a target's headers. |
3123 | 3143 |
3124 See also "public_configs". | 3144 See also "public_configs". |
3125 | 3145 |
3126 ``` | 3146 ``` |
3127 | 3147 |
3128 ### **Ordering of flags and values**: | 3148 ### **Ordering of flags and values** |
3129 | 3149 |
3130 ``` | 3150 ``` |
3131 1. Those set on the current target (not in a config). | 3151 1. Those set on the current target (not in a config). |
3132 2. Those set on the "configs" on the target in order that the | 3152 2. Those set on the "configs" on the target in order that the |
3133 configs appear in the list. | 3153 configs appear in the list. |
3134 3. Those set on the "all_dependent_configs" on the target in order | 3154 3. Those set on the "all_dependent_configs" on the target in order |
3135 that the configs appear in the list. | 3155 that the configs appear in the list. |
3136 4. Those set on the "public_configs" on the target in order that | 3156 4. Those set on the "public_configs" on the target in order that |
3137 those configs appear in the list. | 3157 those configs appear in the list. |
3138 5. all_dependent_configs pulled from dependencies, in the order of | 3158 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3202 | 3222 |
3203 "cflags" are passed to all invocations of the C, C++, Objective C, | 3223 "cflags" are passed to all invocations of the C, C++, Objective C, |
3204 and Objective C++ compilers. | 3224 and Objective C++ compilers. |
3205 | 3225 |
3206 To target one of these variants individually, use "cflags_c", | 3226 To target one of these variants individually, use "cflags_c", |
3207 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. | 3227 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. |
3208 These variant-specific versions will be appended to the "cflags". | 3228 These variant-specific versions will be appended to the "cflags". |
3209 | 3229 |
3210 ``` | 3230 ``` |
3211 | 3231 |
3212 ### **Ordering of flags and values**: | 3232 ### **Ordering of flags and values** |
3213 | 3233 |
3214 ``` | 3234 ``` |
3215 1. Those set on the current target (not in a config). | 3235 1. Those set on the current target (not in a config). |
3216 2. Those set on the "configs" on the target in order that the | 3236 2. Those set on the "configs" on the target in order that the |
3217 configs appear in the list. | 3237 configs appear in the list. |
3218 3. Those set on the "all_dependent_configs" on the target in order | 3238 3. Those set on the "all_dependent_configs" on the target in order |
3219 that the configs appear in the list. | 3239 that the configs appear in the list. |
3220 4. Those set on the "public_configs" on the target in order that | 3240 4. Those set on the "public_configs" on the target in order that |
3221 those configs appear in the list. | 3241 those configs appear in the list. |
3222 5. all_dependent_configs pulled from dependencies, in the order of | 3242 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 12 matching lines...) Expand all Loading... |
3235 | 3255 |
3236 "cflags" are passed to all invocations of the C, C++, Objective C, | 3256 "cflags" are passed to all invocations of the C, C++, Objective C, |
3237 and Objective C++ compilers. | 3257 and Objective C++ compilers. |
3238 | 3258 |
3239 To target one of these variants individually, use "cflags_c", | 3259 To target one of these variants individually, use "cflags_c", |
3240 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. | 3260 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. |
3241 These variant-specific versions will be appended to the "cflags". | 3261 These variant-specific versions will be appended to the "cflags". |
3242 | 3262 |
3243 ``` | 3263 ``` |
3244 | 3264 |
3245 ### **Ordering of flags and values**: | 3265 ### **Ordering of flags and values** |
3246 | 3266 |
3247 ``` | 3267 ``` |
3248 1. Those set on the current target (not in a config). | 3268 1. Those set on the current target (not in a config). |
3249 2. Those set on the "configs" on the target in order that the | 3269 2. Those set on the "configs" on the target in order that the |
3250 configs appear in the list. | 3270 configs appear in the list. |
3251 3. Those set on the "all_dependent_configs" on the target in order | 3271 3. Those set on the "all_dependent_configs" on the target in order |
3252 that the configs appear in the list. | 3272 that the configs appear in the list. |
3253 4. Those set on the "public_configs" on the target in order that | 3273 4. Those set on the "public_configs" on the target in order that |
3254 those configs appear in the list. | 3274 those configs appear in the list. |
3255 5. all_dependent_configs pulled from dependencies, in the order of | 3275 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 12 matching lines...) Expand all Loading... |
3268 | 3288 |
3269 "cflags" are passed to all invocations of the C, C++, Objective C, | 3289 "cflags" are passed to all invocations of the C, C++, Objective C, |
3270 and Objective C++ compilers. | 3290 and Objective C++ compilers. |
3271 | 3291 |
3272 To target one of these variants individually, use "cflags_c", | 3292 To target one of these variants individually, use "cflags_c", |
3273 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. | 3293 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. |
3274 These variant-specific versions will be appended to the "cflags". | 3294 These variant-specific versions will be appended to the "cflags". |
3275 | 3295 |
3276 ``` | 3296 ``` |
3277 | 3297 |
3278 ### **Ordering of flags and values**: | 3298 ### **Ordering of flags and values** |
3279 | 3299 |
3280 ``` | 3300 ``` |
3281 1. Those set on the current target (not in a config). | 3301 1. Those set on the current target (not in a config). |
3282 2. Those set on the "configs" on the target in order that the | 3302 2. Those set on the "configs" on the target in order that the |
3283 configs appear in the list. | 3303 configs appear in the list. |
3284 3. Those set on the "all_dependent_configs" on the target in order | 3304 3. Those set on the "all_dependent_configs" on the target in order |
3285 that the configs appear in the list. | 3305 that the configs appear in the list. |
3286 4. Those set on the "public_configs" on the target in order that | 3306 4. Those set on the "public_configs" on the target in order that |
3287 those configs appear in the list. | 3307 those configs appear in the list. |
3288 5. all_dependent_configs pulled from dependencies, in the order of | 3308 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 12 matching lines...) Expand all Loading... |
3301 | 3321 |
3302 "cflags" are passed to all invocations of the C, C++, Objective C, | 3322 "cflags" are passed to all invocations of the C, C++, Objective C, |
3303 and Objective C++ compilers. | 3323 and Objective C++ compilers. |
3304 | 3324 |
3305 To target one of these variants individually, use "cflags_c", | 3325 To target one of these variants individually, use "cflags_c", |
3306 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. | 3326 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. |
3307 These variant-specific versions will be appended to the "cflags". | 3327 These variant-specific versions will be appended to the "cflags". |
3308 | 3328 |
3309 ``` | 3329 ``` |
3310 | 3330 |
3311 ### **Ordering of flags and values**: | 3331 ### **Ordering of flags and values** |
3312 | 3332 |
3313 ``` | 3333 ``` |
3314 1. Those set on the current target (not in a config). | 3334 1. Those set on the current target (not in a config). |
3315 2. Those set on the "configs" on the target in order that the | 3335 2. Those set on the "configs" on the target in order that the |
3316 configs appear in the list. | 3336 configs appear in the list. |
3317 3. Those set on the "all_dependent_configs" on the target in order | 3337 3. Those set on the "all_dependent_configs" on the target in order |
3318 that the configs appear in the list. | 3338 that the configs appear in the list. |
3319 4. Those set on the "public_configs" on the target in order that | 3339 4. Those set on the "public_configs" on the target in order that |
3320 those configs appear in the list. | 3340 those configs appear in the list. |
3321 5. all_dependent_configs pulled from dependencies, in the order of | 3341 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 12 matching lines...) Expand all Loading... |
3334 | 3354 |
3335 "cflags" are passed to all invocations of the C, C++, Objective C, | 3355 "cflags" are passed to all invocations of the C, C++, Objective C, |
3336 and Objective C++ compilers. | 3356 and Objective C++ compilers. |
3337 | 3357 |
3338 To target one of these variants individually, use "cflags_c", | 3358 To target one of these variants individually, use "cflags_c", |
3339 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. | 3359 "cflags_cc", "cflags_objc", and "cflags_objcc", respectively. |
3340 These variant-specific versions will be appended to the "cflags". | 3360 These variant-specific versions will be appended to the "cflags". |
3341 | 3361 |
3342 ``` | 3362 ``` |
3343 | 3363 |
3344 ### **Ordering of flags and values**: | 3364 ### **Ordering of flags and values** |
3345 | 3365 |
3346 ``` | 3366 ``` |
3347 1. Those set on the current target (not in a config). | 3367 1. Those set on the current target (not in a config). |
3348 2. Those set on the "configs" on the target in order that the | 3368 2. Those set on the "configs" on the target in order that the |
3349 configs appear in the list. | 3369 configs appear in the list. |
3350 3. Those set on the "all_dependent_configs" on the target in order | 3370 3. Those set on the "all_dependent_configs" on the target in order |
3351 that the configs appear in the list. | 3371 that the configs appear in the list. |
3352 4. Those set on the "public_configs" on the target in order that | 3372 4. Those set on the "public_configs" on the target in order that |
3353 those configs appear in the list. | 3373 those configs appear in the list. |
3354 5. all_dependent_configs pulled from dependencies, in the order of | 3374 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3431 ### **Example** | 3451 ### **Example** |
3432 | 3452 |
3433 ``` | 3453 ``` |
3434 static_library("foo") { | 3454 static_library("foo") { |
3435 complete_static_lib = true | 3455 complete_static_lib = true |
3436 deps = [ "bar" ] | 3456 deps = [ "bar" ] |
3437 } | 3457 } |
3438 | 3458 |
3439 | 3459 |
3440 ``` | 3460 ``` |
3441 ## **configs**: Configs applying to this target. | 3461 ## **configs**: Configs applying to this target or config. |
3442 | 3462 |
3443 ``` | 3463 ``` |
3444 A list of config labels. | 3464 A list of config labels. |
3445 | 3465 |
3446 The include_dirs, defines, etc. in each config are appended in the | 3466 ``` |
3447 order they appear to the compile command for each file in the target. | 3467 |
3448 They will appear after the include_dirs, defines, etc. that the target | 3468 ### **Configs on a target** |
3449 sets directly. | 3469 |
| 3470 ``` |
| 3471 When used on a target, the include_dirs, defines, etc. in each config |
| 3472 are appended in the order they appear to the compile command for each |
| 3473 file in the target. They will appear after the include_dirs, defines, |
| 3474 etc. that the target sets directly. |
| 3475 |
| 3476 Since configs apply after the values set on a target, directly setting |
| 3477 a compiler flag will prepend it to the command line. If you want to |
| 3478 append a flag instead, you can put that flag in a one-off config and |
| 3479 append that config to the target's configs list. |
3450 | 3480 |
3451 The build configuration script will generally set up the default | 3481 The build configuration script will generally set up the default |
3452 configs applying to a given target type (see "set_defaults"). | 3482 configs applying to a given target type (see "set_defaults"). |
3453 When a target is being defined, it can add to or remove from this | 3483 When a target is being defined, it can add to or remove from this |
3454 list. | 3484 list. |
3455 | 3485 |
3456 ``` | 3486 ``` |
3457 | 3487 |
3458 ### **Ordering of flags and values**: | 3488 ### **Configs on a config** |
| 3489 |
| 3490 ``` |
| 3491 It is possible to create composite configs by specifying configs on a |
| 3492 config. One might do this to forward values, or to factor out blocks |
| 3493 of settings from very large configs into more manageable named chunks. |
| 3494 |
| 3495 In this case, the composite config is expanded to be the concatenation |
| 3496 of its own values, and in order, the values from its sub-configs |
| 3497 *before* anything else happens. This has some ramifications: |
| 3498 |
| 3499 - A target has no visibility into a config's sub-configs. Target |
| 3500 code only sees the name of the composite config. It can't remove |
| 3501 sub-configs or opt in to only parts of it. The composite config may |
| 3502 not even be defined before the target is. |
| 3503 |
| 3504 - You can get duplication of values if a config is listed twice, say, |
| 3505 on a target and in a sub-config that also applies. In other cases, |
| 3506 the configs applying to a target are de-duped. It's expected that |
| 3507 if a config is listed as a sub-config that it is only used in that |
| 3508 context. (Note that it's possible to fix this and de-dupe, but it's |
| 3509 not normally relevant and complicates the implementation.) |
| 3510 |
| 3511 ``` |
| 3512 |
| 3513 ### **Ordering of flags and values** |
3459 | 3514 |
3460 ``` | 3515 ``` |
3461 1. Those set on the current target (not in a config). | 3516 1. Those set on the current target (not in a config). |
3462 2. Those set on the "configs" on the target in order that the | 3517 2. Those set on the "configs" on the target in order that the |
3463 configs appear in the list. | 3518 configs appear in the list. |
3464 3. Those set on the "all_dependent_configs" on the target in order | 3519 3. Those set on the "all_dependent_configs" on the target in order |
3465 that the configs appear in the list. | 3520 that the configs appear in the list. |
3466 4. Those set on the "public_configs" on the target in order that | 3521 4. Those set on the "public_configs" on the target in order that |
3467 those configs appear in the list. | 3522 those configs appear in the list. |
3468 5. all_dependent_configs pulled from dependencies, in the order of | 3523 5. all_dependent_configs pulled from dependencies, in the order of |
3469 the "deps" list. This is done recursively. If a config appears | 3524 the "deps" list. This is done recursively. If a config appears |
3470 more than once, only the first occurance will be used. | 3525 more than once, only the first occurance will be used. |
3471 6. public_configs pulled from dependencies, in the order of the | 3526 6. public_configs pulled from dependencies, in the order of the |
3472 "deps" list. If a dependency is public, they will be applied | 3527 "deps" list. If a dependency is public, they will be applied |
3473 recursively. | 3528 recursively. |
3474 | 3529 |
3475 ``` | 3530 ``` |
3476 | 3531 |
3477 ### **Example**: | 3532 ### **Example** |
| 3533 |
3478 ``` | 3534 ``` |
3479 static_library("foo") { | 3535 # Configs on a target. |
3480 configs -= "//build:no_rtti" # Don't use the default RTTI config. | 3536 source_set("foo") { |
3481 configs += ":mysettings" # Add some of our own settings. | 3537 # Don't use the default RTTI config that BUILDCONFIG applied to us. |
| 3538 configs -= [ "//build:no_rtti" ] |
| 3539 |
| 3540 # Add some of our own settings. |
| 3541 configs += [ ":mysettings" ] |
| 3542 } |
| 3543 |
| 3544 # Create a default_optimization config that forwards to one of a set |
| 3545 # of more specialized configs depending on build flags. This pattern |
| 3546 # is useful because it allows a target to opt in to either a default |
| 3547 # set, or a more specific set, while avoid duplicating the settings in |
| 3548 # two places. |
| 3549 config("super_optimization") { |
| 3550 cflags = [ ... ] |
| 3551 } |
| 3552 config("default_optimization") { |
| 3553 if (optimize_everything) { |
| 3554 configs = [ ":super_optimization" ] |
| 3555 } else { |
| 3556 configs = [ ":no_optimization" ] |
| 3557 } |
3482 } | 3558 } |
3483 | 3559 |
3484 | 3560 |
3485 ``` | 3561 ``` |
3486 ## **data**: Runtime data file dependencies. | 3562 ## **data**: Runtime data file dependencies. |
3487 | 3563 |
3488 ``` | 3564 ``` |
3489 Lists files or directories required to run the given target. These are | 3565 Lists files or directories required to run the given target. These are |
3490 typically data files or directories of data files. The paths are | 3566 typically data files or directories of data files. The paths are |
3491 interpreted as being relative to the current build file. Since these | 3567 interpreted as being relative to the current build file. Since these |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3540 ## **defines**: C preprocessor defines. | 3616 ## **defines**: C preprocessor defines. |
3541 | 3617 |
3542 ``` | 3618 ``` |
3543 A list of strings | 3619 A list of strings |
3544 | 3620 |
3545 These strings will be passed to the C/C++ compiler as #defines. The | 3621 These strings will be passed to the C/C++ compiler as #defines. The |
3546 strings may or may not include an "=" to assign a value. | 3622 strings may or may not include an "=" to assign a value. |
3547 | 3623 |
3548 ``` | 3624 ``` |
3549 | 3625 |
3550 ### **Ordering of flags and values**: | 3626 ### **Ordering of flags and values** |
3551 | 3627 |
3552 ``` | 3628 ``` |
3553 1. Those set on the current target (not in a config). | 3629 1. Those set on the current target (not in a config). |
3554 2. Those set on the "configs" on the target in order that the | 3630 2. Those set on the "configs" on the target in order that the |
3555 configs appear in the list. | 3631 configs appear in the list. |
3556 3. Those set on the "all_dependent_configs" on the target in order | 3632 3. Those set on the "all_dependent_configs" on the target in order |
3557 that the configs appear in the list. | 3633 that the configs appear in the list. |
3558 4. Those set on the "public_configs" on the target in order that | 3634 4. Those set on the "public_configs" on the target in order that |
3559 those configs appear in the list. | 3635 those configs appear in the list. |
3560 5. all_dependent_configs pulled from dependencies, in the order of | 3636 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3604 } | 3680 } |
3605 | 3681 |
3606 | 3682 |
3607 ``` | 3683 ``` |
3608 ## **deps**: Private linked dependencies. | 3684 ## **deps**: Private linked dependencies. |
3609 | 3685 |
3610 ``` | 3686 ``` |
3611 A list of target labels. | 3687 A list of target labels. |
3612 | 3688 |
3613 Specifies private dependencies of a target. Shared and dynamic | 3689 Specifies private dependencies of a target. Shared and dynamic |
3614 libraries will be linked into the current target. Other target types | 3690 libraries will be linked into the current target. |
3615 that can't be linked (like actions and groups) listed in "deps" will | |
3616 be treated as "data_deps". Likewise, if the current target isn't | |
3617 linkable, then all deps will be treated as "data_deps". | |
3618 | 3691 |
3619 These dependencies are private in that it does not grant dependent | 3692 These dependencies are private in that it does not grant dependent |
3620 targets the ability to include headers from the dependency, and direct | 3693 targets the ability to include headers from the dependency, and direct |
3621 dependent configs are not forwarded. | 3694 dependent configs are not forwarded. |
3622 | 3695 |
3623 See also "public_deps" and "data_deps". | 3696 See also "public_deps" and "data_deps". |
3624 | 3697 |
3625 | 3698 |
3626 ``` | 3699 ``` |
3627 ## **forward_dependent_configs_from** | 3700 ## **forward_dependent_configs_from** |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3679 ## **include_dirs**: Additional include directories. | 3752 ## **include_dirs**: Additional include directories. |
3680 | 3753 |
3681 ``` | 3754 ``` |
3682 A list of source directories. | 3755 A list of source directories. |
3683 | 3756 |
3684 The directories in this list will be added to the include path for | 3757 The directories in this list will be added to the include path for |
3685 the files in the affected target. | 3758 the files in the affected target. |
3686 | 3759 |
3687 ``` | 3760 ``` |
3688 | 3761 |
3689 ### **Ordering of flags and values**: | 3762 ### **Ordering of flags and values** |
3690 | 3763 |
3691 ``` | 3764 ``` |
3692 1. Those set on the current target (not in a config). | 3765 1. Those set on the current target (not in a config). |
3693 2. Those set on the "configs" on the target in order that the | 3766 2. Those set on the "configs" on the target in order that the |
3694 configs appear in the list. | 3767 configs appear in the list. |
3695 3. Those set on the "all_dependent_configs" on the target in order | 3768 3. Those set on the "all_dependent_configs" on the target in order |
3696 that the configs appear in the list. | 3769 that the configs appear in the list. |
3697 4. Those set on the "public_configs" on the target in order that | 3770 4. Those set on the "public_configs" on the target in order that |
3698 those configs appear in the list. | 3771 those configs appear in the list. |
3699 5. all_dependent_configs pulled from dependencies, in the order of | 3772 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3773 specify various linking options. Most targets will not need these and | 3846 specify various linking options. Most targets will not need these and |
3774 will use "libs" and "lib_dirs" instead. | 3847 will use "libs" and "lib_dirs" instead. |
3775 | 3848 |
3776 ldflags are NOT pushed to dependents, so applying ldflags to source | 3849 ldflags are NOT pushed to dependents, so applying ldflags to source |
3777 sets or static libraries will be a no-op. If you want to apply ldflags | 3850 sets or static libraries will be a no-op. If you want to apply ldflags |
3778 to dependent targets, put them in a config and set it in the | 3851 to dependent targets, put them in a config and set it in the |
3779 all_dependent_configs or public_configs. | 3852 all_dependent_configs or public_configs. |
3780 | 3853 |
3781 ``` | 3854 ``` |
3782 | 3855 |
3783 ### **Ordering of flags and values**: | 3856 ### **Ordering of flags and values** |
3784 | 3857 |
3785 ``` | 3858 ``` |
3786 1. Those set on the current target (not in a config). | 3859 1. Those set on the current target (not in a config). |
3787 2. Those set on the "configs" on the target in order that the | 3860 2. Those set on the "configs" on the target in order that the |
3788 configs appear in the list. | 3861 configs appear in the list. |
3789 3. Those set on the "all_dependent_configs" on the target in order | 3862 3. Those set on the "all_dependent_configs" on the target in order |
3790 that the configs appear in the list. | 3863 that the configs appear in the list. |
3791 4. Those set on the "public_configs" on the target in order that | 3864 4. Those set on the "public_configs" on the target in order that |
3792 those configs appear in the list. | 3865 those configs appear in the list. |
3793 5. all_dependent_configs pulled from dependencies, in the order of | 3866 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 15 matching lines...) Expand all Loading... |
3809 will be treated as being relative to the current build file. | 3882 will be treated as being relative to the current build file. |
3810 | 3883 |
3811 libs and lib_dirs work differently than other flags in two respects. | 3884 libs and lib_dirs work differently than other flags in two respects. |
3812 First, then are inherited across static library boundaries until a | 3885 First, then are inherited across static library boundaries until a |
3813 shared library or executable target is reached. Second, they are | 3886 shared library or executable target is reached. Second, they are |
3814 uniquified so each one is only passed once (the first instance of it | 3887 uniquified so each one is only passed once (the first instance of it |
3815 will be the one used). | 3888 will be the one used). |
3816 | 3889 |
3817 ``` | 3890 ``` |
3818 | 3891 |
3819 ### **Ordering of flags and values**: | 3892 ### **Ordering of flags and values** |
3820 | 3893 |
3821 ``` | 3894 ``` |
3822 1. Those set on the current target (not in a config). | 3895 1. Those set on the current target (not in a config). |
3823 2. Those set on the "configs" on the target in order that the | 3896 2. Those set on the "configs" on the target in order that the |
3824 configs appear in the list. | 3897 configs appear in the list. |
3825 3. Those set on the "all_dependent_configs" on the target in order | 3898 3. Those set on the "all_dependent_configs" on the target in order |
3826 that the configs appear in the list. | 3899 that the configs appear in the list. |
3827 4. Those set on the "public_configs" on the target in order that | 3900 4. Those set on the "public_configs" on the target in order that |
3828 those configs appear in the list. | 3901 those configs appear in the list. |
3829 5. all_dependent_configs pulled from dependencies, in the order of | 3902 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3862 the lib_prefix, and the ".framework" suffix will be trimmed. | 3935 the lib_prefix, and the ".framework" suffix will be trimmed. |
3863 | 3936 |
3864 libs and lib_dirs work differently than other flags in two respects. | 3937 libs and lib_dirs work differently than other flags in two respects. |
3865 First, then are inherited across static library boundaries until a | 3938 First, then are inherited across static library boundaries until a |
3866 shared library or executable target is reached. Second, they are | 3939 shared library or executable target is reached. Second, they are |
3867 uniquified so each one is only passed once (the first instance of it | 3940 uniquified so each one is only passed once (the first instance of it |
3868 will be the one used). | 3941 will be the one used). |
3869 | 3942 |
3870 ``` | 3943 ``` |
3871 | 3944 |
3872 ### **Ordering of flags and values**: | 3945 ### **Ordering of flags and values** |
3873 | 3946 |
3874 ``` | 3947 ``` |
3875 1. Those set on the current target (not in a config). | 3948 1. Those set on the current target (not in a config). |
3876 2. Those set on the "configs" on the target in order that the | 3949 2. Those set on the "configs" on the target in order that the |
3877 configs appear in the list. | 3950 configs appear in the list. |
3878 3. Those set on the "all_dependent_configs" on the target in order | 3951 3. Those set on the "all_dependent_configs" on the target in order |
3879 that the configs appear in the list. | 3952 that the configs appear in the list. |
3880 4. Those set on the "public_configs" on the target in order that | 3953 4. Those set on the "public_configs" on the target in order that |
3881 those configs appear in the list. | 3954 those configs appear in the list. |
3882 5. all_dependent_configs pulled from dependencies, in the order of | 3955 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4067 dependencies have been resolved. Therefore, a target will not see | 4140 dependencies have been resolved. Therefore, a target will not see |
4068 these force-added configs in their "configs" variable while the | 4141 these force-added configs in their "configs" variable while the |
4069 script is running, and then can not be removed. As a result, this | 4142 script is running, and then can not be removed. As a result, this |
4070 capability should generally only be used to add defines and include | 4143 capability should generally only be used to add defines and include |
4071 directories necessary to compile a target's headers. | 4144 directories necessary to compile a target's headers. |
4072 | 4145 |
4073 See also "all_dependent_configs". | 4146 See also "all_dependent_configs". |
4074 | 4147 |
4075 ``` | 4148 ``` |
4076 | 4149 |
4077 ### **Ordering of flags and values**: | 4150 ### **Ordering of flags and values** |
4078 | 4151 |
4079 ``` | 4152 ``` |
4080 1. Those set on the current target (not in a config). | 4153 1. Those set on the current target (not in a config). |
4081 2. Those set on the "configs" on the target in order that the | 4154 2. Those set on the "configs" on the target in order that the |
4082 configs appear in the list. | 4155 configs appear in the list. |
4083 3. Those set on the "all_dependent_configs" on the target in order | 4156 3. Those set on the "all_dependent_configs" on the target in order |
4084 that the configs appear in the list. | 4157 that the configs appear in the list. |
4085 4. Those set on the "public_configs" on the target in order that | 4158 4. Those set on the "public_configs" on the target in order that |
4086 those configs appear in the list. | 4159 those configs appear in the list. |
4087 5. all_dependent_configs pulled from dependencies, in the order of | 4160 5. all_dependent_configs pulled from dependencies, in the order of |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4837 ``` | 4910 ``` |
4838 | 4911 |
4839 ** \--args**: Specifies build arguments overrides. | 4912 ** \--args**: Specifies build arguments overrides. |
4840 ** \--color**: Force colored output. | 4913 ** \--color**: Force colored output. |
4841 ** \--dotfile**: Override the name of the ".gn" file. | 4914 ** \--dotfile**: Override the name of the ".gn" file. |
4842 ** \--markdown**: write the output in the Markdown format. | 4915 ** \--markdown**: write the output in the Markdown format. |
4843 ** \--nocolor**: Force non-colored output. | 4916 ** \--nocolor**: Force non-colored output. |
4844 ** -q**: Quiet mode. Don't print output on success. | 4917 ** -q**: Quiet mode. Don't print output on success. |
4845 ** \--root**: Explicitly specify source root. | 4918 ** \--root**: Explicitly specify source root. |
4846 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. | 4919 ** \--runtime-deps-list-file**: Save runtime dependencies for targets in file. |
| 4920 ** \--threads**: Specify number of worker threads. |
4847 ** \--time**: Outputs a summary of how long everything took. | 4921 ** \--time**: Outputs a summary of how long everything took. |
4848 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. | 4922 ** \--tracelog**: Writes a Chrome-compatible trace log to the given file. |
4849 ** -v**: Verbose logging. | 4923 ** -v**: Verbose logging. |
4850 ** \--version**: Prints the GN version number and exits. | 4924 ** \--version**: Prints the GN version number and exits. |
4851 | 4925 |
4852 ``` | 4926 ``` |
OLD | NEW |