FindPython3.cmake 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. FindPython3
  5. -----------
  6. Find Python 3 interpreter, compiler and development environment (include
  7. directories and libraries).
  8. Three components are supported:
  9. * ``Interpreter``: search for Python 3 interpreter
  10. * ``Compiler``: search for Python 3 compiler. Only offered by IronPython.
  11. * ``Development``: search for development artifacts (include directories and
  12. libraries)
  13. * ``NumPy``: search for NumPy include directories.
  14. If no ``COMPONENTS`` is specified, ``Interpreter`` is assumed.
  15. To ensure consistent versions between components ``Interpreter``, ``Compiler``,
  16. ``Development`` and ``NumPy``, specify all components at the same time::
  17. find_package (Python3 COMPONENTS Interpreter Development)
  18. This module looks only for version 3 of Python. This module can be used
  19. concurrently with :module:`FindPython2` module to use both Python versions.
  20. The :module:`FindPython` module can be used if Python version does not matter
  21. for you.
  22. .. note::
  23. If components ``Interpreter`` and ``Development`` are both specified, this
  24. module search only for interpreter with same platform architecture as the one
  25. defined by ``CMake`` configuration. This contraint does not apply if only
  26. ``Interpreter`` component is specified.
  27. Imported Targets
  28. ^^^^^^^^^^^^^^^^
  29. This module defines the following :ref:`Imported Targets <Imported Targets>`
  30. (when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
  31. ``Python3::Interpreter``
  32. Python 3 interpreter. Target defined if component ``Interpreter`` is found.
  33. ``Python3::Compiler``
  34. Python 3 compiler. Target defined if component ``Compiler`` is found.
  35. ``Python3::Python``
  36. Python 3 library for Python embedding. Target defined if component
  37. ``Development`` is found.
  38. ``Python3::Module``
  39. Python 3 library for Python module. Target defined if component
  40. ``Development`` is found.
  41. ``Python3::NumPy``
  42. NumPy library for Python 3. Target defined if component ``NumPy`` is found.
  43. Result Variables
  44. ^^^^^^^^^^^^^^^^
  45. This module will set the following variables in your project
  46. (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
  47. ``Python3_FOUND``
  48. System has the Python 3 requested components.
  49. ``Python3_Interpreter_FOUND``
  50. System has the Python 3 interpreter.
  51. ``Python3_EXECUTABLE``
  52. Path to the Python 3 interpreter.
  53. ``Python3_INTERPRETER_ID``
  54. A short string unique to the interpreter. Possible values include:
  55. * Python
  56. * ActivePython
  57. * Anaconda
  58. * Canopy
  59. * IronPython
  60. ``Python3_STDLIB``
  61. Standard platform independent installation directory.
  62. Information returned by
  63. ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``.
  64. ``Python3_STDARCH``
  65. Standard platform dependent installation directory.
  66. Information returned by
  67. ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``.
  68. ``Python3_SITELIB``
  69. Third-party platform independent installation directory.
  70. Information returned by
  71. ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``.
  72. ``Python3_SITEARCH``
  73. Third-party platform dependent installation directory.
  74. Information returned by
  75. ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``.
  76. ``Python3_Compiler_FOUND``
  77. System has the Python 3 compiler.
  78. ``Python3_COMPILER``
  79. Path to the Python 3 compiler. Only offered by IronPython.
  80. ``Python3_COMPILER_ID``
  81. A short string unique to the compiler. Possible values include:
  82. * IronPython
  83. ``Python3_Development_FOUND``
  84. System has the Python 3 development artifacts.
  85. ``Python3_INCLUDE_DIRS``
  86. The Python 3 include directories.
  87. ``Python3_LIBRARIES``
  88. The Python 3 libraries.
  89. ``Python3_LIBRARY_DIRS``
  90. The Python 3 library directories.
  91. ``Python3_RUNTIME_LIBRARY_DIRS``
  92. The Python 3 runtime library directories.
  93. ``Python3_VERSION``
  94. Python 3 version.
  95. ``Python3_VERSION_MAJOR``
  96. Python 3 major version.
  97. ``Python3_VERSION_MINOR``
  98. Python 3 minor version.
  99. ``Python3_VERSION_PATCH``
  100. Python 3 patch version.
  101. ``Python3_NumPy_FOUND``
  102. System has the NumPy.
  103. ``Python3_NumPy_INCLUDE_DIRS``
  104. The NumPy include directries.
  105. ``Python3_NumPy_VERSION``
  106. The NumPy version.
  107. Hints
  108. ^^^^^
  109. ``Python3_ROOT_DIR``
  110. Define the root directory of a Python 3 installation.
  111. ``Python3_USE_STATIC_LIBS``
  112. * If not defined, search for shared libraries and static libraries in that
  113. order.
  114. * If set to TRUE, search **only** for static libraries.
  115. * If set to FALSE, search **only** for shared libraries.
  116. ``Python3_FIND_ABI``
  117. This variable defines which ABIs, as defined in
  118. `PEP 3149 <https://www.python.org/dev/peps/pep-3149/>`_, should be searched.
  119. .. note::
  120. If ``Python3_FIND_ABI`` is not defined, any ABI will be searched.
  121. The ``Python3_FIND_ABI`` variable is a 3-tuple specifying, in that order,
  122. ``pydebug`` (``d``), ``pymalloc`` (``m``) and ``unicode`` (``u``) flags.
  123. Each element can be set to one of the following:
  124. * ``ON``: Corresponding flag is selected.
  125. * ``OFF``: Corresponding flag is not selected.
  126. * ``ANY``: The two posibilties (``ON`` and ``OFF``) will be searched.
  127. From this 3-tuple, various ABIs will be searched starting from the most
  128. specialized to the most general. Moreover, ``debug`` versions will be
  129. searched **after** ``non-debug`` ones.
  130. For example, if we have::
  131. set (Python3_FIND_ABI "ON" "ANY" "ANY")
  132. The following flags combinations will be appended, in that order, to the
  133. artifact names: ``dmu``, ``dm``, ``du``, and ``d``.
  134. And to search any possible ABIs::
  135. set (Python3_FIND_ABI "ANY" "ANY" "ANY")
  136. The following combinations, in that order, will be used: ``mu``, ``m``,
  137. ``u``, ``<empty>``, ``dmu``, ``dm``, ``du`` and ``d``.
  138. .. note::
  139. This hint is useful only on ``POSIX`` systems. So, on ``Windows`` systems,
  140. when ``Python3_FIND_ABI`` is defined, ``Python`` distributions from
  141. `python.org <https://www.python.org/>`_ will be found only if value for
  142. each flag is ``OFF`` or ``ANY``.
  143. ``Python3_FIND_STRATEGY``
  144. This variable defines how lookup will be done.
  145. The ``Python3_FIND_STRATEGY`` variable can be set to empty or one of the
  146. following:
  147. * ``VERSION``: Try to find the most recent version in all specified
  148. locations.
  149. This is the default if policy :policy:`CMP0094` is undefined or set to
  150. ``OLD``.
  151. * ``LOCATION``: Stops lookup as soon as a version satisfying version
  152. constraints is founded.
  153. This is the default if policy :policy:`CMP0094` is set to ``NEW``.
  154. ``Python3_FIND_REGISTRY``
  155. On Windows the ``Python3_FIND_REGISTRY`` variable determine the order
  156. of preference between registry and environment variables.
  157. The ``Python3_FIND_REGISTRY`` variable can be set to empty or one of the
  158. following:
  159. * ``FIRST``: Try to use registry before environment variables.
  160. This is the default.
  161. * ``LAST``: Try to use registry after environment variables.
  162. * ``NEVER``: Never try to use registry.
  163. ``Python3_FIND_FRAMEWORK``
  164. On macOS the ``Python3_FIND_FRAMEWORK`` variable determine the order of
  165. preference between Apple-style and unix-style package components.
  166. This variable can be set to empty or take same values as
  167. :variable:`CMAKE_FIND_FRAMEWORK` variable.
  168. .. note::
  169. Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
  170. If ``Python3_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
  171. variable will be used, if any.
  172. ``Python3_FIND_VIRTUALENV``
  173. This variable defines the handling of virtual environments. It is meaningfull
  174. only when a virtual environment is active (i.e. the ``activate`` script has
  175. been evaluated). In this case, it takes precedence over
  176. ``Python3_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK`` variables.
  177. The ``Python3_FIND_VIRTUALENV`` variable can be set to empty or one of the
  178. following:
  179. * ``FIRST``: The virtual environment is used before any other standard
  180. paths to look-up for the interpreter. This is the default.
  181. * ``ONLY``: Only the virtual environment is used to look-up for the
  182. interpreter.
  183. * ``STANDARD``: The virtual environment is not used to look-up for the
  184. interpreter. In this case, variable ``Python3_FIND_REGISTRY`` (Windows)
  185. or ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
  186. ``NEVER`` to select preferably the interpreter from the virtual
  187. environment.
  188. .. note::
  189. If the component ``Development`` is requested, it is **strongly**
  190. recommended to also include the component ``Interpreter`` to get expected
  191. result.
  192. Commands
  193. ^^^^^^^^
  194. This module defines the command ``Python_add_library`` (when
  195. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
  196. :command:`add_library` and adds a dependency to target ``Python3::Python`` or,
  197. when library type is ``MODULE``, to target ``Python3::Module`` and takes care
  198. of Python module naming rules::
  199. Python3_add_library (my_module MODULE src1.cpp)
  200. If library type is not specified, ``MODULE`` is assumed.
  201. #]=======================================================================]
  202. set (_PYTHON_PREFIX Python3)
  203. set (_Python3_REQUIRED_VERSION_MAJOR 3)
  204. include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
  205. if (COMMAND __Python3_add_library)
  206. macro (Python3_add_library)
  207. __Python3_add_library (Python3 ${ARGV})
  208. endmacro()
  209. endif()
  210. unset (_PYTHON_PREFIX)