Merge topic 'cuda_add_12.8_new_sm_support'
[kiteware-cmake.git] / Modules / FindPython.cmake
blob04728ad7dbcac3c59ba0953069404494a71bf5f0
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindPython
6 ----------
8 .. versionadded:: 3.12
10 Find Python interpreter, compiler and development environment (include
11 directories and libraries).
13 .. versionadded:: 3.19
14   When a version is requested, it can be specified as a simple value or as a
15   range. For a detailed description of version range usage and capabilities,
16   refer to the :command:`find_package` command.
18 The following components are supported:
20 * ``Interpreter``: search for Python interpreter.
21 * ``Compiler``: search for Python compiler. Only offered by IronPython.
22 * ``Development``: search for development artifacts (include directories and
23   libraries).
25   .. versionadded:: 3.18
26     This component includes two sub-components which can be specified
27     independently:
29     * ``Development.Module``: search for artifacts for Python module
30       developments.
31     * ``Development.Embed``: search for artifacts for Python embedding
32       developments.
34   .. versionadded:: 3.26
36     * ``Development.SABIModule``: search for artifacts for Python module
37       developments using the
38       `Stable Application Binary Interface <https://docs.python.org/3/c-api/stable.html>`_.
39       This component is available only for version ``3.2`` and upper.
41 * ``NumPy``: search for NumPy include directories.
43 .. versionadded:: 3.14
44   Added the ``NumPy`` component.
46 If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
48 If component ``Development`` is specified, it implies sub-components
49 ``Development.Module`` and ``Development.Embed``.
51 To ensure consistent versions between components ``Interpreter``, ``Compiler``,
52 ``Development`` (or one of its sub-components) and ``NumPy``, specify all
53 components at the same time:
55 .. code-block:: cmake
57   find_package (Python COMPONENTS Interpreter Development)
59 This module looks preferably for version 3 of Python. If not found, version 2
60 is searched.
61 To manage concurrent versions 3 and 2 of Python, use :module:`FindPython3` and
62 :module:`FindPython2` modules rather than this one.
64 .. note::
66   If components ``Interpreter`` and ``Development`` (or one of its
67   sub-components) are both specified, this module search only for interpreter
68   with same platform architecture as the one defined by CMake
69   configuration. This constraint does not apply if only ``Interpreter``
70   component is specified.
72 Imported Targets
73 ^^^^^^^^^^^^^^^^
75 This module defines the following :ref:`Imported Targets <Imported Targets>`:
77 .. versionchanged:: 3.14
78   :ref:`Imported Targets <Imported Targets>` are only created when
79   :prop_gbl:`CMAKE_ROLE` is ``PROJECT``.
81 ``Python::Interpreter``
82   Python interpreter. This target is defined only if the ``Interpreter``
83   component is found.
84 ``Python::InterpreterDebug``
85   .. versionadded:: 3.30
87   Python debug interpreter. This target is defined only if the ``Interpreter``
88   component is found and the ``Python_EXECUTABLE_DEBUG`` variable is defined.
89   The target is only defined on the ``Windows`` platform.
91 ``Python::InterpreterMultiConfig``
92   .. versionadded:: 3.30
94   Python interpreter. The release or debug version of the interpreter will be
95   used, based on the context (platform, configuration).
96   This target is defined only if the ``Interpreter`` component is found
98 ``Python::Compiler``
99   Python compiler. This target is defined only if the ``Compiler`` component is
100   found.
102 ``Python::Module``
103   .. versionadded:: 3.15
105   Python library for Python module. Target defined if component
106   ``Development.Module`` is found.
108 ``Python::SABIModule``
109   .. versionadded:: 3.26
111   Python library for Python module using the Stable Application Binary
112   Interface. Target defined if component ``Development.SABIModule`` is found.
114 ``Python::Python``
115   Python library for Python embedding. Target defined if component
116   ``Development.Embed`` is found.
118 ``Python::NumPy``
119   .. versionadded:: 3.14
121   NumPy Python library. Target defined if component ``NumPy`` is found.
123 Result Variables
124 ^^^^^^^^^^^^^^^^
126 This module will set the following variables in your project
127 (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
129 ``Python_FOUND``
130   System has the Python requested components.
131 ``Python_Interpreter_FOUND``
132   System has the Python interpreter.
133 ``Python_EXECUTABLE``
134   Path to the Python interpreter.
135 ``Python_EXECUTABLE_DEBUG``
136   .. versionadded:: 3.30
138   Path to the debug Python interpreter. It is only defined on the ``Windows``
139   platform.
141 ``Python_INTERPRETER``
142   .. versionadded:: 3.30
144   Path to the Python interpreter, defined as a
145   :manual:`generator expression <cmake-generator-expressions(7)>` selecting
146   the ``Python_EXECUTABLE`` or ``Python_EXECUTABLE_DEBUG`` variable based on
147   the context (platform, configuration).
149 ``Python_INTERPRETER_ID``
150   A short string unique to the interpreter. Possible values include:
151     * Python
152     * ActivePython
153     * Anaconda
154     * Canopy
155     * IronPython
156     * PyPy
157 ``Python_STDLIB``
158   Standard platform independent installation directory.
160   Information returned by ``sysconfig.get_path('stdlib')``.
161 ``Python_STDARCH``
162   Standard platform dependent installation directory.
164   Information returned by ``sysconfig.get_path('platstdlib')``.
165 ``Python_SITELIB``
166   Third-party platform independent installation directory.
168   Information returned by ``sysconfig.get_path('purelib')``.
169 ``Python_SITEARCH``
170   Third-party platform dependent installation directory.
172   Information returned by ``sysconfig.get_path('platlib')``.
174 ``Python_SOABI``
175   .. versionadded:: 3.17
177   Extension suffix for modules.
179   Information computed from ``sysconfig.get_config_var('EXT_SUFFIX')`` or
180   ``sysconfig.get_config_var('SOABI')`` or
181   ``python3-config --extension-suffix``.
183 ``Python_SOSABI``
184   .. versionadded:: 3.26
186   Extension suffix for modules using the Stable Application Binary Interface.
188   Information computed from ``importlib.machinery.EXTENSION_SUFFIXES`` if the
189   COMPONENT ``Interpreter`` was specified. Otherwise, the extension is ``abi3``
190   except for ``Windows``, ``MSYS`` and ``CYGWIN`` for which this is an empty
191   string.
193 ``Python_Compiler_FOUND``
194   System has the Python compiler.
195 ``Python_COMPILER``
196   Path to the Python compiler. Only offered by IronPython.
197 ``Python_COMPILER_ID``
198   A short string unique to the compiler. Possible values include:
199     * IronPython
201 ``Python_DOTNET_LAUNCHER``
202   .. versionadded:: 3.18
204   The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
206 ``Python_Development_FOUND``
207   System has the Python development artifacts.
209 ``Python_Development.Module_FOUND``
210   .. versionadded:: 3.18
212   System has the Python development artifacts for Python module.
214 ``Python_Development.SABIModule_FOUND``
215   .. versionadded:: 3.26
217   System has the Python development artifacts for Python module using the
218   Stable Application Binary Interface.
220 ``Python_Development.Embed_FOUND``
221   .. versionadded:: 3.18
223   System has the Python development artifacts for Python embedding.
225 ``Python_INCLUDE_DIRS``
227   The Python include directories.
229 ``Python_DEFINITIONS``
230   .. versionadded:: 3.30.3
232   The Python preprocessor definitions.
234 ``Python_DEBUG_POSTFIX``
235   .. versionadded:: 3.30
237   Postfix of debug python module. This variable can be used to define the
238   :prop_tgt:`DEBUG_POSTFIX` target property.
240 ``Python_LINK_OPTIONS``
241   .. versionadded:: 3.19
243   The Python link options. Some configurations require specific link options
244   for a correct build and execution.
246 ``Python_LIBRARIES``
247   The Python libraries.
248 ``Python_LIBRARY_DIRS``
249   The Python library directories.
250 ``Python_RUNTIME_LIBRARY_DIRS``
251   The Python runtime library directories.
252 ``Python_SABI_LIBRARIES``
253   .. versionadded:: 3.26
255   The Python libraries for the Stable Application Binary Interface.
256 ``Python_SABI_LIBRARY_DIRS``
257   .. versionadded:: 3.26
259   The Python ``SABI`` library directories.
260 ``Python_RUNTIME_SABI_LIBRARY_DIRS``
261   .. versionadded:: 3.26
263   The Python runtime ``SABI`` library directories.
264 ``Python_VERSION``
265   Python version.
266 ``Python_VERSION_MAJOR``
267   Python major version.
268 ``Python_VERSION_MINOR``
269   Python minor version.
270 ``Python_VERSION_PATCH``
271   Python patch version.
273 ``Python_PyPy_VERSION``
274   .. versionadded:: 3.18
276   Python PyPy version.
278 ``Python_NumPy_FOUND``
279   .. versionadded:: 3.14
281   System has the NumPy.
283 ``Python_NumPy_INCLUDE_DIRS``
284   .. versionadded:: 3.14
286   The NumPy include directories.
288 ``Python_NumPy_VERSION``
289   .. versionadded:: 3.14
291   The NumPy version.
293 Hints
294 ^^^^^
296 ``Python_ROOT_DIR``
297   Define the root directory of a Python installation.
299 ``Python_USE_STATIC_LIBS``
300   * If not defined, search for shared libraries and static libraries in that
301     order.
302   * If set to TRUE, search **only** for static libraries.
303   * If set to FALSE, search **only** for shared libraries.
305   .. note::
307     This hint will be ignored on ``Windows`` because static libraries are not
308     available on this platform.
310 ``Python_FIND_ABI``
311   .. versionadded:: 3.16
313   This variable defines which ABIs, as defined in :pep:`3149`, should be
314   searched.
316   .. note::
318     This hint will be honored only when searched for ``Python`` version 3.
320   The ``Python_FIND_ABI`` variable is a 4-tuple specifying, in that order,
321   ``pydebug`` (``d``), ``pymalloc`` (``m``), ``unicode`` (``u``) and
322   ``gil_disabled`` (``t``) flags.
324   .. versionadded:: 3.30
325     A fourth element, specifying the ``gil_disabled`` flag (i.e. free
326     threaded python), is added and is optional. If not specified, the value is
327     ``OFF``.
329   Each element can be set to one of the following:
331   * ``ON``: Corresponding flag is selected.
332   * ``OFF``: Corresponding flag is not selected.
333   * ``ANY``: The two possibilities (``ON`` and ``OFF``) will be searched.
335   .. note::
337     If ``Python3_FIND_ABI`` is not defined, any ABI, excluding the
338     ``gil_disabled`` flag, will be searched.
340   From this 4-tuple, various ABIs will be searched starting from the most
341   specialized to the most general. Moreover, when ``ANY`` is specified for
342   ``pydebug`` and ``gil_disabled``, ``debug`` and ``free threaded`` versions
343   will be searched **after** ``non-debug`` and ``non-gil-disabled`` ones.
345   For example, if we have:
347   .. code-block:: cmake
349     set (Python_FIND_ABI "ON" "ANY" "ANY" "ON")
351   The following flags combinations will be appended, in that order, to the
352   artifact names: ``tdmu``, ``tdm``, ``tdu``, and ``td``.
354   And to search any possible ABIs:
356   .. code-block:: cmake
358     set (Python_FIND_ABI "ANY" "ANY" "ANY" "ANY")
360   The following combinations, in that order, will be used: ``mu``, ``m``,
361   ``u``, ``<empty>``, ``dmu``, ``dm``, ``du``, ``d``, ``tmu``, ``tm``, ``tu``,
362   ``t``, ``tdmu``, ``tdm``, ``tdu``, and ``td``.
364   .. note::
366     This hint is useful only on ``POSIX`` systems except for the
367     ``gil_disabled`` flag. So, on ``Windows`` systems,
368     when ``Python_FIND_ABI`` is defined, ``Python`` distributions from
369     `python.org <https://www.python.org/>`_ will be found only if the value for
370     each flag is ``OFF`` or ``ANY`` except for the fourth one
371     (``gil_disabled``).
373 ``Python_FIND_STRATEGY``
374   .. versionadded:: 3.15
376   This variable defines how lookup will be done.
377   The ``Python_FIND_STRATEGY`` variable can be set to one of the following:
379   * ``VERSION``: Try to find the most recent version in all specified
380     locations.
381     This is the default if policy :policy:`CMP0094` is undefined or set to
382     ``OLD``.
383   * ``LOCATION``: Stops lookup as soon as a version satisfying version
384     constraints is founded.
385     This is the default if policy :policy:`CMP0094` is set to ``NEW``.
387   See also ``Python_FIND_UNVERSIONED_NAMES``.
389 ``Python_FIND_REGISTRY``
390   .. versionadded:: 3.13
392   On Windows the ``Python_FIND_REGISTRY`` variable determine the order
393   of preference between registry and environment variables.
394   the ``Python_FIND_REGISTRY`` variable can be set to one of the following:
396   * ``FIRST``: Try to use registry before environment variables.
397     This is the default.
398   * ``LAST``: Try to use registry after environment variables.
399   * ``NEVER``: Never try to use registry.
401 ``Python_FIND_FRAMEWORK``
402   .. versionadded:: 3.15
404   On macOS the ``Python_FIND_FRAMEWORK`` variable determine the order of
405   preference between Apple-style and unix-style package components.
406   This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
407   variable.
409   .. note::
411     Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
413   If ``Python_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
414   variable will be used, if any.
416 ``Python_FIND_VIRTUALENV``
417   .. versionadded:: 3.15
419   This variable defines the handling of virtual environments managed by
420   ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
421   is active (i.e. the ``activate`` script has been evaluated). In this case, it
422   takes precedence over ``Python_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
423   variables.  The ``Python_FIND_VIRTUALENV`` variable can be set to one of the
424   following:
426   * ``FIRST``: The virtual environment is used before any other standard
427     paths to look-up for the interpreter. This is the default.
428   * ``ONLY``: Only the virtual environment is used to look-up for the
429     interpreter.
430   * ``STANDARD``: The virtual environment is not used to look-up for the
431     interpreter but environment variable ``PATH`` is always considered.
432     In this case, variable ``Python_FIND_REGISTRY`` (Windows) or
433     ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
434     ``NEVER`` to select preferably the interpreter from the virtual
435     environment.
437   .. versionadded:: 3.17
438     Added support for ``conda`` environments.
440   .. note::
442     If the component ``Development`` is requested (or one of its
443     sub-components) and is not found or the wrong artifacts are returned,
444     including also the component ``Interpreter`` may be helpful.
446 ``Python_FIND_IMPLEMENTATIONS``
447   .. versionadded:: 3.18
449   This variable defines, in an ordered list, the different implementations
450   which will be searched. The ``Python_FIND_IMPLEMENTATIONS`` variable can
451   hold the following values:
453   * ``CPython``: this is the standard implementation. Various products, like
454     ``Anaconda`` or ``ActivePython``, rely on this implementation.
455   * ``IronPython``: This implementation use the ``CSharp`` language for
456     ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``).
457     See `IronPython <https://ironpython.net>`_.
458   * ``PyPy``: This implementation use ``RPython`` language and
459     ``RPython translation toolchain`` to produce the python interpreter.
460     See `PyPy <https://pypy.org>`_.
462   The default value is:
464   * Windows platform: ``CPython``, ``IronPython``
465   * Other platforms: ``CPython``
467   .. note::
469     This hint has the lowest priority of all hints, so even if, for example,
470     you specify ``IronPython`` first and ``CPython`` in second, a python
471     product based on ``CPython`` can be selected because, for example with
472     ``Python_FIND_STRATEGY=LOCATION``, each location will be search first for
473     ``IronPython`` and second for ``CPython``.
475   .. note::
477     When ``IronPython`` is specified, on platforms other than ``Windows``, the
478     ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available
479     through the ``PATH`` variable.
481 ``Python_FIND_UNVERSIONED_NAMES``
482   .. versionadded:: 3.20
484   This variable defines how the generic names will be searched. Currently, it
485   only applies to the generic names of the interpreter, namely, ``python3`` or
486   ``python2`` and ``python``.
487   The ``Python_FIND_UNVERSIONED_NAMES`` variable can be set to one of the
488   following values:
490   * ``FIRST``: The generic names are searched before the more specialized ones
491     (such as ``python2.5`` for example).
492   * ``LAST``: The generic names are searched after the more specialized ones.
493     This is the default.
494   * ``NEVER``: The generic name are not searched at all.
496   See also ``Python_FIND_STRATEGY``.
498 Artifacts Specification
499 ^^^^^^^^^^^^^^^^^^^^^^^
501 .. versionadded:: 3.16
503 To solve special cases, it is possible to specify directly the artifacts by
504 setting the following variables:
506 ``Python_EXECUTABLE``
507   The path to the interpreter.
509 ``Python_COMPILER``
510   The path to the compiler.
512 ``Python_DOTNET_LAUNCHER``
513   .. versionadded:: 3.18
515   The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
517 ``Python_LIBRARY``
518   The path to the library. It will be used to compute the
519   variables ``Python_LIBRARIES``, ``Python_LIBRARY_DIRS`` and
520   ``Python_RUNTIME_LIBRARY_DIRS``.
522 ``Python_SABI_LIBRARY``
523   .. versionadded:: 3.26
525   The path to the library for Stable Application Binary Interface. It will be
526   used to compute the variables ``Python_SABI_LIBRARIES``,
527   ``Python_SABI_LIBRARY_DIRS`` and ``Python_RUNTIME_SABI_LIBRARY_DIRS``.
529 ``Python_INCLUDE_DIR``
530   The path to the directory of the ``Python`` headers. It will be used to
531   compute the variable ``Python_INCLUDE_DIRS``.
533 ``Python_NumPy_INCLUDE_DIR``
534   The path to the directory of the ``NumPy`` headers. It will be used to
535   compute the variable ``Python_NumPy_INCLUDE_DIRS``.
537 .. note::
539   All paths must be absolute. Any artifact specified with a relative path
540   will be ignored.
542 .. note::
544   When an artifact is specified, all ``HINTS`` will be ignored and no search
545   will be performed for this artifact.
547   If more than one artifact is specified, it is the user's responsibility to
548   ensure the consistency of the various artifacts.
550 By default, this module supports multiple calls in different directories of a
551 project with different version/component requirements while providing correct
552 and consistent results for each call. To support this behavior, CMake cache
553 is not used in the traditional way which can be problematic for interactive
554 specification. So, to enable also interactive specification, module behavior
555 can be controlled with the following variable:
557 ``Python_ARTIFACTS_INTERACTIVE``
558   .. versionadded:: 3.18
560   Selects the behavior of the module. This is a boolean variable:
562   * If set to ``TRUE``: Create CMake cache entries for the above artifact
563     specification variables so that users can edit them interactively.
564     This disables support for multiple version/component requirements.
565   * If set to ``FALSE`` or undefined: Enable multiple version/component
566     requirements.
568 ``Python_ARTIFACTS_PREFIX``
569   .. versionadded:: 4.0
571   Define a custom prefix which will be used for the definition of all the
572   result variables, targets, and commands. By using this variable, this module
573   supports multiple calls in the same directory with different
574   version/component requirements.
575   For example, in case of cross-compilation, development components are needed
576   but the native python interpreter can also be required:
578   .. code-block:: cmake
580     find_package(Python COMPONENTS Development)
582     set(Python_ARTIFACTS_PREFIX "_HOST")
583     find_package(Python COMPONENTS Interpreter)
585     # Here Python_HOST_EXECUTABLE and Python_HOST::Interpreter artifacts are defined
587   .. note::
589     For consistency with standard behavior of modules, the various standard
590     ``_FOUND`` variables (i.e. without the custom prefix) are also defined by
591     each call to the :command:`find_package` command.
593 Commands
594 ^^^^^^^^
596 This module defines the command ``Python_add_library`` (when
597 :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
598 :command:`add_library` and adds a dependency to target ``Python::Python`` or,
599 when library type is ``MODULE``, to target ``Python::Module`` or
600 ``Python::SABIModule`` (when ``USE_SABI`` option is specified) and takes care
601 of Python module naming rules:
603 .. code-block:: cmake
605   Python_add_library (<name> [STATIC | SHARED | MODULE [USE_SABI <version>] [WITH_SOABI]]
606                       <source1> [<source2> ...])
608 If the library type is not specified, ``MODULE`` is assumed.
610 .. versionadded:: 3.17
611   For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the
612   module suffix will include the ``Python_SOABI`` value, if any.
614 .. versionadded:: 3.26
615   For ``MODULE`` type, if the option ``USE_SABI`` is specified, the
616   preprocessor definition ``Py_LIMITED_API`` will be specified, as ``PRIVATE``,
617   for the target ``<name>`` with the value computed from ``<version>`` argument.
618   The expected format for ``<version>`` is ``major[.minor]``, where each
619   component is a numeric value. If ``minor`` component is specified, the
620   version should be, at least, ``3.2`` which is the version where the
621   `Stable Application Binary Interface <https://docs.python.org/3/c-api/stable.html>`_
622   was introduced. Specifying only major version ``3`` is equivalent to ``3.2``.
624   When option ``WITH_SOABI`` is also specified,  the module suffix will include
625   the ``Python_SOSABI`` value, if any.
627 .. versionadded:: 3.30
628   For ``MODULE`` type, the :prop_tgt:`DEBUG_POSTFIX` target property is
629   initialized with the value of ``Python_DEBUG_POSTFIX`` variable if defined.
630 #]=======================================================================]
633 cmake_policy(PUSH)
634 # foreach loop variable scope
635 cmake_policy (SET CMP0124 NEW)
638 set (_PYTHON_BASE Python)
639 if(${_PYTHON_BASE}_ARTIFACTS_PREFIX)
640   set(_PYTHON_PREFIX "${_PYTHON_BASE}${${_PYTHON_BASE}_ARTIFACTS_PREFIX}")
641 else()
642   set(_PYTHON_PREFIX "${_PYTHON_BASE}")
643 endif()
645 unset (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
646 unset (_${_PYTHON_PREFIX}_REQUIRED_VERSIONS)
648 if (Python_FIND_VERSION_RANGE)
649   # compute list of major versions
650   foreach (version_major IN ITEMS 3 2)
651     if (version_major VERSION_GREATER_EQUAL Python_FIND_VERSION_MIN_MAJOR
652         AND ((Python_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND version_major VERSION_LESS_EQUAL Python_FIND_VERSION_MAX)
653         OR (Python_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND version_major VERSION_LESS Python_FIND_VERSION_MAX)))
654       list (APPEND _${_PYTHON_PREFIX}_REQUIRED_VERSIONS ${version_major})
655     endif()
656   endforeach()
657   list (LENGTH _${_PYTHON_PREFIX}_REQUIRED_VERSIONS _${_PYTHON_PREFIX}_VERSION_COUNT)
658   if (_${_PYTHON_PREFIX}_VERSION_COUNT EQUAL 0)
659     unset (_${_PYTHON_PREFIX}_REQUIRED_VERSIONS)
660   elseif (_${_PYTHON_PREFIX}_VERSION_COUNT EQUAL 1)
661     set (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR ${_${_PYTHON_PREFIX}_REQUIRED_VERSIONS})
662   endif()
663 elseif (DEFINED Python_FIND_VERSION)
664   set (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR ${Python_FIND_VERSION_MAJOR})
665 else()
666   set (_${_PYTHON_PREFIX}_REQUIRED_VERSIONS 3 2)
667 endif()
669 if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
670   include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
671 elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSIONS)
672   # iterate over versions in quiet and NOT required modes to avoid multiple
673   # "Found" messages and prematurally failure.
674   set (_${_PYTHON_PREFIX}_QUIETLY ${Python_FIND_QUIETLY})
675   set (_${_PYTHON_PREFIX}_REQUIRED ${Python_FIND_REQUIRED})
676   set (Python_FIND_QUIETLY TRUE)
677   set (Python_FIND_REQUIRED FALSE)
679   set (_${_PYTHON_PREFIX}_REQUIRED_VERSION_LAST 2)
681   unset (_${_PYTHON_PREFIX}_INPUT_VARS)
682   foreach (item IN ITEMS Python_EXECUTABLE Python_COMPILER Python_LIBRARY
683                          Python_INCLUDE_DIR Python_NumPy_INCLUDE_DIR)
684     if (NOT DEFINED ${item})
685       list (APPEND _${_PYTHON_PREFIX}_INPUT_VARS ${item})
686     endif()
687   endforeach()
689   foreach (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR IN LISTS _${_PYTHON_PREFIX}_REQUIRED_VERSIONS)
690     set (Python_FIND_VERSION ${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR})
691     include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
692     if (Python_FOUND OR
693         _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_LAST)
694       break()
695     endif()
696     # clean-up INPUT variables not set by the user
697     foreach (item IN LISTS _${_PYTHON_PREFIX}_INPUT_VARS)
698       unset (${item})
699     endforeach()
700     # clean-up some CACHE variables to ensure look-up restart from scratch
701     foreach (item IN LISTS _${_PYTHON_PREFIX}_CACHED_VARS)
702       unset (${item} CACHE)
703     endforeach()
704   endforeach()
706   unset (Python_FIND_VERSION)
708   set (Python_FIND_QUIETLY ${_${_PYTHON_PREFIX}_QUIETLY})
709   set (Python_FIND_REQUIRED ${_${_PYTHON_PREFIX}_REQUIRED})
710   if (Python_FIND_REQUIRED OR NOT Python_FIND_QUIETLY)
711     # call again validation command to get "Found" or error message
712     find_package_handle_standard_args (Python HANDLE_COMPONENTS HANDLE_VERSION_RANGE
713                                               REQUIRED_VARS ${_${_PYTHON_PREFIX}_REQUIRED_VARS}
714                                               VERSION_VAR Python_VERSION)
715   endif()
716 else()
717   # supported versions not in the specified range. Call final check
718   if (NOT Python_FIND_COMPONENTS)
719     set (Python_FIND_COMPONENTS Interpreter)
720     set (Python_FIND_REQUIRED_Interpreter TRUE)
721   endif()
723   include(FindPackageHandleStandardArgs)
724   find_package_handle_standard_args (Python HANDLE_COMPONENTS HANDLE_VERSION_RANGE
725                                             VERSION_VAR Python_VERSION
726                                             REASON_FAILURE_MESSAGE "Version range specified \"${Python_FIND_VERSION_RANGE}\" does not include supported versions")
727 endif()
729 if (COMMAND __${_PYTHON_PREFIX}_add_library AND NOT COMMAND ${_PYTHON_PREFIX}_add_library)
730   cmake_language(EVAL CODE
731     "macro (${_PYTHON_PREFIX}_add_library)
732       __${_PYTHON_PREFIX}_add_library (${_PYTHON_PREFIX} \${ARGV})
733     endmacro()")
734 endif()
736 unset (_PYTHON_BASE)
737 unset (_PYTHON_PREFIX)
739 cmake_policy(POP)