FindPython.cmake 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindPython
  5. ----------
  6. .. versionadded:: 3.12
  7. Find Python interpreter, compiler and development environment (include
  8. directories and libraries).
  9. .. versionadded:: 3.19
  10. When a version is requested, it can be specified as a simple value or as a
  11. range. For a detailed description of version range usage and capabilities,
  12. refer to the :command:`find_package` command.
  13. The following components are supported:
  14. * ``Interpreter``: search for Python interpreter.
  15. * ``Compiler``: search for Python compiler. Only offered by IronPython.
  16. * ``Development``: search for development artifacts (include directories and
  17. libraries).
  18. .. versionadded:: 3.18
  19. This component includes two sub-components which can be specified
  20. independently:
  21. * ``Development.Module``: search for artifacts for Python module
  22. developments.
  23. * ``Development.Embed``: search for artifacts for Python embedding
  24. developments.
  25. .. versionadded:: 3.26
  26. * ``Development.SABIModule``: search for artifacts for Python module
  27. developments using the
  28. `Stable Application Binary Interface <https://docs.python.org/3/c-api/stable.html>`_.
  29. This component is available only for version ``3.2`` and upper.
  30. * ``NumPy``: search for NumPy include directories.
  31. .. versionadded:: 3.14
  32. Added the ``NumPy`` component.
  33. If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
  34. If component ``Development`` is specified, it implies sub-components
  35. ``Development.Module`` and ``Development.Embed``.
  36. To ensure consistent versions between components ``Interpreter``, ``Compiler``,
  37. ``Development`` (or one of its sub-components) and ``NumPy``, specify all
  38. components at the same time::
  39. find_package (Python COMPONENTS Interpreter Development)
  40. This module looks preferably for version 3 of Python. If not found, version 2
  41. is searched.
  42. To manage concurrent versions 3 and 2 of Python, use :module:`FindPython3` and
  43. :module:`FindPython2` modules rather than this one.
  44. .. note::
  45. If components ``Interpreter`` and ``Development`` (or one of its
  46. sub-components) are both specified, this module search only for interpreter
  47. with same platform architecture as the one defined by CMake
  48. configuration. This constraint does not apply if only ``Interpreter``
  49. component is specified.
  50. Imported Targets
  51. ^^^^^^^^^^^^^^^^
  52. This module defines the following :ref:`Imported Targets <Imported Targets>`:
  53. .. versionchanged:: 3.14
  54. :ref:`Imported Targets <Imported Targets>` are only created when
  55. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``.
  56. ``Python::Interpreter``
  57. Python interpreter. Target defined if component ``Interpreter`` is found.
  58. ``Python::Compiler``
  59. Python compiler. Target defined if component ``Compiler`` is found.
  60. ``Python::Module``
  61. .. versionadded:: 3.15
  62. Python library for Python module. Target defined if component
  63. ``Development.Module`` is found.
  64. ``Python::SABIModule``
  65. .. versionadded:: 3.26
  66. Python library for Python module using the Stable Application Binary
  67. Interface. Target defined if component ``Development.SABIModule`` is found.
  68. ``Python::Python``
  69. Python library for Python embedding. Target defined if component
  70. ``Development.Embed`` is found.
  71. ``Python::NumPy``
  72. .. versionadded:: 3.14
  73. NumPy Python library. Target defined if component ``NumPy`` is found.
  74. Result Variables
  75. ^^^^^^^^^^^^^^^^
  76. This module will set the following variables in your project
  77. (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
  78. ``Python_FOUND``
  79. System has the Python requested components.
  80. ``Python_Interpreter_FOUND``
  81. System has the Python interpreter.
  82. ``Python_EXECUTABLE``
  83. Path to the Python interpreter.
  84. ``Python_INTERPRETER_ID``
  85. A short string unique to the interpreter. Possible values include:
  86. * Python
  87. * ActivePython
  88. * Anaconda
  89. * Canopy
  90. * IronPython
  91. * PyPy
  92. ``Python_STDLIB``
  93. Standard platform independent installation directory.
  94. Information returned by
  95. ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``
  96. or else ``sysconfig.get_path('stdlib')``.
  97. ``Python_STDARCH``
  98. Standard platform dependent installation directory.
  99. Information returned by
  100. ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``
  101. or else ``sysconfig.get_path('platstdlib')``.
  102. ``Python_SITELIB``
  103. Third-party platform independent installation directory.
  104. Information returned by
  105. ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``
  106. or else ``sysconfig.get_path('purelib')``.
  107. ``Python_SITEARCH``
  108. Third-party platform dependent installation directory.
  109. Information returned by
  110. ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``
  111. or else ``sysconfig.get_path('platlib')``.
  112. ``Python_SOABI``
  113. .. versionadded:: 3.17
  114. Extension suffix for modules.
  115. Information computed from ``distutils.sysconfig.get_config_var('EXT_SUFFIX')``
  116. or ``distutils.sysconfig.get_config_var('SOABI')`` or
  117. ``python3-config --extension-suffix``. If package ``distutils.sysconfig`` is
  118. not available, ``sysconfig.get_config_var('EXT_SUFFIX')`` or
  119. ``sysconfig.get_config_var('SOABI')`` are used.
  120. ``Python_SOSABI``
  121. .. versionadded:: 3.26
  122. Extension suffix for modules using the Stable Application Binary Interface.
  123. Information computed from ``importlib.machinery.EXTENSION_SUFFIXES`` if the
  124. COMPONENT ``Interpreter`` was specified. Otherwise, the extension is ``abi3``
  125. except for ``Windows``, ``MSYS`` and ``CYGWIN`` for which this is an empty
  126. string.
  127. ``Python_Compiler_FOUND``
  128. System has the Python compiler.
  129. ``Python_COMPILER``
  130. Path to the Python compiler. Only offered by IronPython.
  131. ``Python_COMPILER_ID``
  132. A short string unique to the compiler. Possible values include:
  133. * IronPython
  134. ``Python_DOTNET_LAUNCHER``
  135. .. versionadded:: 3.18
  136. The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
  137. ``Python_Development_FOUND``
  138. System has the Python development artifacts.
  139. ``Python_Development.Module_FOUND``
  140. .. versionadded:: 3.18
  141. System has the Python development artifacts for Python module.
  142. ``Python_Development.SABIModule_FOUND``
  143. .. versionadded:: 3.26
  144. System has the Python development artifacts for Python module using the
  145. Stable Application Binary Interface.
  146. ``Python_Development.Embed_FOUND``
  147. .. versionadded:: 3.18
  148. System has the Python development artifacts for Python embedding.
  149. ``Python_INCLUDE_DIRS``
  150. The Python include directories.
  151. ``Python_LINK_OPTIONS``
  152. .. versionadded:: 3.19
  153. The Python link options. Some configurations require specific link options
  154. for a correct build and execution.
  155. ``Python_LIBRARIES``
  156. The Python libraries.
  157. ``Python_LIBRARY_DIRS``
  158. The Python library directories.
  159. ``Python_RUNTIME_LIBRARY_DIRS``
  160. The Python runtime library directories.
  161. ``Python_SABI_LIBRARIES``
  162. .. versionadded:: 3.26
  163. The Python libraries for the Stable Application Binary Interface.
  164. ``Python_SABI_LIBRARY_DIRS``
  165. .. versionadded:: 3.26
  166. The Python ``SABI`` library directories.
  167. ``Python_RUNTIME_SABI_LIBRARY_DIRS``
  168. .. versionadded:: 3.26
  169. The Python runtime ``SABI`` library directories.
  170. ``Python_VERSION``
  171. Python version.
  172. ``Python_VERSION_MAJOR``
  173. Python major version.
  174. ``Python_VERSION_MINOR``
  175. Python minor version.
  176. ``Python_VERSION_PATCH``
  177. Python patch version.
  178. ``Python_PyPy_VERSION``
  179. .. versionadded:: 3.18
  180. Python PyPy version.
  181. ``Python_NumPy_FOUND``
  182. .. versionadded:: 3.14
  183. System has the NumPy.
  184. ``Python_NumPy_INCLUDE_DIRS``
  185. .. versionadded:: 3.14
  186. The NumPy include directories.
  187. ``Python_NumPy_VERSION``
  188. .. versionadded:: 3.14
  189. The NumPy version.
  190. Hints
  191. ^^^^^
  192. ``Python_ROOT_DIR``
  193. Define the root directory of a Python installation.
  194. ``Python_USE_STATIC_LIBS``
  195. * If not defined, search for shared libraries and static libraries in that
  196. order.
  197. * If set to TRUE, search **only** for static libraries.
  198. * If set to FALSE, search **only** for shared libraries.
  199. .. note::
  200. This hint will be ignored on ``Windows`` because static libraries are not
  201. available on this platform.
  202. ``Python_FIND_ABI``
  203. .. versionadded:: 3.16
  204. This variable defines which ABIs, as defined in :pep:`3149`, should be
  205. searched.
  206. .. note::
  207. This hint will be honored only when searched for ``Python`` version 3.
  208. .. note::
  209. If ``Python_FIND_ABI`` is not defined, any ABI will be searched.
  210. The ``Python_FIND_ABI`` variable is a 3-tuple specifying, in that order,
  211. ``pydebug`` (``d``), ``pymalloc`` (``m``) and ``unicode`` (``u``) flags.
  212. Each element can be set to one of the following:
  213. * ``ON``: Corresponding flag is selected.
  214. * ``OFF``: Corresponding flag is not selected.
  215. * ``ANY``: The two possibilities (``ON`` and ``OFF``) will be searched.
  216. From this 3-tuple, various ABIs will be searched starting from the most
  217. specialized to the most general. Moreover, ``debug`` versions will be
  218. searched **after** ``non-debug`` ones.
  219. For example, if we have::
  220. set (Python_FIND_ABI "ON" "ANY" "ANY")
  221. The following flags combinations will be appended, in that order, to the
  222. artifact names: ``dmu``, ``dm``, ``du``, and ``d``.
  223. And to search any possible ABIs::
  224. set (Python_FIND_ABI "ANY" "ANY" "ANY")
  225. The following combinations, in that order, will be used: ``mu``, ``m``,
  226. ``u``, ``<empty>``, ``dmu``, ``dm``, ``du`` and ``d``.
  227. .. note::
  228. This hint is useful only on ``POSIX`` systems. So, on ``Windows`` systems,
  229. when ``Python_FIND_ABI`` is defined, ``Python`` distributions from
  230. `python.org <https://www.python.org/>`_ will be found only if value for
  231. each flag is ``OFF`` or ``ANY``.
  232. ``Python_FIND_STRATEGY``
  233. .. versionadded:: 3.15
  234. This variable defines how lookup will be done.
  235. The ``Python_FIND_STRATEGY`` variable can be set to one of the following:
  236. * ``VERSION``: Try to find the most recent version in all specified
  237. locations.
  238. This is the default if policy :policy:`CMP0094` is undefined or set to
  239. ``OLD``.
  240. * ``LOCATION``: Stops lookup as soon as a version satisfying version
  241. constraints is founded.
  242. This is the default if policy :policy:`CMP0094` is set to ``NEW``.
  243. See also ``Python_FIND_UNVERSIONED_NAMES``.
  244. ``Python_FIND_REGISTRY``
  245. .. versionadded:: 3.13
  246. On Windows the ``Python_FIND_REGISTRY`` variable determine the order
  247. of preference between registry and environment variables.
  248. the ``Python_FIND_REGISTRY`` variable can be set to one of the following:
  249. * ``FIRST``: Try to use registry before environment variables.
  250. This is the default.
  251. * ``LAST``: Try to use registry after environment variables.
  252. * ``NEVER``: Never try to use registry.
  253. ``Python_FIND_FRAMEWORK``
  254. .. versionadded:: 3.15
  255. On macOS the ``Python_FIND_FRAMEWORK`` variable determine the order of
  256. preference between Apple-style and unix-style package components.
  257. This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
  258. variable.
  259. .. note::
  260. Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
  261. If ``Python_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
  262. variable will be used, if any.
  263. ``Python_FIND_VIRTUALENV``
  264. .. versionadded:: 3.15
  265. This variable defines the handling of virtual environments managed by
  266. ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
  267. is active (i.e. the ``activate`` script has been evaluated). In this case, it
  268. takes precedence over ``Python_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
  269. variables. The ``Python_FIND_VIRTUALENV`` variable can be set to one of the
  270. following:
  271. * ``FIRST``: The virtual environment is used before any other standard
  272. paths to look-up for the interpreter. This is the default.
  273. * ``ONLY``: Only the virtual environment is used to look-up for the
  274. interpreter.
  275. * ``STANDARD``: The virtual environment is not used to look-up for the
  276. interpreter but environment variable ``PATH`` is always considered.
  277. In this case, variable ``Python_FIND_REGISTRY`` (Windows) or
  278. ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
  279. ``NEVER`` to select preferably the interpreter from the virtual
  280. environment.
  281. .. versionadded:: 3.17
  282. Added support for ``conda`` environments.
  283. .. note::
  284. If the component ``Development`` is requested, it is **strongly**
  285. recommended to also include the component ``Interpreter`` to get expected
  286. result.
  287. ``Python_FIND_IMPLEMENTATIONS``
  288. .. versionadded:: 3.18
  289. This variable defines, in an ordered list, the different implementations
  290. which will be searched. The ``Python_FIND_IMPLEMENTATIONS`` variable can
  291. hold the following values:
  292. * ``CPython``: this is the standard implementation. Various products, like
  293. ``Anaconda`` or ``ActivePython``, rely on this implementation.
  294. * ``IronPython``: This implementation use the ``CSharp`` language for
  295. ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``).
  296. See `IronPython <https://ironpython.net>`_.
  297. * ``PyPy``: This implementation use ``RPython`` language and
  298. ``RPython translation toolchain`` to produce the python interpreter.
  299. See `PyPy <https://www.pypy.org>`_.
  300. The default value is:
  301. * Windows platform: ``CPython``, ``IronPython``
  302. * Other platforms: ``CPython``
  303. .. note::
  304. This hint has the lowest priority of all hints, so even if, for example,
  305. you specify ``IronPython`` first and ``CPython`` in second, a python
  306. product based on ``CPython`` can be selected because, for example with
  307. ``Python_FIND_STRATEGY=LOCATION``, each location will be search first for
  308. ``IronPython`` and second for ``CPython``.
  309. .. note::
  310. When ``IronPython`` is specified, on platforms other than ``Windows``, the
  311. ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available
  312. through the ``PATH`` variable.
  313. ``Python_FIND_UNVERSIONED_NAMES``
  314. .. versionadded:: 3.20
  315. This variable defines how the generic names will be searched. Currently, it
  316. only applies to the generic names of the interpreter, namely, ``python3`` or
  317. ``python2`` and ``python``.
  318. The ``Python_FIND_UNVERSIONED_NAMES`` variable can be set to one of the
  319. following values:
  320. * ``FIRST``: The generic names are searched before the more specialized ones
  321. (such as ``python2.5`` for example).
  322. * ``LAST``: The generic names are searched after the more specialized ones.
  323. This is the default.
  324. * ``NEVER``: The generic name are not searched at all.
  325. See also ``Python_FIND_STRATEGY``.
  326. Artifacts Specification
  327. ^^^^^^^^^^^^^^^^^^^^^^^
  328. .. versionadded:: 3.16
  329. To solve special cases, it is possible to specify directly the artifacts by
  330. setting the following variables:
  331. ``Python_EXECUTABLE``
  332. The path to the interpreter.
  333. ``Python_COMPILER``
  334. The path to the compiler.
  335. ``Python_DOTNET_LAUNCHER``
  336. .. versionadded:: 3.18
  337. The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
  338. ``Python_LIBRARY``
  339. The path to the library. It will be used to compute the
  340. variables ``Python_LIBRARIES``, ``Python_LIBRARY_DIRS`` and
  341. ``Python_RUNTIME_LIBRARY_DIRS``.
  342. ``Python_SABI_LIBRARY``
  343. .. versionadded:: 3.26
  344. The path to the library for Stable Application Binary Interface. It will be
  345. used to compute the variables ``Python_SABI_LIBRARIES``,
  346. ``Python_SABI_LIBRARY_DIRS`` and ``Python_RUNTIME_SABI_LIBRARY_DIRS``.
  347. ``Python_INCLUDE_DIR``
  348. The path to the directory of the ``Python`` headers. It will be used to
  349. compute the variable ``Python_INCLUDE_DIRS``.
  350. ``Python_NumPy_INCLUDE_DIR``
  351. The path to the directory of the ``NumPy`` headers. It will be used to
  352. compute the variable ``Python_NumPy_INCLUDE_DIRS``.
  353. .. note::
  354. All paths must be absolute. Any artifact specified with a relative path
  355. will be ignored.
  356. .. note::
  357. When an artifact is specified, all ``HINTS`` will be ignored and no search
  358. will be performed for this artifact.
  359. If more than one artifact is specified, it is the user's responsibility to
  360. ensure the consistency of the various artifacts.
  361. By default, this module supports multiple calls in different directories of a
  362. project with different version/component requirements while providing correct
  363. and consistent results for each call. To support this behavior, CMake cache
  364. is not used in the traditional way which can be problematic for interactive
  365. specification. So, to enable also interactive specification, module behavior
  366. can be controlled with the following variable:
  367. ``Python_ARTIFACTS_INTERACTIVE``
  368. .. versionadded:: 3.18
  369. Selects the behavior of the module. This is a boolean variable:
  370. * If set to ``TRUE``: Create CMake cache entries for the above artifact
  371. specification variables so that users can edit them interactively.
  372. This disables support for multiple version/component requirements.
  373. * If set to ``FALSE`` or undefined: Enable multiple version/component
  374. requirements.
  375. Commands
  376. ^^^^^^^^
  377. This module defines the command ``Python_add_library`` (when
  378. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
  379. :command:`add_library` and adds a dependency to target ``Python::Python`` or,
  380. when library type is ``MODULE``, to target ``Python::Module`` or
  381. ``Python::SABIModule`` (when ``USE_SABI`` option is specified) and takes care
  382. of Python module naming rules::
  383. Python_add_library (<name> [STATIC | SHARED | MODULE [USE_SABI <version>] [WITH_SOABI]]
  384. <source1> [<source2> ...])
  385. If the library type is not specified, ``MODULE`` is assumed.
  386. .. versionadded:: 3.17
  387. For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the
  388. module suffix will include the ``Python_SOABI`` value, if any.
  389. .. versionadded:: 3.26
  390. For ``MODULE`` type, if the option ``USE_SABI`` is specified, the
  391. preprocessor definition ``Py_LIMITED_API`` will be specified, as ``PRIVATE``,
  392. for the target ``<name>`` with the value computed from ``<version>`` argument.
  393. The expected format for ``<version>`` is ``major[.minor]``, where each
  394. component is a numeric value. If ``minor`` component is specified, the
  395. version should be, at least, ``3.2`` which is the version where the
  396. `Stable Application Binary Interface <https://docs.python.org/3/c-api/stable.html>`_
  397. was introduced. Specifying only major version ``3`` is equivalent to ``3.2``.
  398. When option ``WITH_SOABI`` is also specified, the module suffix will include
  399. the ``Python_SOSABI`` value, if any.
  400. #]=======================================================================]
  401. cmake_policy(PUSH)
  402. # numbers and boolean constants
  403. cmake_policy (SET CMP0012 NEW)
  404. set (_PYTHON_PREFIX Python)
  405. unset (_Python_REQUIRED_VERSION_MAJOR)
  406. unset (_Python_REQUIRED_VERSIONS)
  407. if (Python_FIND_VERSION_RANGE)
  408. # compute list of major versions
  409. foreach (_Python_MAJOR IN ITEMS 3 2)
  410. if (_Python_MAJOR VERSION_GREATER_EQUAL Python_FIND_VERSION_MIN_MAJOR
  411. AND ((Python_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND _Python_MAJOR VERSION_LESS_EQUAL Python_FIND_VERSION_MAX)
  412. OR (Python_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND _Python_MAJOR VERSION_LESS Python_FIND_VERSION_MAX)))
  413. list (APPEND _Python_REQUIRED_VERSIONS ${_Python_MAJOR})
  414. endif()
  415. endforeach()
  416. list (LENGTH _Python_REQUIRED_VERSIONS _Python_VERSION_COUNT)
  417. if (_Python_VERSION_COUNT EQUAL 0)
  418. unset (_Python_REQUIRED_VERSIONS)
  419. elseif (_Python_VERSION_COUNT EQUAL 1)
  420. set (_Python_REQUIRED_VERSION_MAJOR ${_Python_REQUIRED_VERSIONS})
  421. endif()
  422. elseif (DEFINED Python_FIND_VERSION)
  423. set (_Python_REQUIRED_VERSION_MAJOR ${Python_FIND_VERSION_MAJOR})
  424. else()
  425. set (_Python_REQUIRED_VERSIONS 3 2)
  426. endif()
  427. if (_Python_REQUIRED_VERSION_MAJOR)
  428. include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
  429. elseif (_Python_REQUIRED_VERSIONS)
  430. # iterate over versions in quiet and NOT required modes to avoid multiple
  431. # "Found" messages and prematurally failure.
  432. set (_Python_QUIETLY ${Python_FIND_QUIETLY})
  433. set (_Python_REQUIRED ${Python_FIND_REQUIRED})
  434. set (Python_FIND_QUIETLY TRUE)
  435. set (Python_FIND_REQUIRED FALSE)
  436. set (_Python_REQUIRED_VERSION_LAST 2)
  437. unset (_Python_INPUT_VARS)
  438. foreach (_Python_ITEM IN ITEMS Python_EXECUTABLE Python_COMPILER Python_LIBRARY
  439. Python_INCLUDE_DIR Python_NumPy_INCLUDE_DIR)
  440. if (NOT DEFINED ${_Python_ITEM})
  441. list (APPEND _Python_INPUT_VARS ${_Python_ITEM})
  442. endif()
  443. endforeach()
  444. foreach (_Python_REQUIRED_VERSION_MAJOR IN LISTS _Python_REQUIRED_VERSIONS)
  445. set (Python_FIND_VERSION ${_Python_REQUIRED_VERSION_MAJOR})
  446. include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
  447. if (Python_FOUND OR
  448. _Python_REQUIRED_VERSION_MAJOR EQUAL _Python_REQUIRED_VERSION_LAST)
  449. break()
  450. endif()
  451. # clean-up INPUT variables not set by the user
  452. foreach (_Python_ITEM IN LISTS _Python_INPUT_VARS)
  453. unset (${_Python_ITEM})
  454. endforeach()
  455. # clean-up some CACHE variables to ensure look-up restart from scratch
  456. foreach (_Python_ITEM IN LISTS _Python_CACHED_VARS)
  457. unset (${_Python_ITEM} CACHE)
  458. endforeach()
  459. endforeach()
  460. unset (Python_FIND_VERSION)
  461. set (Python_FIND_QUIETLY ${_Python_QUIETLY})
  462. set (Python_FIND_REQUIRED ${_Python_REQUIRED})
  463. if (Python_FIND_REQUIRED OR NOT Python_FIND_QUIETLY)
  464. # call again validation command to get "Found" or error message
  465. find_package_handle_standard_args (Python HANDLE_COMPONENTS HANDLE_VERSION_RANGE
  466. REQUIRED_VARS ${_Python_REQUIRED_VARS}
  467. VERSION_VAR Python_VERSION)
  468. endif()
  469. else()
  470. # supported versions not in the specified range. Call final check
  471. if (NOT Python_FIND_COMPONENTS)
  472. set (Python_FIND_COMPONENTS Interpreter)
  473. set (Python_FIND_REQUIRED_Interpreter TRUE)
  474. endif()
  475. include (${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  476. find_package_handle_standard_args (Python HANDLE_COMPONENTS HANDLE_VERSION_RANGE
  477. VERSION_VAR Python_VERSION
  478. REASON_FAILURE_MESSAGE "Version range specified \"${Python_FIND_VERSION_RANGE}\" does not include supported versions")
  479. endif()
  480. if (COMMAND __Python_add_library)
  481. macro (Python_add_library)
  482. __Python_add_library (Python ${ARGV})
  483. endmacro()
  484. endif()
  485. unset (_PYTHON_PREFIX)
  486. cmake_policy(POP)