summaryrefslogtreecommitdiff
path: root/debian/patches/use_local_gtest.diff
blob: 9ccd231664fe323b6217b3e26b4f7c2451460593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
From: Benjamin Barenblat <bbaren@google.com>
Subject: Support testing with a local googletest checkout
Forwarded: yes
Applied-Upstream: https://github.com/abseil/abseil-cpp/commit/bcefbdcdf6ad85046ccacee0aeffba5404d3e528

Debian likes doing dependency management manually, so add support for
testing against a local googletest checkout rather than one downloaded
from GitHub. Add an ABSL_LOCAL_GOOGLETEST_DIR variable that can be used
in conjunction with -DABSL_RUN_TESTS=ON -DABSL_USE_GOOGLETEST_HEAD=OFF
to specify the googletest location manually, and do a bit of related
cleanup.

This patch was originally submitted as
https://github.com/abseil/abseil-cpp/pull/628. Since the author works at
Google, upstream requested that he submit it internally. It was applied
as Piper revision 297677173 and exported to GitHub; the Applied-Upstream
URL above points to the exported commit.

--- a/CMake/Googletest/CMakeLists.txt.in
+++ b/CMake/Googletest/CMakeLists.txt.in
@@ -1,15 +1,26 @@
 cmake_minimum_required(VERSION 2.8.2)
 
-project(googletest-download NONE)
+project(googletest-external NONE)
 
 include(ExternalProject)
-ExternalProject_Add(googletest
-  GIT_REPOSITORY    https://github.com/google/googletest.git
-  GIT_TAG           master
-  SOURCE_DIR        "${CMAKE_BINARY_DIR}/googletest-src"
-  BINARY_DIR        "${CMAKE_BINARY_DIR}/googletest-build"
-  CONFIGURE_COMMAND ""
-  BUILD_COMMAND     ""
-  INSTALL_COMMAND   ""
-  TEST_COMMAND      ""
-)
\ No newline at end of file
+if(${ABSL_USE_GOOGLETEST_HEAD})
+  ExternalProject_Add(googletest
+    GIT_REPOSITORY    https://github.com/google/googletest.git
+    GIT_TAG           master
+    SOURCE_DIR        "${absl_gtest_src_dir}"
+    BINARY_DIR        "${absl_gtest_build_dir}"
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND     ""
+    INSTALL_COMMAND   ""
+    TEST_COMMAND      ""
+  )
+else()
+  ExternalProject_Add(googletest
+    SOURCE_DIR        "${absl_gtest_src_dir}"
+    BINARY_DIR        "${absl_gtest_build_dir}"
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND     ""
+    INSTALL_COMMAND   ""
+    TEST_COMMAND      ""
+  )
+endif()
\ No newline at end of file
--- a/CMake/Googletest/DownloadGTest.cmake
+++ b/CMake/Googletest/DownloadGTest.cmake
@@ -1,10 +1,11 @@
-# Downloads and unpacks googletest at configure time.  Based on the instructions
-# at https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
+# Integrates googletest at configure time.  Based on the instructions at
+# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
 
-# Download the latest googletest from Github master
+# Set up the external googletest project, downloading the latest from Github
+# master if requested.
 configure_file(
   ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in
-  ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt
+  ${CMAKE_BINARY_DIR}/googletest-external/CMakeLists.txt
 )
 
 set(ABSL_SAVE_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
@@ -14,17 +15,17 @@ if (BUILD_SHARED_LIBS)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_CREATE_SHARED_LIBRARY=1")
 endif()
 
-# Configure and build the downloaded googletest source
+# Configure and build the googletest source.
 execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
   RESULT_VARIABLE result
-  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external )
 if(result)
   message(FATAL_ERROR "CMake step for googletest failed: ${result}")
 endif()
 
 execute_process(COMMAND ${CMAKE_COMMAND} --build .
   RESULT_VARIABLE result
-  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download)
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-external)
 if(result)
   message(FATAL_ERROR "Build step for googletest failed: ${result}")
 endif()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdfb2cf..74b5cd9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,6 +84,10 @@
 option(ABSL_USE_GOOGLETEST_HEAD
   "If ON, abseil will download HEAD from googletest at config time." OFF)
 
+set(ABSL_LOCAL_GOOGLETEST_DIR "/usr/src/googletest" CACHE PATH
+  "If ABSL_USE_GOOGLETEST_HEAD is OFF, specifies the directory of a local googletest checkout."
+  )
+
 option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
 
 if(${ABSL_RUN_TESTS})
@@ -96,11 +100,13 @@
 ## check targets
 if(BUILD_TESTING)
 
+  set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
   if(${ABSL_USE_GOOGLETEST_HEAD})
-    include(CMake/Googletest/DownloadGTest.cmake)
     set(absl_gtest_src_dir ${CMAKE_BINARY_DIR}/googletest-src)
-    set(absl_gtest_build_dir ${CMAKE_BINARY_DIR}/googletest-build)
+  else()
+    set(absl_gtest_src_dir ${ABSL_LOCAL_GOOGLETEST_DIR})
   endif()
+  include(CMake/Googletest/DownloadGTest.cmake)
 
   check_target(gtest)
   check_target(gtest_main)