FindPython3.cmake 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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_STRATEGY``
  117. This variable defines how lookup will be done.
  118. The ``Python3_FIND_STRATEGY`` variable can be set to empty or one of the
  119. following:
  120. * ``VERSION``: Try to find the most recent version in all specified
  121. locations.
  122. This is the default if policy :policy:`CMP0094` is undefined or set to
  123. ``OLD``.
  124. * ``LOCATION``: Stops lookup as soon as a version satisfying version
  125. constraints is founded.
  126. This is the default if policy :policy:`CMP0094` is set to ``NEW``.
  127. ``Python3_FIND_REGISTRY``
  128. On Windows the ``Python3_FIND_REGISTRY`` variable determine the order
  129. of preference between registry and environment variables.
  130. The ``Python3_FIND_REGISTRY`` variable can be set to empty or one of the
  131. following:
  132. * ``FIRST``: Try to use registry before environment variables.
  133. This is the default.
  134. * ``LAST``: Try to use registry after environment variables.
  135. * ``NEVER``: Never try to use registry.
  136. ``Python3_FIND_FRAMEWORK``
  137. On macOS the ``Python3_FIND_FRAMEWORK`` variable determine the order of
  138. preference between Apple-style and unix-style package components.
  139. This variable can be set to empty or take same values as
  140. :variable:`CMAKE_FIND_FRAMEWORK` variable.
  141. .. note::
  142. Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
  143. If ``Python3_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
  144. variable will be used, if any.
  145. ``Python3_FIND_VIRTUALENV``
  146. This variable defines the handling of virtual environments. It is meaningfull
  147. only when a virtual environment is active (i.e. the ``activate`` script has
  148. been evaluated). In this case, it takes precedence over
  149. ``Python3_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK`` variables.
  150. The ``Python3_FIND_VIRTUALENV`` variable can be set to empty or one of the
  151. following:
  152. * ``FIRST``: The virtual environment is used before any other standard
  153. paths to look-up for the interpreter. This is the default.
  154. * ``ONLY``: Only the virtual environment is used to look-up for the
  155. interpreter.
  156. * ``STANDARD``: The virtual environment is not used to look-up for the
  157. interpreter. In this case, variable ``Python3_FIND_REGISTRY`` (Windows)
  158. or ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
  159. ``NEVER`` to select preferably the interpreter from the virtual
  160. environment.
  161. Commands
  162. ^^^^^^^^
  163. This module defines the command ``Python_add_library`` (when
  164. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
  165. :command:`add_library` and adds a dependency to target ``Python3::Python`` or,
  166. when library type is ``MODULE``, to target ``Python3::Module`` and takes care
  167. of Python module naming rules::
  168. Python3_add_library (my_module MODULE src1.cpp)
  169. If library type is not specified, ``MODULE`` is assumed.
  170. #]=======================================================================]
  171. set (_PYTHON_PREFIX Python3)
  172. set (_Python3_REQUIRED_VERSION_MAJOR 3)
  173. include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
  174. if (COMMAND __Python3_add_library)
  175. macro (Python3_add_library)
  176. __Python3_add_library (Python3 ${ARGV})
  177. endmacro()
  178. endif()
  179. unset (_PYTHON_PREFIX)