Crascit/DownloadProject

GTest example doesn't work with MSVC 11

Closed this issue · 6 comments

The GTest example actually doesn't work with MSVC 11 (toolset v110) due to VC++ not supporting variadic templates.

The problem can be fixed by defining GTEST_HAS_TR1_TUPLE to 0 or _VARIADIC_MAX to 10, although the latter is more of a band aid than a solution.

This is just a heads up for anyone who might want to use this with an old version of MSVC

To clarify, it's the build of gtest itself that fails, not the downloading? In other words, you have this problem regardless of how you obtain the gtest sources?

yes it's an issue of gtest. Like I said, I just posted this issue to give a heads up to people who want to simply copy&paste your example (probably the majority of users) and are surprised that their build doesn't work, I wasn't expecting a "fix" from you.

Okay, no worries. Thanks for documenting it and providing a workaround. I'll close this issue now.

In my opinion it is not an issue of gtest. In gtest they already put the workaround to compile but being called from a parent CMake file is not working because we are forcing to not change compiling options.
For me the solution is to add the snipped code under the download_project.

include(DownloadProject.cmake)
download_project(PROJ                googletest
                 GIT_REPOSITORY      https://github.com/google/googletest.git
                 GIT_TAG             master
                 ${UPDATE_DISCONNECTED_IF_AVAILABLE}
)

if (MSVC AND MSVC_VERSION EQUAL 1700)
  add_definitions(/D _VARIADIC_MAX=10)
endif()

@limdor Does gtest change compile options only for it's own targets or globally? Otherwise it is definitely necessary to prevent gtest from changing compile options, as it would also affect your own targets and might lead to unexpected behaviour. But I do see your point.

Also have a look at this project of mine which I created specifically for configuring gtest with cmake, as gtest is really just an example usage of DownloadProject. I tested it with several versions of gcc, clang and msvc.

I understand the point about blocking the compiler options.
To reproduce this it is only necessary to try to compile the DownloadProject with VS2012.

Here you can see how the fix is already in googletest:
https://github.com/google/googletest/blob/master/googletest/CMakeLists.txt#L78