]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | # Copyright (c) 2005 Reece H. Dunn. |
2 | # Copyright 2006 Ilya Sokolov | |
3 | # | |
4 | # Use, modification and distribution is subject to the Boost Software | |
1e59de90 TL |
5 | # License Version 1.0. (See accompanying file LICENSE.txt or |
6 | # https://www.bfgroup.xyz/b2/LICENSE.txt) | |
7c673cae FG |
7 | |
8 | ##### Using Precompiled Headers (Quick Guide) ##### | |
9 | # | |
10 | # Make precompiled mypch.hpp: | |
11 | # | |
12 | # import pch ; | |
13 | # | |
14 | # cpp-pch mypch | |
15 | # : # sources | |
16 | # mypch.hpp | |
17 | # : # requiremnts | |
18 | # <toolset>msvc:<source>mypch.cpp | |
19 | # ; | |
20 | # | |
21 | # Add cpp-pch to sources: | |
22 | # | |
23 | # exe hello | |
24 | # : main.cpp hello.cpp mypch | |
25 | # ; | |
26 | ||
27 | import "class" : new ; | |
28 | import type ; | |
29 | import feature ; | |
30 | import generators ; | |
31 | ||
32 | type.register PCH : pch ; | |
33 | ||
34 | type.register C_PCH : : PCH ; | |
35 | type.register CPP_PCH : : PCH ; | |
36 | ||
37 | # Control precompiled header (PCH) generation. | |
38 | feature.feature pch : | |
39 | on | |
40 | off | |
41 | : propagated ; | |
42 | ||
43 | ||
44 | feature.feature pch-header : : free dependency ; | |
45 | feature.feature pch-file : : free dependency ; | |
46 | ||
47 | # Base PCH generator. The 'run' method has the logic to prevent this generator | |
48 | # from being run unless it's being used for a top-level PCH target. | |
49 | class pch-generator : generator | |
50 | { | |
51 | import property-set ; | |
52 | ||
53 | rule action-class ( ) | |
54 | { | |
55 | return compile-action ; | |
56 | } | |
57 | ||
58 | rule run ( project name ? : property-set : sources + ) | |
59 | { | |
60 | if ! $(name) | |
61 | { | |
62 | # Unless this generator is invoked as the top-most generator for a | |
63 | # main target, fail. This allows using 'H' type as input type for | |
f67539c2 | 64 | # this generator, while preventing B2 to try this generator |
7c673cae FG |
65 | # when not explicitly asked for. |
66 | # | |
67 | # One bad example is msvc, where pch generator produces both PCH | |
68 | # target and OBJ target, so if there's any header generated (like by | |
69 | # bison, or by msidl), we'd try to use pch generator to get OBJ from | |
70 | # that H, which is completely wrong. By restricting this generator | |
71 | # only to pch main target, such problem is solved. | |
72 | } | |
73 | else | |
74 | { | |
75 | local r = [ run-pch $(project) $(name) | |
76 | : [ $(property-set).add-raw <define>BOOST_BUILD_PCH_ENABLED ] | |
77 | : $(sources) ] ; | |
78 | return [ generators.add-usage-requirements $(r) | |
79 | : <define>BOOST_BUILD_PCH_ENABLED ] ; | |
80 | } | |
81 | } | |
82 | ||
83 | # This rule must be overridden by the derived classes. | |
84 | rule run-pch ( project name ? : property-set : sources + ) | |
85 | { | |
86 | } | |
87 | } | |
88 | ||
89 | ||
90 | # NOTE: requirements are empty, default pch generator can be applied when | |
91 | # pch=off. | |
92 | generators.register | |
93 | [ new dummy-generator pch.default-c-pch-generator : : C_PCH ] ; | |
94 | generators.register | |
95 | [ new dummy-generator pch.default-cpp-pch-generator : : CPP_PCH ] ; |