diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2022-11-15 08:48:26 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2022-11-15 15:54:44 (GMT) |
commit | 328d847f7032f08334e3558a25ee60e7298f88dd (patch) | |
tree | 144d7cb9fcc8367a4f57d31a0605b28fddcdbd4d /Modules | |
parent | 88c4006f054bd3a2233ce607e22d961f106c3512 (diff) | |
download | CMake-328d847f7032f08334e3558a25ee60e7298f88dd.zip CMake-328d847f7032f08334e3558a25ee60e7298f88dd.tar.gz CMake-328d847f7032f08334e3558a25ee60e7298f88dd.tar.bz2 |
FindPython: enhance SOABI computation
Fixes: #24121, #23651
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindPython.cmake | 11 | ||||
-rw-r--r-- | Modules/FindPython/Support.cmake | 39 | ||||
-rw-r--r-- | Modules/FindPython3.cmake | 9 |
3 files changed, 40 insertions, 19 deletions
diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index d98bc95..3fb56e4 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -139,12 +139,11 @@ This module will set the following variables in your project Extension suffix for modules. - Information returned by - ``distutils.sysconfig.get_config_var('SOABI')`` or computed from - ``distutils.sysconfig.get_config_var('EXT_SUFFIX')`` or - ``python-config --extension-suffix``. If package ``distutils.sysconfig`` is - not available, ``sysconfig.get_config_var('SOABI')`` or - ``sysconfig.get_config_var('EXT_SUFFIX')`` are used. + Information computed from ``distutils.sysconfig.get_config_var('EXT_SUFFIX')`` + or ``distutils.sysconfig.get_config_var('SOABI')`` or + ``python3-config --extension-suffix``. If package ``distutils.sysconfig`` is + not available, ``sysconfig.get_config_var('EXT_SUFFIX')`` or + ``sysconfig.get_config_var('SOABI')`` are used. ``Python_Compiler_FOUND`` System has the Python compiler. diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 7a127e4..9b78220 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -508,21 +508,16 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) list (REMOVE_DUPLICATES _values) endif() elseif (NAME STREQUAL "SOABI") + # first step: compute SOABI form EXT_SUFFIX config variable execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c - "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '',sysconfig.get_config_var('SO') or '']))\nexcept Exception:\n import sysconfig;sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('EXT_SUFFIX') or '',sysconfig.get_config_var('SO') or '']))" + "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(sysconfig.get_config_var('EXT_SUFFIX') or '')\nexcept Exception:\n import sysconfig;sys.stdout.write(sysconfig.get_config_var('EXT_SUFFIX') or '')" RESULT_VARIABLE _result - OUTPUT_VARIABLE _soabi + OUTPUT_VARIABLE _values ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if (_result) unset (_values) else() - foreach (_item IN LISTS _soabi) - if (_item) - set (_values "${_item}") - break() - endif() - endforeach() if (_values) # clean-up: remove prefix character and suffix if (_values MATCHES "^(\\.${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$") @@ -532,6 +527,34 @@ function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME) endif() endif() endif() + + # second step: use SOABI or SO config variables as fallback + if (NOT _values) + execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c + "import sys\ntry:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('SO') or '']))\nexcept Exception:\n import sysconfig;sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('SO') or '']))" + RESULT_VARIABLE _result + OUTPUT_VARIABLE _soabi + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (_result) + unset (_values) + else() + foreach (_item IN LISTS _soabi) + if (_item) + set (_values "${_item}") + break() + endif() + endforeach() + if (_values) + # clean-up: remove prefix character and suffix + if (_values MATCHES "^(\\.${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$") + set(_values "") + else() + string (REGEX REPLACE "^[.-](.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}") + endif() + endif() + endif() + endif() else() set (config_flag "${NAME}") if (NAME STREQUAL "CONFIGDIR") diff --git a/Modules/FindPython3.cmake b/Modules/FindPython3.cmake index 75b7a34..837300e 100644 --- a/Modules/FindPython3.cmake +++ b/Modules/FindPython3.cmake @@ -140,12 +140,11 @@ This module will set the following variables in your project Extension suffix for modules. - Information returned by - ``distutils.sysconfig.get_config_var('SOABI')`` or computed from - ``distutils.sysconfig.get_config_var('EXT_SUFFIX')`` or + Information computed from ``distutils.sysconfig.get_config_var('EXT_SUFFIX')`` + or ``distutils.sysconfig.get_config_var('SOABI')`` or ``python3-config --extension-suffix``. If package ``distutils.sysconfig`` is - not available, ``sysconfig.get_config_var('SOABI')`` or - ``sysconfig.get_config_var('EXT_SUFFIX')`` are used. + not available, ``sysconfig.get_config_var('EXT_SUFFIX')`` or + ``sysconfig.get_config_var('SOABI')`` are used. ``Python3_Compiler_FOUND`` System has the Python 3 compiler. |