diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 4a8a4f0858..c659576f3c 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -1519,13 +1519,13 @@ unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS) unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_SABIMODULE_ARTIFACTS) unset (_${_PYTHON_PREFIX}_FIND_DEVELOPMENT_EMBED_ARTIFACTS) if ("Development.Module" IN_LIST ${_PYTHON_BASE}_FIND_COMPONENTS) - if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS)$") + if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS|Android)$") list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS "LIBRARY") endif() list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS "INCLUDE_DIR") endif() if ("Development.SABIModule" IN_LIST ${_PYTHON_BASE}_FIND_COMPONENTS) - if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS)$") + if (CMAKE_SYSTEM_NAME MATCHES "^(Windows.*|CYGWIN|MSYS|Android)$") list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_SABIMODULE_ARTIFACTS "SABI_LIBRARY") endif() list (APPEND _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_SABIMODULE_ARTIFACTS "INCLUDE_DIR") @@ -4351,7 +4351,7 @@ if(_${_PYTHON_PREFIX}_CMAKE_ROLE STREQUAL "PROJECT") if (${_PYTHON_PREFIX}_Development.Module_FOUND) if ("LIBRARY" IN_LIST _${_PYTHON_PREFIX}_FIND_DEVELOPMENT_MODULE_ARTIFACTS) - # On Windows/CYGWIN/MSYS, Python::Module is the same as Python::Python + # On Windows/CYGWIN/MSYS/Android, Python::Module is the same as Python::Python # but ALIAS cannot be used because the imported library is not GLOBAL. __python_import_library (${_PYTHON_PREFIX}::Module) else() diff --git a/Tests/RunCMake/FindPython/Android.cmake b/Tests/RunCMake/FindPython/Android.cmake new file mode 100644 index 0000000000..bafba7f032 --- /dev/null +++ b/Tests/RunCMake/FindPython/Android.cmake @@ -0,0 +1,51 @@ +enable_language(C) + +set(components Development.Embed Development.Module Development.SABIModule) +find_package(Python REQUIRED COMPONENTS ${components}) + +foreach(component ${components}) + set(found_var Python_${component}_FOUND) + if(NOT ${found_var}) + message(FATAL_ERROR "${found_var} is not set") + endif() +endforeach() + +set(android_root "${CMAKE_SOURCE_DIR}/android_root") +if(NOT Python_INCLUDE_DIRS STREQUAL "${android_root}/include/python3.13") + message(FATAL_ERROR "Python_INCLUDE_DIRS=${Python_INCLUDE_DIRS}") +endif() +if(NOT Python_LIBRARIES STREQUAL "${android_root}/lib/libpython3.13.so") + message(FATAL_ERROR "Python_LIBRARIES=${Python_LIBRARIES}") +endif() +if(NOT Python_SABI_LIBRARIES STREQUAL "${android_root}/lib/libpython3.so") + message(FATAL_ERROR "Python_SABI_LIBRARIES=${Python_SABI_LIBRARIES}") +endif() + +foreach(target Python::Python Python::Module Python::SABIModule) + if(NOT TARGET ${target}) + message(FATAL_ERROR "Target ${target} does not exist") + endif() + + # The Module and SABIModule targets will be SHARED_LIBRARY if Python modules should + # link against libpython (as on Android), and INTERFACE_LIBRARY if they should not (as + # on Linux). + get_target_property(target_type ${target} TYPE) + if(NOT target_type STREQUAL SHARED_LIBRARY) + message(FATAL_ERROR "${target} TYPE=${target_type}") + endif() + + get_target_property(target_location ${target} LOCATION) + if(target STREQUAL "Python::SABIModule") + set(expected "${android_root}/lib/libpython3.so") + else() + set(expected "${android_root}/lib/libpython3.13.so") + endif() + if(NOT target_location STREQUAL expected) + message(FATAL_ERROR "${target} LOCATION=${target_location}") + endif() + + get_target_property(target_include ${target} INTERFACE_INCLUDE_DIRECTORIES) + if(NOT target_include STREQUAL "${android_root}/include/python3.13") + message(FATAL_ERROR "${target} INTERFACE_INCLUDE_DIRECTORIES=${target_include}") + endif() +endforeach() diff --git a/Tests/RunCMake/FindPython/RunCMakeTest.cmake b/Tests/RunCMake/FindPython/RunCMakeTest.cmake index 5d3518f9aa..a4d667df81 100644 --- a/Tests/RunCMake/FindPython/RunCMakeTest.cmake +++ b/Tests/RunCMake/FindPython/RunCMakeTest.cmake @@ -322,6 +322,7 @@ if(CMake_TEST_FindPython_Various) run_python(ArtifactsInteractive VARIANT "OFF" OPTIONS -DCMake_TEST_FindPython3_NumPy=${CMake_TEST_FindPython3_NumPy} -DPython3_ARTIFACTS_INTERACTIVE=OFF) + run_python(Android OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/android_toolchain.cmake") endif() if(CMake_TEST_FindPython2 OR CMake_TEST_FindPython3) diff --git a/Tests/RunCMake/FindPython/android_root/README.txt b/Tests/RunCMake/FindPython/android_root/README.txt new file mode 100644 index 0000000000..ae55f9260e --- /dev/null +++ b/Tests/RunCMake/FindPython/android_root/README.txt @@ -0,0 +1 @@ +This directory contains a dummy Python installation tree for the Android test. diff --git a/Tests/RunCMake/FindPython/android_root/include/python3.13/Python.h b/Tests/RunCMake/FindPython/android_root/include/python3.13/Python.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/FindPython/android_root/include/python3.13/patchlevel.h b/Tests/RunCMake/FindPython/android_root/include/python3.13/patchlevel.h new file mode 100644 index 0000000000..9c7b8ded65 --- /dev/null +++ b/Tests/RunCMake/FindPython/android_root/include/python3.13/patchlevel.h @@ -0,0 +1 @@ +#define PY_VERSION "3.13.0" diff --git a/Tests/RunCMake/FindPython/android_root/include/python3.13/pyconfig.h b/Tests/RunCMake/FindPython/android_root/include/python3.13/pyconfig.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/FindPython/android_root/lib/libpython3.13.so b/Tests/RunCMake/FindPython/android_root/lib/libpython3.13.so new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/FindPython/android_root/lib/libpython3.so b/Tests/RunCMake/FindPython/android_root/lib/libpython3.so new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/FindPython/android_toolchain.cmake b/Tests/RunCMake/FindPython/android_toolchain.cmake new file mode 100644 index 0000000000..c588c16c8a --- /dev/null +++ b/Tests/RunCMake/FindPython/android_toolchain.cmake @@ -0,0 +1,8 @@ +set(CMAKE_SYSTEM_NAME Android) + +# This test doesn't require the NDK, so inhibit CMake's NDK handling code. +set(CMAKE_SYSTEM_VERSION 1) + +set(CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}/android_root") +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)