Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / CXX / CXXFLAGS.py
blob8d72708ee8de8bed1f2373442341935e008928a7
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify that $CXXFLAGS settings are used to build both static
29 and shared object files.
30 """
32 import os
33 import sys
35 import TestSCons
37 _obj = TestSCons._obj
39 if os.name == 'posix':
40 os.environ['LD_LIBRARY_PATH'] = '.'
41 if sys.platform.find('irix') > -1:
42 os.environ['LD_LIBRARYN32_PATH'] = '.'
44 test = TestSCons.TestSCons()
46 e = test.Environment()
48 test.write('SConstruct', """
49 foo = Environment(WINDOWS_INSERT_DEF=1)
50 foo.Append(CXXFLAGS = '-DFOO')
51 bar = Environment(WINDOWS_INSERT_DEF=1)
52 bar.Append(CXXFLAGS = '-DBAR')
53 foo_obj = foo.SharedObject(target = 'fooshared%(_obj)s', source = 'doIt.cpp')
54 bar_obj = bar.SharedObject(target = 'barshared%(_obj)s', source = 'doIt.cpp')
55 foo.SharedLibrary(target = 'foo', source = foo_obj)
56 bar.SharedLibrary(target = 'bar', source = bar_obj)
58 fooMain = foo.Clone(LIBS='foo', LIBPATH='.')
59 foo_obj = fooMain.Object(target='foomain', source='main.c')
60 fooMain.Program(target='fooprog', source=foo_obj)
62 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
63 bar_obj = barMain.Object(target='barmain', source='main.c')
64 barMain.Program(target='barprog', source=bar_obj)
66 foo_obj = foo.Object(target = 'foostatic', source = 'prog.cpp')
67 bar_obj = bar.Object(target = 'barstatic', source = 'prog.cpp')
68 foo.Program(target = 'foo', source = foo_obj)
69 bar.Program(target = 'bar', source = bar_obj)
70 """ % locals())
72 test.write('foo.def', r"""
73 LIBRARY "foo"
74 DESCRIPTION "Foo Shared Library"
76 EXPORTS
77 doIt
78 """)
80 test.write('bar.def', r"""
81 LIBRARY "bar"
82 DESCRIPTION "Bar Shared Library"
84 EXPORTS
85 doIt
86 """)
88 test.write('doIt.cpp', r"""
89 #include <stdio.h>
91 extern "C" void
92 doIt()
94 #ifdef FOO
95 printf("doIt.cpp: FOO\n");
96 #endif
97 #ifdef BAR
98 printf("doIt.cpp: BAR\n");
99 #endif
101 """)
103 test.write('main.c', r"""
105 void doIt();
108 main(int argc, char* argv[])
110 doIt();
111 return 0;
113 """)
115 test.write('prog.cpp', r"""
116 #include <stdio.h>
117 #include <stdlib.h>
120 main(int argc, char *argv[])
122 argv[argc++] = (char *)"--";
123 #ifdef FOO
124 printf("prog.c: FOO\n");
125 #endif
126 #ifdef BAR
127 printf("prog.c: BAR\n");
128 #endif
129 exit (0);
131 """)
133 test.run(arguments = '.')
135 test.run(program = test.workpath('fooprog'), stdout = "doIt.cpp: FOO\n")
136 test.run(program = test.workpath('barprog'), stdout = "doIt.cpp: BAR\n")
137 test.run(program = test.workpath('foo'), stdout = "prog.c: FOO\n")
138 test.run(program = test.workpath('bar'), stdout = "prog.c: BAR\n")
142 test.write('SConstruct', """
143 bar = Environment(WINDOWS_INSERT_DEF=1)
144 bar.Append(CXXFLAGS = '-DBAR')
145 foo_obj = bar.SharedObject(target = 'foo%(_obj)s', source = 'doIt.cpp')
146 bar_obj = bar.SharedObject(target = 'bar%(_obj)s', source = 'doIt.cpp')
147 bar.SharedLibrary(target = 'foo', source = foo_obj)
148 bar.SharedLibrary(target = 'bar', source = bar_obj)
150 barMain = bar.Clone(LIBS='bar', LIBPATH='.')
151 foo_obj = barMain.Object(target='foomain', source='main.c')
152 bar_obj = barMain.Object(target='barmain', source='main.c')
153 barMain.Program(target='barprog', source=foo_obj)
154 barMain.Program(target='fooprog', source=bar_obj)
155 """ % locals())
157 test.run(arguments = '.')
159 test.run(program = test.workpath('fooprog'), stdout = "doIt.cpp: BAR\n")
160 test.run(program = test.workpath('barprog'), stdout = "doIt.cpp: BAR\n")
164 test.pass_test()
166 # Local Variables:
167 # tab-width:4
168 # indent-tabs-mode:nil
169 # End:
170 # vim: set expandtab tabstop=4 shiftwidth=4: