OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/variables.h" | 5 #include "tools/gn/variables.h" |
6 | 6 |
7 namespace variables { | 7 namespace variables { |
8 | 8 |
9 // Built-in variables ---------------------------------------------------------- | 9 // Built-in variables ---------------------------------------------------------- |
10 | 10 |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1444 const char kPrecompiledHeader[] = "precompiled_header"; | 1444 const char kPrecompiledHeader[] = "precompiled_header"; |
1445 const char kPrecompiledHeader_HelpShort[] = | 1445 const char kPrecompiledHeader_HelpShort[] = |
1446 "precompiled_header: [string] Header file to precompile."; | 1446 "precompiled_header: [string] Header file to precompile."; |
1447 const char kPrecompiledHeader_Help[] = | 1447 const char kPrecompiledHeader_Help[] = |
1448 R"(precompiled_header: [string] Header file to precompile. | 1448 R"(precompiled_header: [string] Header file to precompile. |
1449 | 1449 |
1450 Precompiled headers will be used when a target specifies this value, or a | 1450 Precompiled headers will be used when a target specifies this value, or a |
1451 config applying to this target specifies this value. In addition, the tool | 1451 config applying to this target specifies this value. In addition, the tool |
1452 corresponding to the source files must also specify precompiled headers (see | 1452 corresponding to the source files must also specify precompiled headers (see |
1453 "gn help tool"). The tool will also specify what type of precompiled headers | 1453 "gn help tool"). The tool will also specify what type of precompiled headers |
1454 to use. | 1454 to use, by setting precompiled_header_type to either "gcc" or "msvc". |
1455 | 1455 |
1456 The precompiled header/source variables can be specified on a target or a | 1456 The precompiled header/source variables can be specified on a target or a |
1457 config, but must be the same for all configs applying to a given target since | 1457 config, but must be the same for all configs applying to a given target since |
1458 a target can only have one precompiled header. | 1458 a target can only have one precompiled header. |
1459 | 1459 |
1460 If you use both C and C++ sources, the precompiled header and source file | |
1461 will be compiled once per language. You will want to make sure to wrap C++ | |
1462 includes in __cplusplus #ifdefs so the file will compile in C mode. | |
1463 | |
1464 GCC precompiled headers | |
1465 | |
1466 When using GCC-style precompiled headers, "precompiled_source" contains the | |
1467 path of a .h file that is precompiled and then included by all source files | |
1468 in targets that set "precompiled_source". | |
1469 | |
1470 The value of "precompiled_header" is not used with GCC-style precompiled | |
1471 headers. | |
Nico
2017/03/03 20:24:34
Fairly inconsistent with how MSVC-stype PCH works
| |
1472 | |
1460 MSVC precompiled headers | 1473 MSVC precompiled headers |
1461 | 1474 |
1462 When using MSVC-style precompiled headers, the "precompiled_header" value is | 1475 When using MSVC-style precompiled headers, the "precompiled_header" value is |
1463 a string corresponding to the header. This is NOT a path to a file that GN | 1476 a string corresponding to the header. This is NOT a path to a file that GN |
1464 recognises, but rather the exact string that appears in quotes after an | 1477 recognises, but rather the exact string that appears in quotes after |
1465 #include line in source code. The compiler will match this string against | 1478 an #include line in source code. The compiler will match this string against |
Nico
2017/03/03 20:24:34
The motivation behind this CL was that the #includ
| |
1466 includes or forced includes (/FI). | 1479 includes or forced includes (/FI). |
1467 | 1480 |
1468 MSVC also requires a source file to compile the header with. This must be | 1481 MSVC also requires a source file to compile the header with. This must be |
1469 specified by the "precompiled_source" value. In contrast to the header value, | 1482 specified by the "precompiled_source" value. In contrast to the header value, |
1470 this IS a GN-style file name, and tells GN which source file to compile to | 1483 this IS a GN-style file name, and tells GN which source file to compile to |
1471 make the .pch file used for subsequent compiles. | 1484 make the .pch file used for subsequent compiles. |
1472 | 1485 |
1473 If you use both C and C++ sources, the precompiled header and source file | |
1474 will be compiled using both tools. You will want to make sure to wrap C++ | |
1475 includes in __cplusplus #ifdefs so the file will compile in C mode. | |
1476 | |
1477 For example, if the toolchain specifies MSVC headers: | 1486 For example, if the toolchain specifies MSVC headers: |
1478 | 1487 |
1479 toolchain("vc_x64") { | 1488 toolchain("vc_x64") { |
1480 ... | 1489 ... |
1481 tool("cxx") { | 1490 tool("cxx") { |
1482 precompiled_header_type = "msvc" | 1491 precompiled_header_type = "msvc" |
1483 ... | 1492 ... |
1484 | 1493 |
1485 You might make a config like this: | 1494 You might make a config like this: |
1486 | 1495 |
1487 config("use_precompiled_headers") { | 1496 config("use_precompiled_headers") { |
1488 precompiled_header = "build/precompile.h" | 1497 precompiled_header = "build/precompile.h" |
1489 precompiled_source = "//build/precompile.cc" | 1498 precompiled_source = "//build/precompile.cc" |
1490 | 1499 |
1491 # Either your source files should #include "build/precompile.h" | 1500 # Either your source files should #include "build/precompile.h" |
1492 # first, or you can do this to force-include the header. | 1501 # first, or you can do this to force-include the header. |
1493 cflags = [ "/FI$precompiled_header" ] | 1502 cflags = [ "/FI$precompiled_header" ] |
1494 } | 1503 } |
1495 | 1504 |
1496 And then define a target that uses the config: | 1505 And then define a target that uses the config: |
1497 | 1506 |
1498 executable("doom_melon") { | 1507 executable("doom_melon") { |
1499 configs += [ ":use_precompiled_headers" ] | 1508 configs += [ ":use_precompiled_headers" ] |
1500 ... | 1509 ... |
1501 )"; | 1510 )"; |
1502 | 1511 |
1512 const char kPrecompiledHeaderType[] = "precompiled_header_type"; | |
1513 const char kPrecompiledHeaderType_HelpShort[] = | |
1514 "precompiled_header_type: [string] \"gcc\" or \"msvc\"."; | |
1515 const char kPrecompiledHeaderType_Help[] = | |
1516 R"(precompiled_header_type: [string] "gcc" or "msvc". | |
1517 | |
1518 See "gn help precompiled_header". | |
1519 )"; | |
1520 | |
1503 const char kPrecompiledSource[] = "precompiled_source"; | 1521 const char kPrecompiledSource[] = "precompiled_source"; |
1504 const char kPrecompiledSource_HelpShort[] = | 1522 const char kPrecompiledSource_HelpShort[] = |
1505 "precompiled_source: [file name] Source file to precompile."; | 1523 "precompiled_source: [file name] Source file to precompile."; |
1506 const char kPrecompiledSource_Help[] = | 1524 const char kPrecompiledSource_Help[] = |
1507 R"(precompiled_source: [file name] Source file to precompile. | 1525 R"(precompiled_source: [file name] Source file to precompile. |
1508 | 1526 |
1509 The source file that goes along with the precompiled_header when using | 1527 The source file that goes along with the precompiled_header when using |
1510 "msvc"-style precompiled headers. It will be implicitly added to the sources | 1528 "msvc"-style precompiled headers. It will be implicitly added to the sources |
1511 of the target. See "gn help precompiled_header". | 1529 of the target. See "gn help precompiled_header". |
1512 )"; | 1530 )"; |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1897 INSERT_VARIABLE(Inputs) | 1915 INSERT_VARIABLE(Inputs) |
1898 INSERT_VARIABLE(Ldflags) | 1916 INSERT_VARIABLE(Ldflags) |
1899 INSERT_VARIABLE(Libs) | 1917 INSERT_VARIABLE(Libs) |
1900 INSERT_VARIABLE(LibDirs) | 1918 INSERT_VARIABLE(LibDirs) |
1901 INSERT_VARIABLE(OutputDir) | 1919 INSERT_VARIABLE(OutputDir) |
1902 INSERT_VARIABLE(OutputExtension) | 1920 INSERT_VARIABLE(OutputExtension) |
1903 INSERT_VARIABLE(OutputName) | 1921 INSERT_VARIABLE(OutputName) |
1904 INSERT_VARIABLE(OutputPrefixOverride) | 1922 INSERT_VARIABLE(OutputPrefixOverride) |
1905 INSERT_VARIABLE(Outputs) | 1923 INSERT_VARIABLE(Outputs) |
1906 INSERT_VARIABLE(PrecompiledHeader) | 1924 INSERT_VARIABLE(PrecompiledHeader) |
1925 INSERT_VARIABLE(PrecompiledHeaderType) | |
1907 INSERT_VARIABLE(PrecompiledSource) | 1926 INSERT_VARIABLE(PrecompiledSource) |
1908 INSERT_VARIABLE(ProductType) | 1927 INSERT_VARIABLE(ProductType) |
1909 INSERT_VARIABLE(Public) | 1928 INSERT_VARIABLE(Public) |
1910 INSERT_VARIABLE(PublicConfigs) | 1929 INSERT_VARIABLE(PublicConfigs) |
1911 INSERT_VARIABLE(PublicDeps) | 1930 INSERT_VARIABLE(PublicDeps) |
1912 INSERT_VARIABLE(ResponseFileContents) | 1931 INSERT_VARIABLE(ResponseFileContents) |
1913 INSERT_VARIABLE(Script) | 1932 INSERT_VARIABLE(Script) |
1914 INSERT_VARIABLE(Sources) | 1933 INSERT_VARIABLE(Sources) |
1915 INSERT_VARIABLE(Testonly) | 1934 INSERT_VARIABLE(Testonly) |
1916 INSERT_VARIABLE(Visibility) | 1935 INSERT_VARIABLE(Visibility) |
1917 INSERT_VARIABLE(WriteRuntimeDeps) | 1936 INSERT_VARIABLE(WriteRuntimeDeps) |
1918 } | 1937 } |
1919 return info_map; | 1938 return info_map; |
1920 } | 1939 } |
1921 | 1940 |
1922 #undef INSERT_VARIABLE | 1941 #undef INSERT_VARIABLE |
1923 | 1942 |
1924 } // namespace variables | 1943 } // namespace variables |
OLD | NEW |