From a0643f3e98c47c55920ab08e26dc3af0ad68ddba Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 8 Aug 2022 09:52:40 -0400 Subject: [PATCH] fix(cmake): support vcpkg, try 2 Signed-off-by: Henry Schreiner --- tools/pybind11Tools.cmake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 5535e872f3..bbbd1656b6 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -115,6 +115,7 @@ if(PYTHON_IS_DEBUG) PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG) endif() +# The <3.11 code here does not support release/debug builds at the same time, like on vcpkg if(CMAKE_VERSION VERSION_LESS 3.11) set_property( TARGET pybind11::module @@ -130,16 +131,19 @@ if(CMAKE_VERSION VERSION_LESS 3.11) APPEND PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11 $) else() + # The IMPORTED INTERFACE library here is to ensure that "debug" and "release" get processed outside + # of a generator expression - https://gitlab.kitware.com/cmake/cmake/-/issues/18424, as they are + # target_link_library keywords rather than real libraries. + add_library(pybind11::_ClassicPythonLibraries IMPORTED INTERFACE) + target_link_libraries(pybind11::_ClassicPythonLibraries INTERFACE ${PYTHON_LIBRARIES}) target_link_libraries( pybind11::module INTERFACE pybind11::python_link_helper - "$<$,$>:$>" - ) + "$<$,$>:pybind11::_ClassicPythonLibraries>") target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11 - $) - + pybind11::_ClassicPythonLibraries) endif() function(pybind11_extension name)