5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 This tests the MinGW C/C++ compiler support.
28 This test requires MinGW to be installed.
37 test
= TestSCons
.TestSCons(match
= TestCmd
.match_re_dotall
)
39 # MinGW is Windows only:
40 if sys
.platform
!= 'win32':
41 msg
= "Skipping mingw test on non-Windows platform '%s'\n" % sys
.platform
44 test
.write('SConstruct',"""
46 from SCons.Tool.mingw import exists
48 DefaultEnvironment(tools=[])
56 if 'mingw exists' not in test
.stdout():
57 test
.skip_test("No MinGW on this system, skipping test.\n")
61 # Do the actual testing:
62 test
.write('SConstruct',"""
63 DefaultEnvironment(tools=[])
64 env = Environment(tools=['mingw'])
65 assert env['CC'] == 'gcc'
66 env.StaticLibrary('static', 'static.cpp')
67 env.SharedLibrary('shared', 'shared.cpp')
68 env.SharedLibrary('cshared', ['cshared.c', 'cshared.def'], WINDOWS_INSERT_DEF=1)
71 ['test.cpp', env.RES('resource.rc', CPPPATH=['header'])],
72 LIBS=['static', 'shared', 'cshared'],
77 test
.write('test.cpp', '''
82 void shared_func(void);
83 void static_func(void);
84 extern "C" void cshared_func(void);
88 printf("%s\\n", "test.cpp");
94 LoadString(GetModuleHandle(NULL), IDS_TEST, test, sizeof(test));
95 printf("%d %s\\n", IDS_TEST, test);
101 test
.write('resource.rc', '''
102 #include "resource.h"
103 #include <resource2.h>
105 STRINGTABLE DISCARDABLE
111 test
.write('resource.h', '''
112 #define IDS_TEST 2001
115 test
.write('static.cpp', '''
118 void static_func(void)
120 printf("%s\\n", "static.cpp");
124 test
.write('shared.cpp', '''
127 void shared_func(void)
129 printf("%s\\n", "shared.cpp");
133 test
.write('cshared.c', '''
136 void cshared_func(void)
138 printf("%s\\n", "cshared.c");
142 test
.write('cshared.def', '''
149 test
.write('header/resource2.h', '''
150 #define RESOURCE_RC "resource.rc"
153 # the mingw linker likes to print "Creating library file: libfoo.a" to stderr, but
154 # we'd like for this test to pass once this bug is fixed, so match anything at all
155 # that comes out of stderr:
156 test
.run(arguments
='test.exe', stderr
='.*')
157 # ensure the source def for cshared.def got used, and there wasn't a target def for chshared.dll:
158 test
.fail_test('cshared.def' not in test
.stdout())
159 test
.fail_test('-Wl,--output-def,cshared.def' in test
.stdout())
160 # ensure the target def got generated for the shared.dll:
161 test
.fail_test(not os
.path
.exists(test
.workpath('cshared.def')))
162 test
.fail_test(os
.path
.exists(test
.workpath('shared.def')))
163 test
.run(program
=test
.workpath('test.exe'), stdout
='test.cpp\nshared.cpp\nstatic.cpp\ncshared.c\n2001 resource.rc\n')
165 # ensure that modifying the header causes the resource to be rebuilt:
166 test
.write('resource.h', '''
167 #define IDS_TEST 2002
169 test
.run(arguments
='test.exe', stderr
='.*')
170 test
.run(program
=test
.workpath('test.exe'), stdout
='test.cpp\nshared.cpp\nstatic.cpp\ncshared.c\n2002 resource.rc\n')
172 # Test with specifying the default tool to make sure msvc setting doen't ruin it
174 test
.write('SConstruct',"""
175 env=Environment(tools=['default', 'mingw'])
176 assert env['CC'] == 'gcc'
177 env.SharedLibrary('shared', 'shared.cpp')
178 env.Program('test', 'test.cpp', LIBS=['static', 'shared', 'cshared'], LIBPATH=['.'])
181 test
.write('test.cpp', '''
184 void shared_func(void);
188 printf("%s\\n", "test.cpp2");
194 test
.write('shared.cpp', '''
197 void shared_func(void)
199 printf("%s\\n", "shared.cpp2");
203 # the mingw linker likes to print "Creating library file: libfoo.a" to stderr, but
204 # we'd like for this test to pass once this bug is fixed, so match anything at all
205 # that comes out of stderr:
206 test
.run(arguments
='test.exe', stderr
='.*')
207 test
.run(program
=test
.workpath('test.exe'), stdout
='test.cpp2\nshared.cpp2\n')
213 # indent-tabs-mode:nil
215 # vim: set expandtab tabstop=4 shiftwidth=4: