Blame SOURCES/gtest-1.8.0-fix-double-free-with-shared-libs.patch

09583b
From 0663ce9024c9b78ddf6eb3fc1ceb45361ed91767 Mon Sep 17 00:00:00 2001
09583b
From: Romain Geissler <romain.geissler@gmail.com>
09583b
Date: Sat, 2 Dec 2017 22:47:20 +0100
09583b
Subject: [PATCH] Fix double free when building Gtest/GMock in shared libraries
09583b
 and linking a test executable with both.
09583b
09583b
---
09583b
 googlemock/CMakeLists.txt | 63 ++++++++++++++++++++++++++++++-----------------
09583b
 1 file changed, 40 insertions(+), 23 deletions(-)
09583b
09583b
diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt
09583b
index 724fdd5..f7bad8a 100644
09583b
--- a/googlemock/CMakeLists.txt
09583b
+++ b/googlemock/CMakeLists.txt
09583b
@@ -86,16 +86,23 @@ endif()
09583b
 # Google Mock libraries.  We build them using more strict warnings than what
09583b
 # are used for other targets, to ensure that Google Mock can be compiled by
09583b
 # a user aggressive about warnings.
09583b
-cxx_library(gmock
09583b
-            "${cxx_strict}"
09583b
-            "${gtest_dir}/src/gtest-all.cc"
09583b
-            src/gmock-all.cc)
09583b
-
09583b
-cxx_library(gmock_main
09583b
-            "${cxx_strict}"
09583b
-            "${gtest_dir}/src/gtest-all.cc"
09583b
-            src/gmock-all.cc
09583b
-            src/gmock_main.cc)
09583b
+if (MSVC)
09583b
+  cxx_library(gmock
09583b
+              "${cxx_strict}"
09583b
+              "${gtest_dir}/src/gtest-all.cc"
09583b
+              src/gmock-all.cc)
09583b
+
09583b
+  cxx_library(gmock_main
09583b
+              "${cxx_strict}"
09583b
+              "${gtest_dir}/src/gtest-all.cc"
09583b
+              src/gmock-all.cc
09583b
+              src/gmock_main.cc)
09583b
+else()
09583b
+  cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
09583b
+  target_link_libraries(gmock gtest)
09583b
+  cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
09583b
+  target_link_libraries(gmock_main gmock)
09583b
+endif()
09583b
 
09583b
 # If the CMake version supports it, attach header directory information
09583b
 # to the targets for when we are part of a parent build (ie being pulled
09583b
@@ -175,23 +182,33 @@ if (gmock_build_tests)
09583b
   ############################################################
09583b
   # C++ tests built with non-standard compiler flags.
09583b
 
09583b
-  cxx_library(gmock_main_no_exception "${cxx_no_exception}"
09583b
-    "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
09583b
-
09583b
-  cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
09583b
-    "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
09583b
+  if (MSVC)
09583b
+    cxx_library(gmock_main_no_exception "${cxx_no_exception}"
09583b
+      "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
09583b
 
09583b
-  if (NOT MSVC OR MSVC_VERSION LESS 1600)  # 1600 is Visual Studio 2010.
09583b
-    # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
09583b
-    # conflict with our own definitions. Therefore using our own tuple does not
09583b
-    # work on those compilers.
09583b
-    cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
09583b
+    cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
09583b
       "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
09583b
 
09583b
-    cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
09583b
-      gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
09583b
+    if (MSVC_VERSION LESS 1600)  # 1600 is Visual Studio 2010.
09583b
+      # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
09583b
+      # conflict with our own definitions. Therefore using our own tuple does not
09583b
+      # work on those compilers.
09583b
+      cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
09583b
+        "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
09583b
+
09583b
+      cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
09583b
+        gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
09583b
+    endif()
09583b
+  else()
09583b
+    cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
09583b
+    target_link_libraries(gmock_main_no_exception gmock)
09583b
+
09583b
+    cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
09583b
+    target_link_libraries(gmock_main_no_rtti gmock)
09583b
+
09583b
+    cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc)
09583b
+    target_link_libraries(gmock_main_use_own_tuple gmock)
09583b
   endif()
09583b
-
09583b
   cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
09583b
     gmock_main_no_exception test/gmock-more-actions_test.cc)
09583b
 
09583b
-- 
09583b
2.14.3
09583b