From 683f431d830dea27069e7eef11d355bae2b82b72 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 11 Jun 2009 03:33:05 +0000 Subject: Works around a gcc bug when compiling tr1/tuple with RTTI disabled. --- Makefile.am | 8 ++++++++ include/gtest/internal/gtest-port.h | 14 ++++++++++++++ scons/SConscript | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Makefile.am b/Makefile.am index b030cd8..148a076 100644 --- a/Makefile.am +++ b/Makefile.am @@ -292,6 +292,14 @@ check_PROGRAMS += test/gtest_unittest test_gtest_unittest_SOURCES = test/gtest_unittest.cc 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 # 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 diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 1b573e4..e6b9d14 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -379,7 +379,21 @@ #elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) // GCC 4.0+ implements tr1/tuple in the header. This does // not conform to the TR1 spec, which requires the header to be . + +#if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 +// Until version 4.3.2, gcc has a bug that causes , +// which is #included by , to not compile when RTTI is +// disabled. _TR1_FUNCTIONAL is the header guard for +// . Hence the following #define is a hack to prevent +// from being included. +#define _TR1_FUNCTIONAL 1 +#include +#undef _TR1_FUNCTIONAL // Allows the user to #include + // if he chooses to. +#else #include +#endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 + #else // If the compiler is not GCC 4.0+, we assume the user is using a // spec-conforming TR1 implementation. diff --git a/scons/SConscript b/scons/SConscript index 21b5ab5..c409dcb 100644 --- a/scons/SConscript +++ b/scons/SConscript @@ -126,6 +126,13 @@ if env_with_exceptions['PLATFORM'] == 'win32': if '_TYPEINFO_' in cppdefines: 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', source=gtest_source) 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 return source -def GtestBinary(env, target, gtest_lib, sources): +def GtestBinary(env, target, gtest_libs, sources): """Helper to create gtest binaries: tests, samples, etc. Args: env: The SCons construction environment to use to build. target: The basename of the target's main source file, also used as target 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. """ - 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(): - env.Install('$EXE_OUTPUT', source=[unit_test]) + env.Install('$EXE_OUTPUT', source=[binary]) def GtestUnitTest(env, target, gtest_lib, additional_sources=None): """Helper to create gtest unit tests. @@ -183,7 +190,7 @@ def GtestUnitTest(env, target, gtest_lib, additional_sources=None): """ GtestBinary(env, target, - gtest_lib, + [gtest_lib], ConstructSourceList(target, "../test", additional_sources=additional_sources)) @@ -232,9 +239,25 @@ gtest_unittest_ex_obj = env_with_exceptions.Object( source='../test/gtest_unittest.cc') GtestBinary(env_with_exceptions, 'gtest_ex_unittest', - gtest_ex_main, + [gtest_ex_main], 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 # Windows; otherwise the redirection of stdout does not work # (apparently because of a compiler bug). @@ -258,7 +281,7 @@ def GtestSample(env, target, gtest_lib, additional_sources=None): """ GtestBinary(env, target, - gtest_lib, + [gtest_lib], ConstructSourceList(target, "../samples", additional_sources=additional_sources)) -- cgit v0.12