From 7d1051ce2b3be67d27b200d0050a7ec88c18621b Mon Sep 17 00:00:00 2001 From: kosak Date: Mon, 13 Jan 2014 22:24:15 +0000 Subject: Make Google Test build cleanly on Visual Studio 2010, 2012, 2013. Also improve an error message in gtest_test_utils.py. --- CMakeLists.txt | 24 ++++++++++++++++-------- cmake/internal_utils.cmake | 10 ++++++++-- include/gtest/internal/gtest-tuple.h | 8 ++++++++ include/gtest/internal/gtest-tuple.h.pump | 8 ++++++++ test/gtest-typed-test_test.cc | 3 ++- test/gtest_test_utils.py | 6 +++--- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57470c8..bd78cfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,16 @@ include_directories( # Where Google Test's libraries can be found. link_directories(${gtest_BINARY_DIR}/src) +# Summary of tuple support for Microsoft Visual Studio: +# Compiler version(MS) version(cmake) Support +# ---------- ----------- -------------- ----------------------------- +# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple. +# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10 +# VS 2013 12 1800 std::tr1::tuple +if (MSVC AND MSVC_VERSION EQUAL 1700) + add_definitions(/D _VARIADIC_MAX=10) +endif() + ######################################################################## # # Defines the gtest & gtest_main libraries. User tests should link @@ -171,12 +181,10 @@ if (gtest_build_tests) PROPERTIES COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") - if (NOT MSVC OR NOT MSVC_VERSION EQUAL 1600) - # The C++ Standard specifies tuple_element. - # Yet MSVC 10's declares tuple_element. - # That declaration conflicts with our own standard-conforming - # tuple implementation. Therefore using our own tuple with - # MSVC 10 doesn't compile. + if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. + # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that + # conflict with our own definitions. Therefore using our own tuple does not + # work on those compilers. cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}" src/gtest-all.cc src/gtest_main.cc) @@ -194,8 +202,8 @@ if (gtest_build_tests) cxx_executable(gtest_break_on_failure_unittest_ test gtest) py_test(gtest_break_on_failure_unittest) - # MSVC 7.1 does not support STL with exceptions disabled. - if (NOT MSVC OR MSVC_VERSION GREATER 1310) + # Visual Studio .NET 2003 does not support STL with exceptions disabled. + if (NOT MSVC OR MSVC_VERSION GREATER 1310) # 1310 is Visual Studio .NET 2003 cxx_executable_with_flags( gtest_catch_exceptions_no_ex_test_ "${cxx_no_exception}" diff --git a/cmake/internal_utils.cmake b/cmake/internal_utils.cmake index 8cb2189..d497ca1 100644 --- a/cmake/internal_utils.cmake +++ b/cmake/internal_utils.cmake @@ -37,7 +37,7 @@ macro(fix_default_compiler_settings_) # We prefer more strict warning checking for building Google Test. # Replaces /W3 with /W4 in defaults. - string(REPLACE "/W3" "-W4" ${flag_var} "${${flag_var}}") + string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}") endforeach() endif() endmacro() @@ -56,7 +56,7 @@ macro(config_compiler_and_linker) # Newlines inside flags variables break CMake's NMake generator. # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds. set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi") - if (MSVC_VERSION LESS 1400) + if (MSVC_VERSION LESS 1400) # 1400 is Visual Studio 2005 # Suppress spurious warnings MSVC 7.1 sometimes issues. # Forcing value to bool. set(cxx_base_flags "${cxx_base_flags} -wd4800") @@ -66,6 +66,12 @@ macro(config_compiler_and_linker) # Resolved overload was found by argument-dependent lookup. set(cxx_base_flags "${cxx_base_flags} -wd4675") endif() + if (NOT (MSVC_VERSION LESS 1700)) # 1700 is Visual Studio 2012. + # Suppress "unreachable code" warning on VS 2012 and later. + # http://stackoverflow.com/questions/3232669 explains the issue. + set(cxx_base_flags "${cxx_base_flags} -wd4702") + endif() + set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32") set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN") set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1") diff --git a/include/gtest/internal/gtest-tuple.h b/include/gtest/internal/gtest-tuple.h index 7b3dfc3..e9b4053 100644 --- a/include/gtest/internal/gtest-tuple.h +++ b/include/gtest/internal/gtest-tuple.h @@ -53,6 +53,14 @@ private: #endif +// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict +// with our own definitions. Therefore using our own tuple does not work on +// those compilers. +#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */ +# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \ +GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers." +#endif + // GTEST_n_TUPLE_(T) is the type of an n-tuple. #define GTEST_0_TUPLE_(T) tuple<> #define GTEST_1_TUPLE_(T) tuple= 1600 /* 1600 is Visual Studio 2010 */ +# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \ +GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers." +#endif + $range i 0..n-1 $range j 0..n diff --git a/test/gtest-typed-test_test.cc b/test/gtest-typed-test_test.cc index dd4ba43..c3e66c2 100644 --- a/test/gtest-typed-test_test.cc +++ b/test/gtest-typed-test_test.cc @@ -29,10 +29,11 @@ // // Author: wan@google.com (Zhanyong Wan) +#include "test/gtest-typed-test_test.h" + #include #include -#include "test/gtest-typed-test_test.h" #include "gtest/gtest.h" using testing::Test; diff --git a/test/gtest_test_utils.py b/test/gtest_test_utils.py index 28884bd..7e3cbca 100755 --- a/test/gtest_test_utils.py +++ b/test/gtest_test_utils.py @@ -175,9 +175,9 @@ def GetTestExecutablePath(executable_name, build_dir=None): if not os.path.exists(path): message = ( - 'Unable to find the test binary. Please make sure to provide path\n' - 'to the binary via the --build_dir flag or the BUILD_DIR\n' - 'environment variable.') + 'Unable to find the test binary "%s". Please make sure to provide\n' + 'a path to the binary via the --build_dir flag or the BUILD_DIR\n' + 'environment variable.' % path) print >> sys.stderr, message sys.exit(1) -- cgit v0.12