Works around a gcc bug when compiling tr1/tuple with RTTI disabled.

This commit is contained in:
zhanyong.wan 2009-06-11 03:33:05 +00:00
parent b24b49d85a
commit 683f431d83
3 changed files with 52 additions and 7 deletions

View File

@ -292,6 +292,14 @@ check_PROGRAMS += test/gtest_unittest
test_gtest_unittest_SOURCES = test/gtest_unittest.cc test_gtest_unittest_SOURCES = test/gtest_unittest.cc
test_gtest_unittest_LDADD = lib/libgtest_main.la test_gtest_unittest_LDADD = lib/libgtest_main.la
# Verifies that Google Test works when RTTI is disabled.
TESTS += test/gtest_no_rtti_test
check_PROGRAMS += test/gtest_no_rtti_test
test_gtest_no_rtti_test_SOURCES = test/gtest_unittest.cc \
src/gtest-all.cc \
src/gtest_main.cc
test_gtest_no_rtti_test_CXXFLAGS = $(AM_CXXFLAGS) -fno-rtti -DGTEST_HAS_RTTI=0
# The following tests depend on the presence of a Python installation and are # The following tests depend on the presence of a Python installation and are
# keyed off of it. TODO(chandlerc@google.com): While we currently only attempt # keyed off of it. TODO(chandlerc@google.com): While we currently only attempt
# to build and execute these tests if Autoconf has found Python v2.4 on the # to build and execute these tests if Autoconf has found Python v2.4 on the

View File

@ -379,7 +379,21 @@
#elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) #elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does // GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
// not conform to the TR1 spec, which requires the header to be <tuple>. // not conform to the TR1 spec, which requires the header to be <tuple>.
#if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
// which is #included by <tr1/tuple>, to not compile when RTTI is
// disabled. _TR1_FUNCTIONAL is the header guard for
// <tr1/functional>. Hence the following #define is a hack to prevent
// <tr1/functional> from being included.
#define _TR1_FUNCTIONAL 1
#include <tr1/tuple> #include <tr1/tuple>
#undef _TR1_FUNCTIONAL // Allows the user to #include
// <tr1/functional> if he chooses to.
#else
#include <tr1/tuple>
#endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
#else #else
// If the compiler is not GCC 4.0+, we assume the user is using a // If the compiler is not GCC 4.0+, we assume the user is using a
// spec-conforming TR1 implementation. // spec-conforming TR1 implementation.

View File

@ -126,6 +126,13 @@ if env_with_exceptions['PLATFORM'] == 'win32':
if '_TYPEINFO_' in cppdefines: if '_TYPEINFO_' in cppdefines:
cppdefines.remove('_TYPEINFO_') cppdefines.remove('_TYPEINFO_')
env_without_rtti = env.Clone()
if env_without_rtti['PLATFORM'] == 'win32':
env_without_rtti.Append(CCFLAGS = ['/GR-'])
else:
env_without_rtti.Append(CCFLAGS = ['-fno-rtti'])
env_without_rtti.Append(CPPDEFINES = 'GTEST_HAS_RTTI=0')
gtest_ex_obj = env_with_exceptions.Object(target='gtest_ex', gtest_ex_obj = env_with_exceptions.Object(target='gtest_ex',
source=gtest_source) source=gtest_source)
gtest_main_ex_obj = env_with_exceptions.Object(target='gtest_main_ex', gtest_main_ex_obj = env_with_exceptions.Object(target='gtest_main_ex',
@ -158,19 +165,19 @@ def ConstructSourceList(target, dir_prefix, additional_sources=None):
source += additional_sources source += additional_sources
return source return source
def GtestBinary(env, target, gtest_lib, sources): def GtestBinary(env, target, gtest_libs, sources):
"""Helper to create gtest binaries: tests, samples, etc. """Helper to create gtest binaries: tests, samples, etc.
Args: Args:
env: The SCons construction environment to use to build. env: The SCons construction environment to use to build.
target: The basename of the target's main source file, also used as target target: The basename of the target's main source file, also used as target
name. name.
gtest_lib: The gtest lib to use. gtest_libs: A list of gtest libraries to use.
sources: A list of source files in the target. sources: A list of source files in the target.
""" """
unit_test = env.Program(target=target, source=sources, LIBS=[gtest_lib]) binary = env.Program(target=target, source=sources, LIBS=gtest_libs)
if 'EXE_OUTPUT' in env.Dictionary(): if 'EXE_OUTPUT' in env.Dictionary():
env.Install('$EXE_OUTPUT', source=[unit_test]) env.Install('$EXE_OUTPUT', source=[binary])
def GtestUnitTest(env, target, gtest_lib, additional_sources=None): def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
"""Helper to create gtest unit tests. """Helper to create gtest unit tests.
@ -183,7 +190,7 @@ def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
""" """
GtestBinary(env, GtestBinary(env,
target, target,
gtest_lib, [gtest_lib],
ConstructSourceList(target, "../test", ConstructSourceList(target, "../test",
additional_sources=additional_sources)) additional_sources=additional_sources))
@ -232,9 +239,25 @@ gtest_unittest_ex_obj = env_with_exceptions.Object(
source='../test/gtest_unittest.cc') source='../test/gtest_unittest.cc')
GtestBinary(env_with_exceptions, GtestBinary(env_with_exceptions,
'gtest_ex_unittest', 'gtest_ex_unittest',
gtest_ex_main, [gtest_ex_main],
gtest_unittest_ex_obj) gtest_unittest_ex_obj)
gtest_unittest_no_rtti_obj = env_without_rtti.Object(
target='gtest_unittest_no_rtti',
source='../test/gtest_unittest.cc')
gtest_all_no_rtti_obj = env_without_rtti.Object(
target='gtest_all_no_rtti',
source='../src/gtest-all.cc')
gtest_main_no_rtti_obj = env_without_rtti.Object(
target='gtest_main_no_rtti',
source='../src/gtest_main.cc')
GtestBinary(env_without_rtti,
'gtest_no_rtti_test',
[],
gtest_unittest_no_rtti_obj +
gtest_all_no_rtti_obj +
gtest_main_no_rtti_obj)
# We need to disable some optimization flags for some tests on # We need to disable some optimization flags for some tests on
# Windows; otherwise the redirection of stdout does not work # Windows; otherwise the redirection of stdout does not work
# (apparently because of a compiler bug). # (apparently because of a compiler bug).
@ -258,7 +281,7 @@ def GtestSample(env, target, gtest_lib, additional_sources=None):
""" """
GtestBinary(env, GtestBinary(env,
target, target,
gtest_lib, [gtest_lib],
ConstructSourceList(target, "../samples", ConstructSourceList(target, "../samples",
additional_sources=additional_sources)) additional_sources=additional_sources))