Skip to content
This repository has been archived by the owner on Sep 21, 2019. It is now read-only.

Commit

Permalink
- apply patch from google/googletest#1339
Browse files Browse the repository at this point in the history
  • Loading branch information
SSE4 committed Feb 20, 2018
1 parent eece624 commit f3695f8
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
99 changes: 99 additions & 0 deletions 1339.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
From 0327c7f9a3d3023bd0981fac40485d41f3dd94ed Mon Sep 17 00:00:00 2001
From: Romain Geissler <romain.geissler@gmail.com>
Date: Sat, 2 Dec 2017 22:47:20 +0100
Subject: [PATCH] Fix double free when building Gtest/GMock in shared libraries
and linking a test executable with both.

---
googlemock/CMakeLists.txt | 63 ++++++++++++++++++++++++++++++-----------------
1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt
index beb259a..1719d13 100644
--- a/googlemock/CMakeLists.txt
+++ b/googlemock/CMakeLists.txt
@@ -81,16 +81,23 @@ endif()
# Google Mock libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that Google Mock can be compiled by
# a user aggressive about warnings.
-cxx_library(gmock
- "${cxx_strict}"
- "${gtest_dir}/src/gtest-all.cc"
- src/gmock-all.cc)
-
-cxx_library(gmock_main
- "${cxx_strict}"
- "${gtest_dir}/src/gtest-all.cc"
- src/gmock-all.cc
- src/gmock_main.cc)
+if (MSVC)
+ cxx_library(gmock
+ "${cxx_strict}"
+ "${gtest_dir}/src/gtest-all.cc"
+ src/gmock-all.cc)
+
+ cxx_library(gmock_main
+ "${cxx_strict}"
+ "${gtest_dir}/src/gtest-all.cc"
+ src/gmock-all.cc
+ src/gmock_main.cc)
+else()
+ cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
+ target_link_libraries(gmock gtest)
+ cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
+ target_link_libraries(gmock_main gmock)
+endif()

# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled
@@ -154,23 +161,33 @@ if (gmock_build_tests)
############################################################
# C++ tests built with non-standard compiler flags.

- cxx_library(gmock_main_no_exception "${cxx_no_exception}"
- "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
-
- cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
- "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
+ if (MSVC)
+ cxx_library(gmock_main_no_exception "${cxx_no_exception}"
+ "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)

- 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(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
+ cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
"${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)

- cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
- gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
+ if (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(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
+ "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
+
+ cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
+ gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
+ endif()
+ else()
+ cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
+ target_link_libraries(gmock_main_no_exception gmock)
+
+ cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
+ target_link_libraries(gmock_main_no_rtti gmock)
+
+ cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc)
+ target_link_libraries(gmock_main_use_own_tuple gmock)
endif()
-
cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
gmock_main_no_exception test/gmock-more-actions_test.cc)

--
2.7.4.windows.1


4 changes: 3 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GTestConan(ConanFile):
url = "http://github.com/bincrafters/conan-gtest"
license = "BSD 3-Clause"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
exports_sources = ["CMakeLists.txt", "1339.patch"]
source_subfolder = "source_subfolder"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
Expand All @@ -29,6 +29,8 @@ def source(self):
extracted_dir = "googletest-release-" + self.version
os.rename(extracted_dir, self.source_subfolder)

tools.patch(base_path=self.source_subfolder, patch_file='1339.patch')

def build(self):

cmake = CMake(self)
Expand Down

0 comments on commit f3695f8

Please sign in to comment.