From 996787940e75b13ed2f54db88241daf599e48518 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 17 Jun 2025 14:10:48 -0400 Subject: [PATCH] fix: android CMake support Signed-off-by: Henry Schreiner Co-authored-by: Malcolm Smith --- tools/pybind11NewTools.cmake | 11 +++++++++++ tools/pybind11Tools.cmake | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 087784c22c..e881ca7ca2 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -243,6 +243,17 @@ if(TARGET ${_Python}::Python) endif() if(TARGET ${_Python}::Module) + # On Android, older versions of CMake don't know that modules need to link against + # libpython, so Python::Module will be an INTERFACE target with no associated library + # files. + get_target_property(module_target_type ${_Python}::Module TYPE) + if(ANDROID AND module_target_type STREQUAL INTERFACE_LIBRARY) + set_property( + TARGET ${_Python}::Module + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES "${${_Python}_LIBRARIES}") + endif() + set_property( TARGET pybind11::module APPEND diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 8ef2dbb842..a51efb39fa 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -119,7 +119,8 @@ target_link_libraries( pybind11::module INTERFACE pybind11::python_link_helper - "$<$,$>:pybind11::_ClassicPythonLibraries>") + "$<$,$,$>:pybind11::_ClassicPythonLibraries>" +) target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11 pybind11::_ClassicPythonLibraries)