1From cf5a3177159ca832470e7f876cab0a1923fa666f Mon Sep 17 00:00:00 2001
2From: Peter Seiderer <ps.report@gmx.net>
3Date: Fri, 22 Oct 2021 20:17:36 +0200
4Subject: [PATCH] pkg-config: fix gtest.pc/gmock.pc library names for the debug
5 build
6
7In case CMAKE_BUILD_TYPE is set to Debug the gtest library is
8name libgtestd.a but the link command returned from gtest.pc is
9'-lgtest' (without the debug d) and so the linking of dependent
10packages fails (see [1] for a buildroot failure example).
11
12Enhance the gtest.pc ang gmock.pc generation to honour the debug 'd'.
13
14[1] http://lists.busybox.net/pipermail/buildroot/2021-October/626382.html
15
16[Upstream: https://github.com/google/googletest/pull/3625]
17Signed-off-by: Peter Seiderer <ps.report@gmx.net>
18---
19 googlemock/cmake/gmock.pc.in          | 2 +-
20 googletest/cmake/gtest.pc.in          | 2 +-
21 googletest/cmake/internal_utils.cmake | 3 +++
22 3 files changed, 5 insertions(+), 2 deletions(-)
23
24diff --git a/googlemock/cmake/gmock.pc.in b/googlemock/cmake/gmock.pc.in
25index 23c67b5c..0f469857 100644
26--- a/googlemock/cmake/gmock.pc.in
27+++ b/googlemock/cmake/gmock.pc.in
28@@ -6,5 +6,5 @@ Description: GoogleMock (without main() function)
29 Version: @PROJECT_VERSION@
30 URL: https://github.com/google/googletest
31 Requires: gtest = @PROJECT_VERSION@
32-Libs: -L${libdir} -lgmock @CMAKE_THREAD_LIBS_INIT@
33+Libs: -L${libdir} -lgmock@DEBUG_POSTFIX@ @CMAKE_THREAD_LIBS_INIT@
34 Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@
35diff --git a/googletest/cmake/gtest.pc.in b/googletest/cmake/gtest.pc.in
36index b4148fae..225bba81 100644
37--- a/googletest/cmake/gtest.pc.in
38+++ b/googletest/cmake/gtest.pc.in
39@@ -5,5 +5,5 @@ Name: gtest
40 Description: GoogleTest (without main() function)
41 Version: @PROJECT_VERSION@
42 URL: https://github.com/google/googletest
43-Libs: -L${libdir} -lgtest @CMAKE_THREAD_LIBS_INIT@
44+Libs: -L${libdir} -lgtest@DEBUG_POSTFIX@ @CMAKE_THREAD_LIBS_INIT@
45 Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@
46diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake
47index 58fc9bfb..fd81b825 100644
48--- a/googletest/cmake/internal_utils.cmake
49+++ b/googletest/cmake/internal_utils.cmake
50@@ -335,6 +335,9 @@ function(install_project)
51     # Configure and install pkgconfig files.
52     foreach(t ${ARGN})
53       set(configured_pc "${generated_dir}/${t}.pc")
54+      if(CMAKE_BUILD_TYPE MATCHES Debug)
55+        set(DEBUG_POSTFIX "d")
56+      endif()
57       configure_file("${PROJECT_SOURCE_DIR}/cmake/${t}.pc.in"
58         "${configured_pc}" @ONLY)
59       install(FILES "${configured_pc}"
60--
612.33.1
62
63