OLD | NEW |
1 """engine.SCons.Tool.msvc | 1 """engine.SCons.Tool.msvc |
2 | 2 |
3 Tool-specific initialization for Microsoft Visual C/C++. | 3 Tool-specific initialization for Microsoft Visual C/C++. |
4 | 4 |
5 There normally shouldn't be any need to import this module directly. | 5 There normally shouldn't be any need to import this module directly. |
6 It will usually be imported through the generic SCons.Tool.Tool() | 6 It will usually be imported through the generic SCons.Tool.Tool() |
7 selection method. | 7 selection method. |
8 | 8 |
9 """ | 9 """ |
10 | 10 |
11 # | 11 # |
12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion | 12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The SCons F
oundation |
13 # | 13 # |
14 # Permission is hereby granted, free of charge, to any person obtaining | 14 # Permission is hereby granted, free of charge, to any person obtaining |
15 # a copy of this software and associated documentation files (the | 15 # a copy of this software and associated documentation files (the |
16 # "Software"), to deal in the Software without restriction, including | 16 # "Software"), to deal in the Software without restriction, including |
17 # without limitation the rights to use, copy, modify, merge, publish, | 17 # without limitation the rights to use, copy, modify, merge, publish, |
18 # distribute, sublicense, and/or sell copies of the Software, and to | 18 # distribute, sublicense, and/or sell copies of the Software, and to |
19 # permit persons to whom the Software is furnished to do so, subject to | 19 # permit persons to whom the Software is furnished to do so, subject to |
20 # the following conditions: | 20 # the following conditions: |
21 # | 21 # |
22 # The above copyright notice and this permission notice shall be included | 22 # The above copyright notice and this permission notice shall be included |
23 # in all copies or substantial portions of the Software. | 23 # in all copies or substantial portions of the Software. |
24 # | 24 # |
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | 25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | 26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | 28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | 29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
32 # | 32 # |
33 | 33 |
34 __revision__ = "src/engine/SCons/Tool/msvc.py 3842 2008/12/20 22:59:52 scons" | 34 __revision__ = "src/engine/SCons/Tool/msvc.py 3897 2009/01/13 06:45:54 scons" |
35 | 35 |
36 import os.path | 36 import os.path |
37 import re | 37 import re |
38 import string | 38 import string |
39 | 39 |
40 import SCons.Action | 40 import SCons.Action |
41 import SCons.Builder | 41 import SCons.Builder |
42 import SCons.Errors | 42 import SCons.Errors |
43 import SCons.Platform.win32 | 43 import SCons.Platform.win32 |
44 import SCons.Tool | 44 import SCons.Tool |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 | 665 |
666 # Logic to build .rc files into .res files (resource files) | 666 # Logic to build .rc files into .res files (resource files) |
667 res_scanner = SCons.Scanner.RC.RCScan() | 667 res_scanner = SCons.Scanner.RC.RCScan() |
668 res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') | 668 res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') |
669 res_builder = SCons.Builder.Builder(action=res_action, | 669 res_builder = SCons.Builder.Builder(action=res_action, |
670 src_suffix='.rc', | 670 src_suffix='.rc', |
671 suffix='.res', | 671 suffix='.res', |
672 src_builder=[], | 672 src_builder=[], |
673 source_scanner=res_scanner) | 673 source_scanner=res_scanner) |
674 | 674 |
| 675 def msvc_batch_key(action, env, target, source): |
| 676 """ |
| 677 Returns a key to identify unique batches of sources for compilation. |
| 678 |
| 679 If batching is enabled (via the $MSVC_BATCH setting), then all |
| 680 target+source pairs that use the same action, defined by the same |
| 681 environment, and have the same target and source directories, will |
| 682 be batched. |
| 683 |
| 684 Returning None specifies that the specified target+source should not |
| 685 be batched with other compilations. |
| 686 """ |
| 687 b = env.subst('$MSVC_BATCH') |
| 688 if b in (None, '', '0'): |
| 689 # We're not using batching; return no key. |
| 690 return None |
| 691 t = target[0] |
| 692 s = source[0] |
| 693 if os.path.splitext(t.name)[0] != os.path.splitext(s.name)[0]: |
| 694 # The base names are different, so this *must* be compiled |
| 695 # separately; return no key. |
| 696 return None |
| 697 return (id(action), id(env), t.dir, s.dir) |
| 698 |
| 699 def msvc_output_flag(target, source, env, for_signature): |
| 700 """ |
| 701 Returns the correct /Fo flag for batching. |
| 702 |
| 703 If batching is disabled or there's only one source file, then we |
| 704 return an /Fo string that specifies the target explicitly. Otherwise, |
| 705 we return an /Fo string that just specifies the first target's |
| 706 directory (where the Visual C/C++ compiler will put the .obj files). |
| 707 """ |
| 708 b = env.subst('$MSVC_BATCH') |
| 709 if b in (None, '', '0') or len(source) == 1: |
| 710 return '/Fo$TARGET' |
| 711 else: |
| 712 # The Visual C/C++ compiler requires a \ at the end of the /Fo |
| 713 # option to indicate an output directory. We use os.sep here so |
| 714 # that the test(s) for this can be run on non-Windows systems |
| 715 # without having a hard-coded backslash mess up command-line |
| 716 # argument parsing. |
| 717 return '/Fo${TARGET.dir}' + os.sep |
| 718 |
| 719 CAction = SCons.Action.Action("$CCCOM", "$CCCOMSTR", |
| 720 batch_key=msvc_batch_key, |
| 721 targets='$CHANGED_TARGETS') |
| 722 ShCAction = SCons.Action.Action("$SHCCCOM", "$SHCCCOMSTR", |
| 723 batch_key=msvc_batch_key, |
| 724 targets='$CHANGED_TARGETS') |
| 725 CXXAction = SCons.Action.Action("$CXXCOM", "$CXXCOMSTR", |
| 726 batch_key=msvc_batch_key, |
| 727 targets='$CHANGED_TARGETS') |
| 728 ShCXXAction = SCons.Action.Action("$SHCXXCOM", "$SHCXXCOMSTR", |
| 729 batch_key=msvc_batch_key, |
| 730 targets='$CHANGED_TARGETS') |
675 | 731 |
676 def generate(env): | 732 def generate(env): |
677 """Add Builders and construction variables for MSVC++ to an Environment.""" | 733 """Add Builders and construction variables for MSVC++ to an Environment.""" |
678 static_obj, shared_obj = SCons.Tool.createObjBuilders(env) | 734 static_obj, shared_obj = SCons.Tool.createObjBuilders(env) |
679 | 735 |
| 736 # TODO(batch): shouldn't reach in to cmdgen this way; necessary |
| 737 # for now to bypass the checks in Builder.DictCmdGenerator.__call__() |
| 738 # and allow .cc and .cpp to be compiled in the same command line. |
| 739 static_obj.cmdgen.source_ext_match = False |
| 740 shared_obj.cmdgen.source_ext_match = False |
| 741 |
680 for suffix in CSuffixes: | 742 for suffix in CSuffixes: |
681 static_obj.add_action(suffix, SCons.Defaults.CAction) | 743 static_obj.add_action(suffix, CAction) |
682 shared_obj.add_action(suffix, SCons.Defaults.ShCAction) | 744 shared_obj.add_action(suffix, ShCAction) |
683 static_obj.add_emitter(suffix, static_object_emitter) | 745 static_obj.add_emitter(suffix, static_object_emitter) |
684 shared_obj.add_emitter(suffix, shared_object_emitter) | 746 shared_obj.add_emitter(suffix, shared_object_emitter) |
685 | 747 |
686 for suffix in CXXSuffixes: | 748 for suffix in CXXSuffixes: |
687 static_obj.add_action(suffix, SCons.Defaults.CXXAction) | 749 static_obj.add_action(suffix, CXXAction) |
688 shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction) | 750 shared_obj.add_action(suffix, ShCXXAction) |
689 static_obj.add_emitter(suffix, static_object_emitter) | 751 static_obj.add_emitter(suffix, static_object_emitter) |
690 shared_obj.add_emitter(suffix, shared_object_emitter) | 752 shared_obj.add_emitter(suffix, shared_object_emitter) |
691 | 753 |
692 env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}']) | 754 env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}']) |
693 env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or
"",File(PCH))) or ""}']) | 755 env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or
"",File(PCH))) or ""}']) |
| 756 env['_MSVC_OUTPUT_FLAG'] = msvc_output_flag |
694 env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $CCPCHFLAGS $CCPD
BFLAGS' | 757 env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS $CCPCHFLAGS $CCPD
BFLAGS' |
695 env['CC'] = 'cl' | 758 env['CC'] = 'cl' |
696 env['CCFLAGS'] = SCons.Util.CLVar('/nologo') | 759 env['CCFLAGS'] = SCons.Util.CLVar('/nologo') |
697 env['CFLAGS'] = SCons.Util.CLVar('') | 760 env['CFLAGS'] = SCons.Util.CLVar('') |
698 env['CCCOM'] = '$CC /Fo$TARGET /c $SOURCES $CFLAGS $CCFLAGS $_CCCOMCOM' | 761 env['CCCOM'] = '$CC $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CFLAGS $CCF
LAGS $_CCCOMCOM' |
699 env['SHCC'] = '$CC' | 762 env['SHCC'] = '$CC' |
700 env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') | 763 env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') |
701 env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS') | 764 env['SHCFLAGS'] = SCons.Util.CLVar('$CFLAGS') |
702 env['SHCCCOM'] = '$SHCC /Fo$TARGET /c $SOURCES $SHCFLAGS $SHCCFLAGS $_CCC
OMCOM' | 765 env['SHCCCOM'] = '$SHCC $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCFLAGS
$SHCCFLAGS $_CCCOMCOM' |
703 env['CXX'] = '$CC' | 766 env['CXX'] = '$CC' |
704 env['CXXFLAGS'] = SCons.Util.CLVar('$CCFLAGS $( /TP $)') | 767 env['CXXFLAGS'] = SCons.Util.CLVar('$( /TP $)') |
705 env['CXXCOM'] = '$CXX /Fo$TARGET /c $SOURCES $CXXFLAGS $CCFLAGS $_CCCOMC
OM' | 768 env['CXXCOM'] = '$CXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CXXFLAGS $
CCFLAGS $_CCCOMCOM' |
706 env['SHCXX'] = '$CXX' | 769 env['SHCXX'] = '$CXX' |
707 env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS') | 770 env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS') |
708 env['SHCXXCOM'] = '$SHCXX /Fo$TARGET /c $SOURCES $SHCXXFLAGS $SHCCFLAGS $_
CCCOMCOM' | 771 env['SHCXXCOM'] = '$SHCXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCXXFLA
GS $SHCCFLAGS $_CCCOMCOM' |
709 env['CPPDEFPREFIX'] = '/D' | 772 env['CPPDEFPREFIX'] = '/D' |
710 env['CPPDEFSUFFIX'] = '' | 773 env['CPPDEFSUFFIX'] = '' |
711 env['INCPREFIX'] = '/I' | 774 env['INCPREFIX'] = '/I' |
712 env['INCSUFFIX'] = '' | 775 env['INCSUFFIX'] = '' |
713 # env.Append(OBJEMITTER = [static_object_emitter]) | 776 # env.Append(OBJEMITTER = [static_object_emitter]) |
714 # env.Append(SHOBJEMITTER = [shared_object_emitter]) | 777 # env.Append(SHOBJEMITTER = [shared_object_emitter]) |
715 env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 | 778 env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1 |
716 | 779 |
717 env['RC'] = 'rc' | 780 env['RC'] = 'rc' |
718 env['RCFLAGS'] = SCons.Util.CLVar('') | 781 env['RCFLAGS'] = SCons.Util.CLVar('') |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 if not env['ENV'].has_key('SystemRoot'): # required for dlls in the winsx
s folders | 820 if not env['ENV'].has_key('SystemRoot'): # required for dlls in the winsx
s folders |
758 env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root() | 821 env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root() |
759 | 822 |
760 def exists(env): | 823 def exists(env): |
761 if SCons.Tool.msvs.is_msvs_installed(): | 824 if SCons.Tool.msvs.is_msvs_installed(): |
762 # there's at least one version of MSVS installed. | 825 # there's at least one version of MSVS installed. |
763 return 1 | 826 return 1 |
764 else: | 827 else: |
765 return env.Detect('cl') | 828 return env.Detect('cl') |
766 | 829 |
OLD | NEW |