Skip to content

Commit 6a92b34

Browse files
henryiiimhsmith
andcommitted
fix: android CMake support
Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Malcolm Smith <[email protected]>
1 parent e2f86af commit 6a92b34

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

tools/pybind11NewTools.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ if(TARGET ${_Python}::Python)
243243
endif()
244244

245245
if(TARGET ${_Python}::Module)
246+
# On Android, older versions of CMake don't know that modules need to link against
247+
# libpython, so Python::Module will be an INTERFACE target with no associated library
248+
# files.
249+
get_target_property(module_target_type ${_Python}::Module TYPE)
250+
if(ANDROID AND module_target_type STREQUAL INTERFACE_LIBRARY)
251+
set_property(
252+
TARGET ${_Python}::Module
253+
APPEND
254+
PROPERTY INTERFACE_LINK_LIBRARIES "${${_Python}_LIBRARIES}")
255+
endif()
256+
246257
set_property(
247258
TARGET pybind11::module
248259
APPEND

tools/pybind11Tools.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ target_link_libraries(
119119
pybind11::module
120120
INTERFACE
121121
pybind11::python_link_helper
122-
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:pybind11::_ClassicPythonLibraries>")
122+
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>,$<PLATFORM_ID:Android>>:pybind11::_ClassicPythonLibraries>"
123+
)
123124

124125
target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11
125126
pybind11::_ClassicPythonLibraries)

0 commit comments

Comments
 (0)