Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 112 lines (90 sloc) 3.606 kb
3315fba playing with pre-compiled headers
Eliot Horowitz authored
1 # $Id$
2 #
3 # SCons builder for gcc's precompiled headers
4 # Copyright (C) 2006 Tim Blechmann
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20
21 # $Revision$
22 # $LastChangedRevision$
23 # $LastChangedDate$
24 # $LastChangedBy$
25
26 import SCons.Action
27 import SCons.Builder
28 import SCons.Scanner.C
29 import SCons.Util
30 import SCons.Script
31
32 SCons.Script.EnsureSConsVersion(0,96,92)
33
34 GchAction = SCons.Action.Action('$GCHCOM', '$GCHCOMSTR')
35 GchShAction = SCons.Action.Action('$GCHSHCOM', '$GCHSHCOMSTR')
36
37 def gen_suffix(env, sources):
38 return sources[0].get_suffix() + env['GCHSUFFIX']
39
f550389 Mathias Stearn enable precompiled headers with g++
RedBeard0531 authored
40 def header_path(node):
41 path = node.path
42 return path[:-4] # strip final '.gch'
3315fba playing with pre-compiled headers
Eliot Horowitz authored
43
44 GchShBuilder = SCons.Builder.Builder(action = GchShAction,
45 source_scanner = SCons.Scanner.C.CScanner(),
46 suffix = gen_suffix)
47
48 GchBuilder = SCons.Builder.Builder(action = GchAction,
49 source_scanner = SCons.Scanner.C.CScanner(),
50 suffix = gen_suffix)
51
52 def static_pch_emitter(target,source,env):
53 SCons.Defaults.StaticObjectEmitter( target, source, env )
54
55 scanner = SCons.Scanner.C.CScanner()
56 path = scanner.path(env)
57 deps = scanner(source[0], env, path)
58
59 if env.has_key('Gch') and env['Gch']:
f550389 Mathias Stearn enable precompiled headers with g++
RedBeard0531 authored
60 if header_path(env['Gch']) in [x.path for x in deps]:
3315fba playing with pre-compiled headers
Eliot Horowitz authored
61 env.Depends(target, env['Gch'])
62
63 return (target, source)
64
65 def shared_pch_emitter(target,source,env):
66 SCons.Defaults.SharedObjectEmitter( target, source, env )
67
68 scanner = SCons.Scanner.C.CScanner()
69 path = scanner.path(env)
70 deps = scanner(source[0], env, path)
71
72 if env.has_key('GchSh') and env['GchSh']:
f550389 Mathias Stearn enable precompiled headers with g++
RedBeard0531 authored
73 if header_path(env['GchSh']) in [x.path for x in deps]:
3315fba playing with pre-compiled headers
Eliot Horowitz authored
74 env.Depends(target, env['GchSh'])
75 return (target, source)
76
77 def generate(env):
78 """
79 Add builders and construction variables for the Gch builder.
80 """
81 env.Append(BUILDERS = {
82 'gch': env.Builder(
83 action = GchAction,
84 target_factory = env.fs.File,
85 ),
86 'gchsh': env.Builder(
87 action = GchShAction,
88 target_factory = env.fs.File,
89 ),
90 })
91
92 try:
93 bld = env['BUILDERS']['Gch']
94 bldsh = env['BUILDERS']['GchSh']
95 except KeyError:
96 bld = GchBuilder
97 bldsh = GchShBuilder
98 env['BUILDERS']['Gch'] = bld
99 env['BUILDERS']['GchSh'] = bldsh
100
101 env['GCHCOM'] = '$CXX -o $TARGET -x c++-header -c $CXXFLAGS $_CCCOMCOM $SOURCE'
102 env['GCHSHCOM'] = '$CXX -o $TARGET -x c++-header -c $SHCXXFLAGS $_CCCOMCOM $SOURCE'
103 env['GCHSUFFIX'] = '.gch'
104
105 for suffix in SCons.Util.Split('.c .C .cc .cxx .cpp .c++'):
106 env['BUILDERS']['StaticObject'].add_emitter( suffix, static_pch_emitter )
107 env['BUILDERS']['SharedObject'].add_emitter( suffix, shared_pch_emitter )
108
109
110 def exists(env):
111 return env.Detect('g++')
Something went wrong with that request. Please try again.