FindPython: Ensure SABIModule is found in all cases

Fixes: #26493
This commit is contained in:
Marc Chevrier
2024-12-02 17:37:18 +01:00
parent 27647acc6c
commit ff65c5fca0
2 changed files with 53 additions and 3 deletions

View File

@@ -3464,14 +3464,15 @@ if (("Development.Module" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS
endif()
# finalize library version information
_python_get_version (SABI_LIBRARY PREFIX _${_PYTHON_PREFIX}_)
# ABI library does not have the full version information
if (${_PYTHON_PREFIX}_Interpreter_FOUND OR _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
# update from interpreter or library
if (${_PYTHON_PREFIX}_Interpreter_FOUND AND NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
# update from interpreter
set (_${_PYTHON_PREFIX}_VERSION ${${_PYTHON_PREFIX}_VERSION})
set (_${_PYTHON_PREFIX}_VERSION_MAJOR ${${_PYTHON_PREFIX}_VERSION_MAJOR})
set (_${_PYTHON_PREFIX}_VERSION_MINOR ${${_PYTHON_PREFIX}_VERSION_MINOR})
set (_${_PYTHON_PREFIX}_VERSION_PATCH ${${_PYTHON_PREFIX}_VERSION_PATCH})
elseif(NOT _${_PYTHON_PREFIX}_LIBRARY_RELEASE)
_python_get_version (SABI_LIBRARY PREFIX _${_PYTHON_PREFIX}_)
endif()
set (${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE "${_${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE}")

View File

@@ -16,6 +16,55 @@ else()
set(USER_INCLUDE_DIR "/path/to/invalid/dir")
endif()
# check some combinations for modules search without interpreter
block(SCOPE_FOR VARIABLES)
find_package(Python3 REQUIRED COMPONENTS Development.SABIModule)
if (NOT Python3_FOUND)
message (FATAL_ERROR "Failed to find Python 3")
endif()
if (Python3_Development_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
endif()
if (Python3_Interpreter_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Interpreter' unexpectedly found")
endif()
if (Python3_Development.Embed_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
endif()
if (Python3_Development.Module_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' unexpectedly found")
endif()
if (NOT Python3_Development.SABIModule_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' not found")
endif()
unset(_Python3_SABI_LIBRARY_RELEASE CACHE)
endblock()
block(SCOPE_FOR VARIABLES)
find_package(Python3 REQUIRED COMPONENTS Development.Module Development.SABIModule)
if (NOT Python3_FOUND)
message (FATAL_ERROR "Failed to find Python 3")
endif()
if (Python3_Development_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development' unexpectedly found")
endif()
if (Python3_Interpreter_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Interpreter' unexpectedly found")
endif()
if (Python3_Development.Embed_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development.Embed' unexpectedly found")
endif()
if (NOT Python3_Development.Module_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development.Module' not found")
endif()
if (NOT Python3_Development.SABIModule_FOUND)
message (FATAL_ERROR "Python 3, COMPONENT 'Development.SABIModule' not found")
endif()
unset(_Python3_LIBRARY_RELEASE CACHE)
unset(_Python3_SABI_LIBRARY_RELEASE CACHE)
endblock()
set(components Interpreter Development)
if (CMake_TEST_FindPython3_SABIModule AND WIN32)
list (APPEND components Development.SABIModule)