96
95
############################################################
97
96
# Environments for building the targets, sorted by name.
99
def NewEnvironment(env, type):
100
"""Copies environment and gives it suffix for names of targets built in it."""
107
new_env = env.Clone()
108
new_env['OBJ_SUFFIX'] = suffix
112
def Remove(env, attribute, value):
113
"""Removes the given attribute value from the environment."""
115
attribute_values = env[attribute]
116
if value in attribute_values:
117
attribute_values.remove(value)
121
env = NewEnvironment(env, '')
98
Import('env', 'EnvCreator')
100
env = EnvCreator.Create(env)
123
102
# Note: The relative paths in SConscript files are relative to the location
124
103
# of the SConscript file itself. To make a path relative to the location of
133
112
# file is one directory deeper than the gtest directory.
134
113
env.Prepend(CPPPATH = ['..', '../include'])
136
env_use_own_tuple = NewEnvironment(env, 'use_own_tuple')
137
env_use_own_tuple.Append(CPPDEFINES = 'GTEST_USE_OWN_TR1_TUPLE=1')
139
# Needed to allow gtest_unittest.cc, which triggers a gcc warning when
140
# testing EXPECT_EQ(NULL, ptr), to compile.
141
env_warning_ok = NewEnvironment(env, 'warning_ok')
142
if env_warning_ok['PLATFORM'] == 'win32':
143
Remove(env_warning_ok, 'CCFLAGS', '-WX')
145
Remove(env_warning_ok, 'CCFLAGS', '-Werror')
147
env_with_exceptions = NewEnvironment(env_warning_ok, 'ex')
148
if env_with_exceptions['PLATFORM'] == 'win32':
149
env_with_exceptions.Append(CCFLAGS=['/EHsc'])
150
env_with_exceptions.Append(CPPDEFINES='_HAS_EXCEPTIONS=1')
151
# Undoes the _TYPEINFO_ hack, which is unnecessary and only creates
152
# trouble when exceptions are enabled.
153
Remove(env_with_exceptions, 'CPPDEFINES', '_TYPEINFO_')
154
Remove(env_with_exceptions, 'CPPDEFINES', '_HAS_EXCEPTIONS=0')
156
env_with_exceptions.Append(CCFLAGS='-fexceptions')
157
Remove(env_with_exceptions, 'CCFLAGS', '-fno-exceptions')
159
# We need to disable some optimization flags for some tests on
160
# Windows; otherwise the redirection of stdout does not work
161
# (apparently because of a compiler bug).
162
env_less_optimized = NewEnvironment(env, 'less_optimized')
163
if env_less_optimized['PLATFORM'] == 'win32':
164
for flag in ['/O1', '/Os', '/Og', '/Oy']:
165
Remove(env_less_optimized, 'LINKFLAGS', flag)
167
# Assuming POSIX-like environment with GCC.
168
# TODO(vladl@google.com): sniff presence of pthread_atfork instead of
169
# selecting on a platform.
170
env_with_threads = NewEnvironment(env, 'with_threads')
171
if env_with_threads['PLATFORM'] != 'win32':
172
env_with_threads.Append(CCFLAGS=['-pthread'])
173
env_with_threads.Append(LINKFLAGS=['-pthread'])
175
env_without_rtti = NewEnvironment(env_warning_ok, 'no_rtti')
176
if env_without_rtti['PLATFORM'] == 'win32':
177
env_without_rtti.Append(CCFLAGS=['/GR-'])
179
env_without_rtti.Append(CCFLAGS=['-fno-rtti'])
180
env_without_rtti.Append(CPPDEFINES='GTEST_HAS_RTTI=0')
115
env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple)
116
env_less_optimized = EnvCreator.Create(env, EnvCreator.LessOptimized)
117
env_with_threads = EnvCreator.Create(env, EnvCreator.WithThreads)
118
# The following environments are used to compile gtest_unittest.cc, which
119
# triggers a warning in all but the most recent GCC versions when compiling
120
# the EXPECT_EQ(NULL, ptr) statement.
121
env_warning_ok = EnvCreator.Create(env, EnvCreator.WarningOk)
122
env_with_exceptions = EnvCreator.Create(env_warning_ok,
123
EnvCreator.WithExceptions)
124
env_without_rtti = EnvCreator.Create(env_warning_ok, EnvCreator.NoRtti)
182
126
############################################################
183
127
# Helpers for creating build targets.
318
262
GtestTest(env, 'gtest_throw_on_failure_test_', gtest)
319
263
GtestTest(env, 'gtest_xml_outfile1_test_', gtest_main)
320
264
GtestTest(env, 'gtest_xml_outfile2_test_', gtest_main)
321
GtestTest(env, 'gtest_xml_output_unittest_', gtest_main)
265
GtestTest(env, 'gtest_xml_output_unittest_', gtest)
322
266
GtestTest(env, 'gtest-unittest-api_test', gtest)
267
GtestTest(env, 'gtest-listener_test', gtest)
268
GtestTest(env, 'gtest_shuffle_test_', gtest)
324
270
############################################################
325
271
# Tests targets using custom environments.
363
309
GtestSample(env, 'sample6_unittest')
364
310
GtestSample(env, 'sample7_unittest')
365
311
GtestSample(env, 'sample8_unittest')
312
GtestSample(env, 'sample9_unittest')
313
GtestSample(env, 'sample10_unittest')
367
315
# These exports are used by Google Mock.
368
316
gtest_exports = {'gtest': gtest,
369
317
'gtest_ex': gtest_ex,
370
318
'gtest_no_rtti': gtest_no_rtti,
371
319
'gtest_use_own_tuple': gtest_use_own_tuple,
372
'NewEnvironment': NewEnvironment,
320
'EnvCreator': EnvCreator,
373
321
'GtestObject': GtestObject,
374
322
'GtestBinary': GtestBinary,
375
323
'GtestTest': GtestTest}