summaryrefslogtreecommitdiff
blob: b17385bdcd834470768119b8861f839837495a7c (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
--- a/CMakeLists.txt	2018-08-11 09:54:05.000000000 +0200
+++ b/CMakeLists.txt	2018-08-22 10:48:06.422755215 +0200
@@ -91,6 +91,7 @@
 # Configurable options:
 option (NO_YUBI "Set ON to disable YubiKey support" OFF)
 option (NO_GTEST "Set ON to disable gtest unit testing" OFF)
+option (SYSTEM_GTEST "Set ON to use gtest provided by the system" OFF)
 
 if (WIN32)
   option (WX_WINDOWS "Build wxWidget under Windows" OFF)
@@ -256,31 +257,36 @@
 endif (MSVC)
 
 if (NOT NO_GTEST)
-   # Download and unpack googletest at configure time
-   # See https://crascit.com/2015/07/25/cmake-gtest/
-   configure_file(Misc/CMakeLists.gtest.txt.in googletest-download/CMakeLists.txt)
-   execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
+  if (NOT SYSTEM_GTEST)
+    # Download and unpack googletest at configure time
+    # See https://crascit.com/2015/07/25/cmake-gtest/
+    configure_file(Misc/CMakeLists.gtest.txt.in googletest-download/CMakeLists.txt)
+    execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" )
-   execute_process(COMMAND "${CMAKE_COMMAND}" --build .
+     execute_process(COMMAND "${CMAKE_COMMAND}" --build .
        WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" )
+    # Prevent GoogleTest from overriding our compiler/linker options
+    # when building with Visual Studio
+    set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+    # Set some other gtest configurations:
+    set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
+    set(BUILD_GTEST ON CACHE BOOL "" FORCE)
+    set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
+
+    # Add googletest directly to our build. This adds
+    # the following targets: gtest, gtest_main, gmock
+    # and gmock_main
+    add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
+                     "${CMAKE_BINARY_DIR}/googletest-build")
+
+    include_directories("${gtest_SOURCE_DIR}/include"
+#                        "${gmock_SOURCE_DIR}/include"
+                        )
+  else (NOT SYSTEM_GTEST)
+    find_package(GTest REQUIRED)
+    set(GTEST_LIBRARIES ${GTEST_BOTH_LIBRARIES})
+  endif(NOT SYSTEM_GTEST)
 
-   # Prevent GoogleTest from overriding our compiler/linker options
-   # when building with Visual Studio
-   set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-   # Set some other gtest configurations:
-   set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
-   set(BUILD_GTEST ON CACHE BOOL "" FORCE)
-   set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
-
-   # Add googletest directly to our build. This adds
-   # the following targets: gtest, gtest_main, gmock
-   # and gmock_main
-   add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
-                    "${CMAKE_BINARY_DIR}/googletest-build")
-
-   include_directories("${gtest_SOURCE_DIR}/include"
-#                       "${gmock_SOURCE_DIR}/include"
-                       )
 endif(NOT NO_GTEST)
 
 if (WIN32 AND NOT WX_WINDOWS)