FindPython: Add support for pydebug ABI flag on Windows

Fixes: #27969
This commit is contained in:
Marc Chevrier
2026-07-26 17:10:25 +02:00
parent 2a49f821f3
commit 84cb7e2629
4 changed files with 125 additions and 48 deletions
+11
View File
@@ -432,3 +432,14 @@ Other Changes
* Targets which provide C++ modules may now be consumed by targets with
different :prop_tgt:`compile features <COMPILE_FEATURES>` and
:prop_tgt:`options <COMPILE_OPTIONS>` than the provider.
Updates
=======
Changes made since CMake 4.4.0 include the following.
4.4.1
-----
* The :module:`FindPython`, :module:`FindPython3` modules learned to manage, on
``Windows`` systems, the ``pydebug`` ABI flag.
+29 -14
View File
@@ -183,7 +183,7 @@ This module defines the following variables
* IronPython
* PyPy
``Python3_FREE_THREADED``
``Python_FREE_THREADED``
.. versionadded:: 4.4
Boolean value, which is ``true`` if the python is free threaded (i.e.
@@ -363,6 +363,10 @@ Hints
threaded python), is added and is optional. If not specified, the value is
``OFF``.
.. versionadded:: 4.4.1
The ``pydebug`` flag is now supported on ``Windows`` systems for ``Python``
3.14+.
Each element can be set to one of the following:
* ``ON``: Corresponding flag is selected.
@@ -371,8 +375,10 @@ Hints
.. note::
If ``Python3_FIND_ABI`` is not defined, any ABI, excluding the
``gil_disabled`` flag, will be searched.
If ``Python_FIND_ABI`` is not defined, the following default apply:
* On ``POSIX`` systems: ``ANY``, ``ANY``, ``ANY``, ``OFF``.
* On ``Windows`` systems: ``OFF``, ``OFF``, ``OFF``, ``OFF``.
From this 4-tuple, various ABIs will be searched starting from the most
specialized to the most general. Moreover, when ``ANY`` is specified for
@@ -386,7 +392,10 @@ Hints
set (Python_FIND_ABI "ON" "ANY" "ANY" "ON")
The following flags combinations will be appended, in that order, to the
artifact names: ``tdmu``, ``tdm``, ``tdu``, and ``td``.
artifact names:
* On ``POSIX`` systems: ``tdmu``, ``tdm``, ``tdu``, and ``td``.
* On ``Windows`` systems: ``tmu_d``, ``tm_d``, ``tu_d``, and ``t_d``.
And to search any possible ABIs:
@@ -394,18 +403,24 @@ Hints
set (Python_FIND_ABI "ANY" "ANY" "ANY" "ANY")
The following combinations, in that order, will be used: ``mu``, ``m``,
``u``, ``<empty>``, ``dmu``, ``dm``, ``du``, ``d``, ``tmu``, ``tm``, ``tu``,
``t``, ``tdmu``, ``tdm``, ``tdu``, and ``td``.
The following combinations, in that order, will be used:
* On ``POSIX`` systems: ``mu``, ``m``, ``u``, ``<empty>``, ``dmu``, ``dm``,
``du``, ``d``, ``tmu``, ``tm``, ``tu``, ``t``, ``tdmu``, ``tdm``, ``tdu``,
and ``td``.
* On ``Windows`` systems: ``mu``, ``m``, ``u``, ``<empty>``, ``mu_d``,
``m_d``, ``u_d``, ``_d``, ``tmu``, ``tm``, ``tu``, ``t``, ``tmu_d``, ``tm_d``,
``tu_d``, and ``t_d``.
.. note::
This hint is useful only on ``POSIX`` systems except for the
``gil_disabled`` flag. So, on ``Windows`` systems,
when ``Python_FIND_ABI`` is defined, ``Python`` distributions from
`python.org <https://www.python.org/>`_ will be found only if the value for
each flag is ``OFF`` or ``ANY`` except for the fourth one
(``gil_disabled``).
This hint is fully usable on ``POSIX`` systems. On ``Windows`` systems,
only the ``gil_disabled`` and ``pydebug`` flags are supported. Moreover,
the ``pydebug`` flag is only supported for ``Python`` 3.14+. So, on
``Windows`` systems, when ``Python_FIND_ABI`` is defined, ``Python``
distributions from `python.org <https://www.python.org/>`_ will be found
only if the value for the flags ``pymalloc`` and ``unicode`` is ``OFF`` or
``ANY``.
``Python_FIND_STRATEGY``
.. versionadded:: 3.15
@@ -659,7 +674,7 @@ If the library type is not specified, ``MODULE`` is assumed.
was introduced. Specifying only major version ``3`` is equivalent to ``3.2``.
.. versionchanged:: 4.4
When ``USE_SABI`` is specified, if ``Python3_FREE_THREADED`` is ``true`` and
When ``USE_SABI`` is specified, if ``Python_FREE_THREADED`` is ``true`` and
Python version is ``3.15`` or upper, ``Py_TARGET_ABI3T`` preprocessor
definition will be defined rather than ``Py_LIMITED_API`` (see :pep:`803` for
more details).
+58 -22
View File
@@ -312,18 +312,36 @@ function (_PYTHON_GET_ABIFLAGS _PGA_FIND_ABI _PGABIFLAGS)
endif()
if (pydebug STREQUAL "ON")
if (abiflags)
list (TRANSFORM abiflags PREPEND "d")
if (WIN32)
if (NOT abiflags STREQUAL "<none>")
list (TRANSFORM abiflags APPEND "_d")
else()
set (abiflags "_d")
endif()
else()
set (abiflags "d")
if (NOT abiflags STREQUAL "<none>")
list (TRANSFORM abiflags PREPEND "d")
else()
set (abiflags "d")
endif()
endif()
elseif (pydebug STREQUAL "ANY")
if (abiflags)
set (flags "${abiflags}")
list (TRANSFORM flags PREPEND "d")
list (APPEND abiflags "${flags}")
if (WIN32)
if (NOT abiflags STREQUAL "<none>")
set (flags "${abiflags}")
list (TRANSFORM flags APPEND "_d")
list (APPEND abiflags "${flags}")
else()
set (abiflags "<none>" "_d")
endif()
else()
set (abiflags "<none>" "d")
if (NOT abiflags STREQUAL "<none>")
set (flags "${abiflags}")
list (TRANSFORM flags PREPEND "d")
list (APPEND abiflags "${flags}")
else()
set (abiflags "<none>" "d")
endif()
endif()
endif()
@@ -434,12 +452,26 @@ function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES)
foreach (implementation IN LISTS _PGN_IMPLEMENTATIONS)
if (implementation STREQUAL "CPython")
set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
list (TRANSFORM abi REPLACE "^<none>$" "")
set (unversionednames python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
if (_PGN_INTERPRETER AND _${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES STREQUAL "FIRST")
if (_PGN_DEBUG)
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}_d python_d)
if (abi)
unset (fullnames)
foreach (name IN LISTS unversionednames)
set (abinames "${abi}")
list (TRANSFORM abinames PREPEND "${name}")
list(APPEND fullnames "${abinames}")
endforeach()
else()
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
set (fullnames ${unversionednames})
endif()
if (_PGN_DEBUG AND NOT abi MATCHES "_d")
list (TRANSFORM fullnames APPEND "_d")
endif()
list (APPEND names ${fullnames})
endif()
foreach (version IN LISTS _PGN_VERSION)
if (_PGN_WIN32)
@@ -448,24 +480,19 @@ function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES)
else()
string (REPLACE "." "" name_version ${version})
endif()
set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
list (TRANSFORM abi REPLACE "^<none>$" "")
if (abi)
set (abinames "${abi}")
list (TRANSFORM abinames PREPEND "python${name_version}")
else()
set (abinames "python${name_version}")
endif()
if (_PGN_DEBUG)
if (_PGN_DEBUG AND NOT abi MATCHES "_d")
list (TRANSFORM abinames APPEND "_d")
endif()
list (APPEND names ${abinames})
endif()
if (_PGN_POSIX)
set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
list (TRANSFORM abi REPLACE "^<none>$" "")
if (abi)
if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
set (abinames "${abi}")
@@ -493,11 +520,20 @@ function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES)
endif()
endforeach()
if (_PGN_INTERPRETER AND _${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES STREQUAL "LAST")
if (_PGN_DEBUG)
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}_d python_d)
if (abi)
unset (fullnames)
foreach (name IN LISTS unversionednames)
set (abinames "${abi}")
list (TRANSFORM abinames PREPEND "${name}")
list(APPEND fullnames "${abinames}")
endforeach()
else()
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
set (fullnames ${unversionednames})
endif()
if (_PGN_DEBUG AND NOT abi MATCHES "_d")
list (TRANSFORM fullnames APPEND "_d")
endif()
list(APPEND names ${fullnames})
endif()
elseif (implementation STREQUAL "IronPython")
if (_PGN_INTERPRETER)
@@ -831,7 +867,7 @@ function (_PYTHON_GET_VERSION)
if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
get_filename_component (library_name "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" NAME)
# extract version from library name
if (library_name MATCHES "python([23])([0-9]+)([tdmu]*)")
if (library_name MATCHES "python([23])([0-9]+)([tdmu_]*)")
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)
@@ -867,7 +903,7 @@ function (_PYTHON_GET_VERSION)
if (_${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE)
get_filename_component (library_name "${_${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE}" NAME)
# extract version from library name
if (library_name MATCHES "python([23])([tdmu]*)")
if (library_name MATCHES "python([23])([tdmu_]*)")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (abi "${CMAKE_MATCH_2}")
+27 -12
View File
@@ -362,6 +362,10 @@ Hints
threaded python), is added and is optional. If not specified, the value is
``OFF``.
.. versionadded:: 4.4.1
The ``pydebug`` flag is now supported on ``Windows`` systems for ``Python``
3.14+.
Each element can be set to one of the following:
* ``ON``: Corresponding flag is selected.
@@ -370,8 +374,10 @@ Hints
.. note::
If ``Python3_FIND_ABI`` is not defined, any ABI, excluding the
``gil_disabled`` flag, will be searched.
If ``Python3_FIND_ABI`` is not defined, the following default apply:
* On ``POSIX`` systems: ``ANY``, ``ANY``, ``ANY``, ``OFF``.
* On ``Windows`` systems: ``OFF``, ``OFF``, ``OFF``, ``OFF``.
From this 4-tuple, various ABIs will be searched starting from the most
specialized to the most general. Moreover, when ``ANY`` is specified for
@@ -385,7 +391,10 @@ Hints
set (Python3_FIND_ABI "ON" "ANY" "ANY" "ON")
The following flags combinations will be appended, in that order, to the
artifact names: ``tdmu``, ``tdm``, ``tdu``, and ``td``.
artifact names:
* On ``POSIX`` systems: ``tdmu``, ``tdm``, ``tdu``, and ``td``.
* On ``Windows`` systems: ``tmu_d``, ``tm_d``, ``tu_d``, and ``t_d``.
And to search any possible ABIs:
@@ -393,18 +402,24 @@ Hints
set (Python3_FIND_ABI "ANY" "ANY" "ANY" "ANY")
The following combinations, in that order, will be used: ``mu``, ``m``,
``u``, ``<empty>``, ``dmu``, ``dm``, ``du``, ``d``, ``tmu``, ``tm``, ``tu``,
``t``, ``tdmu``, ``tdm``, ``tdu``, and ``td``.
The following combinations, in that order, will be used:
* On ``POSIX`` systems: ``mu``, ``m``, ``u``, ``<empty>``, ``dmu``, ``dm``,
``du``, ``d``, ``tmu``, ``tm``, ``tu``, ``t``, ``tdmu``, ``tdm``, ``tdu``,
and ``td``.
* On ``Windows`` systems: ``mu``, ``m``, ``u``, ``<empty>``, ``mu_d``,
``m_d``, ``u_d``, ``_d``, ``tmu``, ``tm``, ``tu``, ``t``, ``tmu_d``, ``tm_d``,
``tu_d``, and ``t_d``.
.. note::
This hint is useful only on ``POSIX`` systems except for the
``gil_disabled`` flag. So, on ``Windows`` systems,
when ``Python_FIND_ABI`` is defined, ``Python`` distributions from
`python.org <https://www.python.org/>`_ will be found only if the value for
each flag is ``OFF`` or ``ANY`` except for the fourth one
(``gil_disabled``).
This hint is fully usable on ``POSIX`` systems. On ``Windows`` systems,
only the ``gil_disabled`` and ``pydebug`` flags are supported. Moreover,
the ``pydebug`` flag is only supported for ``Python`` 3.14+. So, on
``Windows`` systems, when ``Python3_FIND_ABI`` is defined, ``Python``
distributions from `python.org <https://www.python.org/>`_ will be found
only if the value for the flags ``pymalloc`` and ``unicode`` is ``OFF`` or
``ANY``.
``Python3_FIND_STRATEGY``
.. versionadded:: 3.15