From 2834cea1552e912f322003b93d3355b5a24f3773 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 17 Mar 2022 11:57:24 +0100 Subject: FindPython: fix various problems using pypy interpreters * add more possible directories for include file search * enhance version detection from library and include files * search for file pypy_decl.h when PyPy.h is not defined --- Modules/FindPython/Support.cmake | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index b7a0ef6..afe9743 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -280,26 +280,26 @@ function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES) if (CMAKE_LIBRARY_ARCHITECTURE) set (suffixes "${abi}") if (suffixes) - list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") + list (TRANSFORM suffixes PREPEND "lib/python${version}/config-${version}") list (TRANSFORM suffixes APPEND "-${CMAKE_LIBRARY_ARCHITECTURE}") else() - set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}-${CMAKE_LIBRARY_ARCHITECTURE}") + set (suffixes "lib/python${version}/config-${version}-${CMAKE_LIBRARY_ARCHITECTURE}") endif() list (APPEND path_suffixes ${suffixes}) endif() set (suffixes "${abi}") if (suffixes) - list (TRANSFORM suffixes PREPEND "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") + list (TRANSFORM suffixes PREPEND "lib/python${version}/config-${version}") else() - set (suffixes "lib/python${_PGPS_VERSION}/config-${_PGPS_VERSION}") + set (suffixes "lib/python${version}/config-${version}") endif() list (APPEND path_suffixes ${suffixes}) elseif (_PGPS_INCLUDE) set (suffixes "${abi}") if (suffixes) - list (TRANSFORM suffixes PREPEND "include/python${_PGPS_VERSION}") + list (TRANSFORM suffixes PREPEND "include/python${version}") else() - set (suffixes "include/python${_PGPS_VERSION}") + set (suffixes "include/python${version}") endif() list (APPEND path_suffixes ${suffixes} include) endif() @@ -318,6 +318,9 @@ function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES) elseif (_PGPS_LIBRARY) list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES}) elseif (_PGPS_INCLUDE) + foreach (version IN LISTS _PGPS_VERSION) + list (APPEND path_suffixes lib/pypy${version}/include pypy${version}/include) + endforeach() list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES}) endif() endif() @@ -587,7 +590,13 @@ function (_PYTHON_GET_VERSION) set (${_PGV_PREFIX}ABI "${CMAKE_MATCH_3}" PARENT_SCOPE) elseif (library_name MATCHES "pypy(3)?-c") set (version "${CMAKE_MATCH_1}") - if (version EQUAL "3") + # try to pick-up a more precise version from the path + get_filename_component (library_dir "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY) + if (library_dir MATCHES "/pypy([23])\\.([0-9]+)/") + set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE) + set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE) + set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE) + elseif (version EQUAL "3") set (${_PGV_PREFIX}VERSION_MAJOR "3" PARENT_SCOPE) set (${_PGV_PREFIX}VERSION "3" PARENT_SCOPE) else() @@ -1265,7 +1274,7 @@ if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3") # special name for runtime part list (APPEND _${_PYTHON_PREFIX}_PYPY_LIB_NAMES libpypy3-c) endif() - set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy3) + set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy3/include pypy3/include) else() set (_${_PYTHON_PREFIX}_PYPY_NAMES pypy) set (_${_PYTHON_PREFIX}_PYPY_LIB_NAMES pypy-c) @@ -1273,8 +1282,9 @@ else() # special name for runtime part list (APPEND _${_PYTHON_PREFIX}_PYPY_LIB_NAMES libpypy-c) endif() - set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy) + set (_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES lib/pypy/include pypy/include) endif() +list (APPEND _${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES libexec/include) set (_${_PYTHON_PREFIX}_PYPY_EXECUTABLE_PATH_SUFFIXES bin) set (_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES lib libs bin) list (APPEND _${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES include) @@ -1303,7 +1313,7 @@ foreach (_${_PYTHON_PREFIX}_IMPLEMENTATION IN LISTS _${_PYTHON_PREFIX}_FIND_IMPL if (_${_PYTHON_PREFIX}_IMPLEMENTATION STREQUAL "CPython") list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "Python.h") elseif (_${_PYTHON_PREFIX}_IMPLEMENTATION STREQUAL "PyPy") - list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "PyPy.h") + list (APPEND _${_PYTHON_PREFIX}_INCLUDE_NAMES "PyPy.h" "pypy_decl.h") endif() endforeach() @@ -2921,6 +2931,11 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS # update versioning set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION}) set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH}) + elseif (_${_PYTHON_PREFIX}_VERSION VERSION_EQUAL _${_PYTHON_PREFIX}_INC_VERSION_MAJOR) + # library specify only major version, use include file for full version information + set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION}) + set (_${_PYTHON_PREFIX}_VERSION_MINOR ${_${_PYTHON_PREFIX}_INC_VERSION_MINOR}) + set (_${_PYTHON_PREFIX}_VERSION_PATCH ${_${_PYTHON_PREFIX}_INC_VERSION_PATCH}) endif() else() set (_${_PYTHON_PREFIX}_VERSION ${_${_PYTHON_PREFIX}_INC_VERSION}) -- cgit v0.12