[PATCH 1/2] cmake: always set GTEST_LIBRARY if it isn't
authorVictor Berger <victor.berger@m4x.org>
Thu, 8 Jul 2021 17:25:23 +0000 (19:25 +0200)
committerPeter Michael Green <plugwash@raspbian.org>
Sun, 9 Jan 2022 23:11:32 +0000 (23:11 +0000)
Previously, the GTEST_LIBRARY would only be set manually set when
GMock is not built from source, causing likage failures on systems
where Gmock is built from source and system-provided GTest does not
set it.

cc #205

Gbp-Pq: Name 0001-cmake-always-set-GTEST_LIBRARY-if-it-isn-t.patch

cmake/FindGtestGmock.cmake

index a57fed8766b4b34bad378d4a2279db867fe43502..359f9aba61ac6f5592c1b3cb947506f3ecf18ea0 100644 (file)
@@ -39,6 +39,12 @@ if (NOT GTEST_FOUND)
     find_package_handle_standard_args(GTest GTEST_LIBRARY GTEST_BOTH_LIBRARIES GTEST_INCLUDE_DIRS)
 endif()
 
+# Upstream GTestConfig.cmake doesn't provide GTEST_LIBRARY but GTEST_LIBRARIES
+# CMake 3.20+ uses the upstream gtest config if possible.
+if (NOT DEFINED GTEST_LIBRARY)
+    set(GTEST_LIBRARY ${GTEST_LIBRARIES})
+endif()
+
 find_file(GMOCK_SOURCE
         NAMES gmock-all.cc
         DOC "GMock source"
@@ -63,11 +69,6 @@ if (EXISTS ${GMOCK_SOURCE})
 else()
     # Assume gmock is no longer source, we'll find out soon enough if that's wrong
     add_custom_target(GMock)
-    # Upstream GTestConfig.cmake doesn't provide GTEST_LIBRARY but GTEST_LIBRARIES
-    # CMake 3.20+ uses the upstream gtest config if possible.
-    if (NOT DEFINED GTEST_LIBRARY)
-        set(GTEST_LIBRARY ${GTEST_LIBRARIES})
-    endif()
     string(REPLACE gtest gmock GMOCK_LIBRARY ${GTEST_LIBRARY})
 endif()