Преглед на файлове

FindPython: Ensure SABIModule is found in all cases

Fixes: #26493
Marc Chevrier преди 11 месеца
родител
ревизия
ff65c5fca0
променени са 2 файла, в които са добавени 53 реда и са изтрити 3 реда
  1. 4 3
      Modules/FindPython/Support.cmake
  2. 49 0
      Tests/FindPython/RequiredArtifacts/CMakeLists.txt

+ 4 - 3
Modules/FindPython/Support.cmake

@@ -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}")

+ 49 - 0
Tests/FindPython/RequiredArtifacts/CMakeLists.txt

@@ -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)