From 713b89e13f5f087d0f0762d36b447518ac8c8546 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Mon, 17 Feb 2020 22:22:36 +0000
Subject: [PATCH 9/9] Avoid deprecated get_config_var(SO), use EXT_SUFFIX, look
 for _d lib when debug

---
 cmake/FindPythonLibsNew.cmake | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/cmake/FindPythonLibsNew.cmake b/cmake/FindPythonLibsNew.cmake
index 919a384..45853e5 100644
--- a/cmake/FindPythonLibsNew.cmake
+++ b/cmake/FindPythonLibsNew.cmake
@@ -79,7 +79,7 @@ print('.'.join(str(v) for v in sys.version_info));
 print(sys.prefix);
 print(s.get_python_inc(plat_specific=True));
 print(s.get_python_lib(plat_specific=True));
-print(s.get_config_var('SO'));
+print(s.get_config_var('EXT_SUFFIX'));
 print(hasattr(sys, 'gettotalrefcount')+0);
 print(struct.calcsize('@P'));
 print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
@@ -142,15 +142,20 @@ string(REGEX REPLACE "\\\\" "/" PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIR})
 string(REGEX REPLACE "\\\\" "/" PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES})
 
 if(CMAKE_HOST_WIN32)
+    # I would like something better here. Ideally PYTHON_LIBRARY_SUFFIX would be set correctly.
+    if(PYTHON_IS_DEBUG)
+        set(PYTHON_LIBRARY_SUFFIX "${PYTHON_LIBRARY_SUFFIX}_d")
+    endif()
+
     set(PYTHON_LIBRARY
-        "${PYTHON_PREFIX}/libs/Python${PYTHON_LIBRARY_SUFFIX}.lib")
+        "${PYTHON_PREFIX}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib")
 
     # when run in a venv, PYTHON_PREFIX points to it. But the libraries remain in the
     # original python installation. They may be found relative to PYTHON_INCLUDE_DIR.
     if(NOT EXISTS "${PYTHON_LIBRARY}")
         get_filename_component(_PYTHON_ROOT ${PYTHON_INCLUDE_DIR} DIRECTORY)
         set(PYTHON_LIBRARY
-            "${_PYTHON_ROOT}/libs/Python${PYTHON_LIBRARY_SUFFIX}.lib")
+            "${_PYTHON_ROOT}/libs/python${PYTHON_LIBRARY_SUFFIX}.lib")
     endif()
 
     # raise an error if the python libs are still not found.
-- 
2.24.1

