3 Tool-specific initialization for Microsoft Visual C/C++.
5 Based on SCons.Tool.msvc, without the MSVS detection.
10 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
12 # Permission is hereby granted, free of charge, to any person obtaining
13 # a copy of this software and associated documentation files (the
14 # "Software"), to deal in the Software without restriction, including
15 # without limitation the rights to use, copy, modify, merge, publish,
16 # distribute, sublicense, and/or sell copies of the Software, and to
17 # permit persons to whom the Software is furnished to do so, subject to
18 # the following conditions:
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
24 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 import SCons.Platform.win32
44 CSuffixes = ['.c', '.C']
45 CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
47 def validate_vars(env):
48 """Validate the PCH and PCHSTOP construction variables."""
49 if env.has_key('PCH') and env['PCH']:
50 if not env.has_key('PCHSTOP'):
51 raise SCons.Errors.UserError, "The PCHSTOP construction must be defined if PCH is defined."
52 if not SCons.Util.is_String(env['PCHSTOP']):
53 raise SCons.Errors.UserError, "The PCHSTOP construction variable must be a string: %r"%env['PCHSTOP']
55 def pch_emitter(target, source, env):
56 """Adds the object file target."""
64 if SCons.Util.splitext(str(t))[1] == '.pch':
66 if SCons.Util.splitext(str(t))[1] == '.obj':
70 obj = SCons.Util.splitext(str(pch))[0]+'.obj'
72 target = [pch, obj] # pch must be first, and obj second for the PCHCOM to work
74 return (target, source)
76 def object_emitter(target, source, env, parent_emitter):
77 """Sets up the PCH dependencies for an object file."""
81 parent_emitter(target, source, env)
83 if env.has_key('PCH') and env['PCH']:
84 env.Depends(target, env['PCH'])
86 return (target, source)
88 def static_object_emitter(target, source, env):
89 return object_emitter(target, source, env,
90 SCons.Defaults.StaticObjectEmitter)
92 def shared_object_emitter(target, source, env):
93 return object_emitter(target, source, env,
94 SCons.Defaults.SharedObjectEmitter)
96 pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR')
97 pch_builder = SCons.Builder.Builder(action=pch_action, suffix='.pch',
99 source_scanner=SCons.Tool.SourceFileScanner)
100 res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
101 res_builder = SCons.Builder.Builder(action=res_action,
105 source_scanner=SCons.Tool.SourceFileScanner)
106 SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
109 """Add Builders and construction variables for MSVC++ to an Environment."""
110 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
112 for suffix in CSuffixes:
113 static_obj.add_action(suffix, SCons.Defaults.CAction)
114 shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
115 static_obj.add_emitter(suffix, static_object_emitter)
116 shared_obj.add_emitter(suffix, shared_object_emitter)
118 for suffix in CXXSuffixes:
119 static_obj.add_action(suffix, SCons.Defaults.CXXAction)
120 shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
121 static_obj.add_emitter(suffix, static_object_emitter)
122 shared_obj.add_emitter(suffix, shared_object_emitter)
124 env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}'])
125 env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'])
126 env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS'
128 env['CCFLAGS'] = SCons.Util.CLVar('/nologo')
129 env['CFLAGS'] = SCons.Util.CLVar('')
130 env['CCCOM'] = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
132 env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS')
133 env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS')
134 env['SHCCCOM'] = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
136 env['CXXFLAGS'] = SCons.Util.CLVar('$CCFLAGS $( /TP $)')
137 env['CXXCOM'] = '$CXX $CXXFLAGS $CCCOMFLAGS'
138 env['SHCXX'] = '$CXX'
139 env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
140 env['SHCXXCOM'] = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
141 env['CPPDEFPREFIX'] = '/D'
142 env['CPPDEFSUFFIX'] = ''
143 env['INCPREFIX'] = '/I'
144 env['INCSUFFIX'] = ''
145 # env.Append(OBJEMITTER = [static_object_emitter])
146 # env.Append(SHOBJEMITTER = [shared_object_emitter])
147 env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
150 env['RCFLAGS'] = SCons.Util.CLVar('')
151 env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES'
152 env['BUILDERS']['RES'] = res_builder
153 env['OBJPREFIX'] = ''
154 env['OBJSUFFIX'] = '.obj'
155 env['SHOBJPREFIX'] = '$OBJPREFIX'
156 env['SHOBJSUFFIX'] = '$OBJSUFFIX'
158 env['CFILESUFFIX'] = '.c'
159 env['CXXFILESUFFIX'] = '.cc'
161 env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
162 env['PCHCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo${TARGETS[1]} /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS'
163 env['BUILDERS']['PCH'] = pch_builder
165 if not env.has_key('ENV'):
167 if not env['ENV'].has_key('SystemRoot'): # required for dlls in the winsxs folders
168 env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root()
171 return env.Detect('cl')
173 # vim:set ts=4 sw=4 et: