From c483c58276e27b720fdc79768ef014269744d1f5 Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <seth@kipro-pcb.com>
Date: Mon, 20 Jun 2022 16:20:01 -0700
Subject: Patch pybind11 for MSVC
Re-comit of earlier ef38642bf1 after updating pybind11 to 2.9.2
diff --git a/thirdparty/pybind11/include/pybind11/detail/common.h b/thirdparty/pybind11/include/pybind11/detail/common.h
index 6e8cfd4922..55d4772230 100644
--- a/thirdparty/pybind11/include/pybind11/detail/common.h
+++ b/thirdparty/pybind11/include/pybind11/detail/common.h
@@ -153,7 +153,6 @@
# define HAVE_SNPRINTF 1
#endif
-/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
#if defined(_MSC_VER)
# pragma warning(push)
// C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
@@ -170,6 +169,7 @@
# define PYBIND11_DEBUG_MARKER
# undef _DEBUG
# endif
+# pragma warning(disable: 4510 4610 4512 4005)
#endif
// https://en.cppreference.com/w/c/chrono/localtime
diff --git a/thirdparty/pybind11/tools/FindPythonLibsNew.cmake b/thirdparty/pybind11/tools/FindPythonLibsNew.cmake
index b5f0e93961..32b41f988f 100644
--- a/thirdparty/pybind11/tools/FindPythonLibsNew.cmake
+++ b/thirdparty/pybind11/tools/FindPythonLibsNew.cmake
@@ -201,6 +201,21 @@ if(CMAKE_HOST_WIN32)
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")
+ elseif(DEFINED VCPKG_TOOLCHAIN AND NOT EXISTS "${PYTHON_LIBRARY}")
+ set(PYTHON_LIBRARY "${PYTHON_PREFIX}/../../lib/python${PYTHON_LIBRARY_SUFFIX}.lib")
+ endif()
+
+ if(DEFINED VCPKG_TOOLCHAIN)
+ unset(PYTHON_LIBRARY)
+ find_library(
+ PYTHON_LIBRARY
+ NAMES "python${PYTHON_LIBRARY_SUFFIX}"
+ NO_SYSTEM_ENVIRONMENT_PATH)
+
+ find_library(PYTHON_DEBUG_LIBRARY
+ NAMES python${PYTHON_LIBRARY_SUFFIX}_d
+ NO_SYSTEM_ENVIRONMENT_PATH
+ )
endif()
# if we are in MSYS & MINGW, and we didn't find windows python lib, look for system python lib
@@ -246,7 +261,7 @@ else()
endif()
endif()
-mark_as_advanced(PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
+mark_as_advanced(PYTHON_DEBUG_LIBRARY PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the
# cache entries because they are meant to specify the location of a single
@@ -259,6 +274,10 @@ if(NOT PYTHON_DEBUG_LIBRARY)
endif()
set(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
+set(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}")
+set(PYTHON_LIBRARY_RELEASE, "${PYTHON_LIBRARY}")
+select_library_configurations(PYTHON)
+
find_package_message(PYTHON "Found PythonLibs: ${PYTHON_LIBRARY}"
"${PYTHON_EXECUTABLE}${PYTHON_VERSION_STRING}")
diff --git a/thirdparty/pybind11/tools/pybind11Tools.cmake b/thirdparty/pybind11/tools/pybind11Tools.cmake
index c255e5cfd8..61d52c301b 100644
--- a/thirdparty/pybind11/tools/pybind11Tools.cmake
+++ b/thirdparty/pybind11/tools/pybind11Tools.cmake
@@ -119,8 +119,11 @@ set_property(
TARGET pybind11::module
APPEND
PROPERTY
- INTERFACE_LINK_LIBRARIES pybind11::python_link_helper
- "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>")
+ INTERFACE_LINK_LIBRARIES pybind11::python_link_helper)
+
+if(WIN32)
+ target_link_libraries(pybind11::module INTERFACE ${PYTHON_LIBRARIES})
+endif()
if(PYTHON_VERSION VERSION_LESS 3)
set_property(
@@ -129,10 +132,13 @@ if(PYTHON_VERSION VERSION_LESS 3)
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python2_no_register)
endif()
+# KiCad Workaround, this ends tying release libraries into debug builds which doesn't end well
set_property(
TARGET pybind11::embed
APPEND
- PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
+ PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11)
+
+target_link_libraries(pybind11::embed INTERFACE ${PYTHON_LIBRARIES})
function(pybind11_extension name)
# The prefix and extension are provided by FindPythonLibsNew.cmake