FindPython2.cmake 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. FindPython2
  5. -----------
  6. Find Python 2 interpreter, compiler and development environment (include
  7. directories and libraries).
  8. The following components are supported:
  9. * ``Interpreter``: search for Python 2 interpreter
  10. * ``Compiler``: search for Python 2 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`` are 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 (Python2 COMPONENTS Interpreter Development)
  18. This module looks only for version 2 of Python. This module can be used
  19. concurrently with :module:`FindPython3` 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. ``Python2::Interpreter``
  32. Python 2 interpreter. Target defined if component ``Interpreter`` is found.
  33. ``Python2::Compiler``
  34. Python 2 compiler. Target defined if component ``Compiler`` is found.
  35. ``Python2::Python``
  36. Python 2 library for Python embedding. Target defined if component
  37. ``Development`` is found.
  38. ``Python2::Module``
  39. Python 2 library for Python module. Target defined if component
  40. ``Development`` is found.
  41. ``Python2::NumPy``
  42. NumPy library for Python 2. 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. ``Python2_FOUND``
  48. System has the Python 2 requested components.
  49. ``Python2_Interpreter_FOUND``
  50. System has the Python 2 interpreter.
  51. ``Python2_EXECUTABLE``
  52. Path to the Python 2 interpreter.
  53. ``Python2_INTERPRETER_ID``
  54. A short string unique to the interpreter. Possible values include:
  55. * Python
  56. * ActivePython
  57. * Anaconda
  58. * Canopy
  59. * IronPython
  60. ``Python2_STDLIB``
  61. Standard platform independent installation directory.
  62. Information returned by
  63. ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``
  64. or else ``sysconfig.get_path('stdlib')``.
  65. ``Python2_STDARCH``
  66. Standard platform dependent installation directory.
  67. Information returned by
  68. ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``
  69. or else ``sysconfig.get_path('platstdlib')``.
  70. ``Python2_SITELIB``
  71. Third-party platform independent installation directory.
  72. Information returned by
  73. ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``
  74. or else ``sysconfig.get_path('purelib')``.
  75. ``Python2_SITEARCH``
  76. Third-party platform dependent installation directory.
  77. Information returned by
  78. ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``
  79. or else ``sysconfig.get_path('platlib')``.
  80. ``Python2_Compiler_FOUND``
  81. System has the Python 2 compiler.
  82. ``Python2_COMPILER``
  83. Path to the Python 2 compiler. Only offered by IronPython.
  84. ``Python2_COMPILER_ID``
  85. A short string unique to the compiler. Possible values include:
  86. * IronPython
  87. ``Python2_Development_FOUND``
  88. System has the Python 2 development artifacts.
  89. ``Python2_INCLUDE_DIRS``
  90. The Python 2 include directories.
  91. ``Python2_LIBRARIES``
  92. The Python 2 libraries.
  93. ``Python2_LIBRARY_DIRS``
  94. The Python 2 library directories.
  95. ``Python2_RUNTIME_LIBRARY_DIRS``
  96. The Python 2 runtime library directories.
  97. ``Python2_VERSION``
  98. Python 2 version.
  99. ``Python2_VERSION_MAJOR``
  100. Python 2 major version.
  101. ``Python2_VERSION_MINOR``
  102. Python 2 minor version.
  103. ``Python2_VERSION_PATCH``
  104. Python 2 patch version.
  105. ``Python2_NumPy_FOUND``
  106. System has the NumPy.
  107. ``Python2_NumPy_INCLUDE_DIRS``
  108. The NumPy include directries.
  109. ``Python2_NumPy_VERSION``
  110. The NumPy version.
  111. Hints
  112. ^^^^^
  113. ``Python2_ROOT_DIR``
  114. Define the root directory of a Python 2 installation.
  115. ``Python2_USE_STATIC_LIBS``
  116. * If not defined, search for shared libraries and static libraries in that
  117. order.
  118. * If set to TRUE, search **only** for static libraries.
  119. * If set to FALSE, search **only** for shared libraries.
  120. ``Python2_FIND_STRATEGY``
  121. This variable defines how lookup will be done.
  122. The ``Python2_FIND_STRATEGY`` variable can be set to one of the following:
  123. * ``VERSION``: Try to find the most recent version in all specified
  124. locations.
  125. This is the default if policy :policy:`CMP0094` is undefined or set to
  126. ``OLD``.
  127. * ``LOCATION``: Stops lookup as soon as a version satisfying version
  128. constraints is founded.
  129. This is the default if policy :policy:`CMP0094` is set to ``NEW``.
  130. ``Python2_FIND_REGISTRY``
  131. On Windows the ``Python2_FIND_REGISTRY`` variable determine the order
  132. of preference between registry and environment variables.
  133. the ``Python2_FIND_REGISTRY`` variable can be set to one of the following:
  134. * ``FIRST``: Try to use registry before environment variables.
  135. This is the default.
  136. * ``LAST``: Try to use registry after environment variables.
  137. * ``NEVER``: Never try to use registry.
  138. ``Python2_FIND_FRAMEWORK``
  139. On macOS the ``Python2_FIND_FRAMEWORK`` variable determine the order of
  140. preference between Apple-style and unix-style package components.
  141. This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
  142. variable.
  143. .. note::
  144. Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
  145. If ``Python2_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
  146. variable will be used, if any.
  147. ``Python2_FIND_VIRTUALENV``
  148. This variable defines the handling of virtual environments managed by
  149. ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
  150. is active (i.e. the ``activate`` script has been evaluated). In this case, it
  151. takes precedence over ``Python2_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
  152. variables. The ``Python2_FIND_VIRTUALENV`` variable can be set to one of the
  153. following:
  154. * ``FIRST``: The virtual environment is used before any other standard
  155. paths to look-up for the interpreter. This is the default.
  156. * ``ONLY``: Only the virtual environment is used to look-up for the
  157. interpreter.
  158. * ``STANDARD``: The virtual environment is not used to look-up for the
  159. interpreter but environment variable ``PATH`` is always considered.
  160. In this case, variable ``Python2_FIND_REGISTRY`` (Windows) or
  161. ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
  162. ``NEVER`` to select preferably the interpreter from the virtual
  163. environment.
  164. .. note::
  165. If the component ``Development`` is requested, it is **strongly**
  166. recommended to also include the component ``Interpreter`` to get expected
  167. result.
  168. Artifacts Specification
  169. ^^^^^^^^^^^^^^^^^^^^^^^
  170. To solve special cases, it is possible to specify directly the artifacts by
  171. setting the following variables:
  172. ``Python2_EXECUTABLE``
  173. The path to the interpreter.
  174. ``Python2_COMPILER``
  175. The path to the compiler.
  176. ``Python2_LIBRARY``
  177. The path to the library. It will be used to compute the
  178. variables ``Python2_LIBRARIES``, ``Python2_LIBRAY_DIRS`` and
  179. ``Python2_RUNTIME_LIBRARY_DIRS``.
  180. ``Python2_INCLUDE_DIR``
  181. The path to the directory of the ``Python`` headers. It will be used to
  182. compute the variable ``Python2_INCLUDE_DIRS``.
  183. ``Python2_NumPy_INCLUDE_DIR``
  184. The path to the directory of the ``NumPy`` headers. It will be used to
  185. compute the variable ``Python2_NumPy_INCLUDE_DIRS``.
  186. .. note::
  187. All paths must be absolute. Any artifact specified with a relative path
  188. will be ignored.
  189. .. note::
  190. When an artifact is specified, all ``HINTS`` will be ignored and no search
  191. will be performed for this artifact.
  192. If more than one artifact is specified, it is the user's responsability to
  193. ensure the consistency of the various artifacts.
  194. By default, this module supports multiple calls in different directories of a
  195. project with different version/component requirements while providing correct
  196. and consistent results for each call. To support this behavior, ``CMake`` cache
  197. is not used in the traditional way which can be problematic for interactive
  198. specification. So, to enable also interactive specification, module behavior
  199. can be controled with the following variable:
  200. ``Python2_ARTIFACTS_INTERACTIVE``
  201. Selects the behavior of the module. This is a boolean variable:
  202. * If set to ``TRUE``: Create CMake cache entries for the above artifact
  203. specification variables so that users can edit them interactively.
  204. This disables support for multiple version/component requirements.
  205. * If set to ``FALSE`` or undefined: Enable multiple version/component
  206. requirements.
  207. Commands
  208. ^^^^^^^^
  209. This module defines the command ``Python2_add_library`` (when
  210. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
  211. :command:`add_library` and adds a dependency to target ``Python2::Python`` or,
  212. when library type is ``MODULE``, to target ``Python2::Module`` and takes care
  213. of Python module naming rules::
  214. Python2_add_library (<name> [STATIC | SHARED | MODULE]
  215. <source1> [<source2> ...])
  216. If library type is not specified, ``MODULE`` is assumed.
  217. #]=======================================================================]
  218. set (_PYTHON_PREFIX Python2)
  219. set (_Python2_REQUIRED_VERSION_MAJOR 2)
  220. include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
  221. if (COMMAND __Python2_add_library)
  222. macro (Python2_add_library)
  223. __Python2_add_library (Python2 ${ARGV})
  224. endmacro()
  225. endif()
  226. unset (_PYTHON_PREFIX)