Skip to content

Commit bbb89da

Browse files
authored
fix(cmake): support vcpkg, try 2 (#4123)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 5bdd3d5 commit bbb89da

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/pybind11Tools.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ if(PYTHON_IS_DEBUG)
115115
PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG)
116116
endif()
117117

118+
# The <3.11 code here does not support release/debug builds at the same time, like on vcpkg
118119
if(CMAKE_VERSION VERSION_LESS 3.11)
119120
set_property(
120121
TARGET pybind11::module
@@ -130,16 +131,19 @@ if(CMAKE_VERSION VERSION_LESS 3.11)
130131
APPEND
131132
PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
132133
else()
134+
# The IMPORTED INTERFACE library here is to ensure that "debug" and "release" get processed outside
135+
# of a generator expression - https://gitlab.kitware.com/cmake/cmake/-/issues/18424, as they are
136+
# target_link_library keywords rather than real libraries.
137+
add_library(pybind11::_ClassicPythonLibraries IMPORTED INTERFACE)
138+
target_link_libraries(pybind11::_ClassicPythonLibraries INTERFACE ${PYTHON_LIBRARIES})
133139
target_link_libraries(
134140
pybind11::module
135141
INTERFACE
136142
pybind11::python_link_helper
137-
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>"
138-
)
143+
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:pybind11::_ClassicPythonLibraries>")
139144

140145
target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11
141-
$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
142-
146+
pybind11::_ClassicPythonLibraries)
143147
endif()
144148

145149
function(pybind11_extension name)

0 commit comments

Comments
 (0)