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:
10 Find Python 2 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 2 interpreter
21 * ``Compiler``: search for Python 2 compiler. Only offered by IronPython.
22 * ``Development``: search for development artifacts (include directories and
25 .. versionadded:: 3.18
26 This component includes two sub-components which can be specified
29 * ``Development.Module``: search for artifacts for Python 2 module
31 * ``Development.Embed``: search for artifacts for Python 2 embedding
34 * ``NumPy``: search for NumPy include directories.
36 .. versionadded:: 3.14
37 Added the ``NumPy`` component.
39 If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
41 If component ``Development`` is specified, it implies sub-components
42 ``Development.Module`` and ``Development.Embed``.
44 To ensure consistent versions between components ``Interpreter``, ``Compiler``,
45 ``Development`` (or one of its sub-components) and ``NumPy``, specify all
46 components at the same time::
48 find_package (Python2 COMPONENTS Interpreter Development)
50 This module looks only for version 2 of Python. This module can be used
51 concurrently with :module:`FindPython3` module to use both Python versions.
53 The :module:`FindPython` module can be used if Python version does not matter
58 If components ``Interpreter`` and ``Development`` (or one of its
59 sub-components) are both specified, this module search only for interpreter
60 with same platform architecture as the one defined by ``CMake``
61 configuration. This constraint does not apply if only ``Interpreter``
62 component is specified.
67 This module defines the following :ref:`Imported Targets <Imported Targets>`:
69 .. versionchanged:: 3.14
70 :ref:`Imported Targets <Imported Targets>` are only created when
71 :prop_gbl:`CMAKE_ROLE` is ``PROJECT``.
73 ``Python2::Interpreter``
74 Python 2 interpreter. Target defined if component ``Interpreter`` is found.
76 Python 2 compiler. Target defined if component ``Compiler`` is found.
78 .. versionadded:: 3.15
80 Python 2 library for Python module. Target defined if component
81 ``Development.Module`` is found.
84 Python 2 library for Python embedding. Target defined if component
85 ``Development.Embed`` is found.
88 .. versionadded:: 3.14
90 NumPy library for Python 2. Target defined if component ``NumPy`` is found.
95 This module will set the following variables in your project
96 (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
99 System has the Python 2 requested components.
100 ``Python2_Interpreter_FOUND``
101 System has the Python 2 interpreter.
102 ``Python2_EXECUTABLE``
103 Path to the Python 2 interpreter.
104 ``Python2_INTERPRETER_ID``
105 A short string unique to the interpreter. Possible values include:
113 Standard platform independent installation directory.
115 Information returned by
116 ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``
117 or else ``sysconfig.get_path('stdlib')``.
119 Standard platform dependent installation directory.
121 Information returned by
122 ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``
123 or else ``sysconfig.get_path('platstdlib')``.
125 Third-party platform independent installation directory.
127 Information returned by
128 ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``
129 or else ``sysconfig.get_path('purelib')``.
131 Third-party platform dependent installation directory.
133 Information returned by
134 ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``
135 or else ``sysconfig.get_path('platlib')``.
136 ``Python2_Compiler_FOUND``
137 System has the Python 2 compiler.
139 Path to the Python 2 compiler. Only offered by IronPython.
140 ``Python2_COMPILER_ID``
141 A short string unique to the compiler. Possible values include:
144 ``Python2_DOTNET_LAUNCHER``
145 .. versionadded:: 3.18
147 The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
149 ``Python2_Development_FOUND``
150 System has the Python 2 development artifacts.
152 ``Python2_Development.Module_FOUND``
153 .. versionadded:: 3.18
155 System has the Python 2 development artifacts for Python module.
157 ``Python2_Development.Embed_FOUND``
158 .. versionadded:: 3.18
160 System has the Python 2 development artifacts for Python embedding.
162 ``Python2_INCLUDE_DIRS``
163 The Python 2 include directories.
165 ``Python2_LINK_OPTIONS``
166 .. versionadded:: 3.19
168 The Python 2 link options. Some configurations require specific link options
169 for a correct build and execution.
171 ``Python2_LIBRARIES``
172 The Python 2 libraries.
173 ``Python2_LIBRARY_DIRS``
174 The Python 2 library directories.
175 ``Python2_RUNTIME_LIBRARY_DIRS``
176 The Python 2 runtime library directories.
179 ``Python2_VERSION_MAJOR``
180 Python 2 major version.
181 ``Python2_VERSION_MINOR``
182 Python 2 minor version.
183 ``Python2_VERSION_PATCH``
184 Python 2 patch version.
186 ``Python2_PyPy_VERSION``
187 .. versionadded:: 3.18
189 Python 2 PyPy version.
191 ``Python2_NumPy_FOUND``
192 .. versionadded:: 3.14
194 System has the NumPy.
196 ``Python2_NumPy_INCLUDE_DIRS``
197 .. versionadded:: 3.14
199 The NumPy include directories.
201 ``Python2_NumPy_VERSION``
202 .. versionadded:: 3.14
210 Define the root directory of a Python 2 installation.
212 ``Python2_USE_STATIC_LIBS``
213 * If not defined, search for shared libraries and static libraries in that
215 * If set to TRUE, search **only** for static libraries.
216 * If set to FALSE, search **only** for shared libraries.
220 This hint will be ignored on ``Windows`` because static libraries are not
221 available on this platform.
223 ``Python2_FIND_STRATEGY``
224 .. versionadded:: 3.15
226 This variable defines how lookup will be done.
227 The ``Python2_FIND_STRATEGY`` variable can be set to one of the following:
229 * ``VERSION``: Try to find the most recent version in all specified
231 This is the default if policy :policy:`CMP0094` is undefined or set to
233 * ``LOCATION``: Stops lookup as soon as a version satisfying version
234 constraints is founded.
235 This is the default if policy :policy:`CMP0094` is set to ``NEW``.
237 ``Python2_FIND_REGISTRY``
238 .. versionadded:: 3.13
240 On Windows the ``Python2_FIND_REGISTRY`` variable determine the order
241 of preference between registry and environment variables.
242 the ``Python2_FIND_REGISTRY`` variable can be set to one of the following:
244 * ``FIRST``: Try to use registry before environment variables.
246 * ``LAST``: Try to use registry after environment variables.
247 * ``NEVER``: Never try to use registry.
249 ``Python2_FIND_FRAMEWORK``
250 .. versionadded:: 3.15
252 On macOS the ``Python2_FIND_FRAMEWORK`` variable determine the order of
253 preference between Apple-style and unix-style package components.
254 This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
259 Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
261 If ``Python2_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
262 variable will be used, if any.
264 ``Python2_FIND_VIRTUALENV``
265 .. versionadded:: 3.15
267 This variable defines the handling of virtual environments managed by
268 ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
269 is active (i.e. the ``activate`` script has been evaluated). In this case, it
270 takes precedence over ``Python2_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
271 variables. The ``Python2_FIND_VIRTUALENV`` variable can be set to one of the
274 * ``FIRST``: The virtual environment is used before any other standard
275 paths to look-up for the interpreter. This is the default.
276 * ``ONLY``: Only the virtual environment is used to look-up for the
278 * ``STANDARD``: The virtual environment is not used to look-up for the
279 interpreter but environment variable ``PATH`` is always considered.
280 In this case, variable ``Python2_FIND_REGISTRY`` (Windows) or
281 ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
282 ``NEVER`` to select preferably the interpreter from the virtual
285 .. versionadded:: 3.17
286 Added support for ``conda`` environments.
290 If the component ``Development`` is requested, it is **strongly**
291 recommended to also include the component ``Interpreter`` to get expected
294 ``Python2_FIND_IMPLEMENTATIONS``
295 .. versionadded:: 3.18
297 This variable defines, in an ordered list, the different implementations
298 which will be searched. The ``Python2_FIND_IMPLEMENTATIONS`` variable can
299 hold the following values:
301 * ``CPython``: this is the standard implementation. Various products, like
302 ``Anaconda`` or ``ActivePython``, rely on this implementation.
303 * ``IronPython``: This implementation use the ``CSharp`` language for
304 ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``).
305 See `IronPython <https://ironpython.net>`_.
306 * ``PyPy``: This implementation use ``RPython`` language and
307 ``RPython translation toolchain`` to produce the python interpreter.
308 See `PyPy <https://www.pypy.org>`_.
310 The default value is:
312 * Windows platform: ``CPython``, ``IronPython``
313 * Other platforms: ``CPython``
317 This hint has the lowest priority of all hints, so even if, for example,
318 you specify ``IronPython`` first and ``CPython`` in second, a python
319 product based on ``CPython`` can be selected because, for example with
320 ``Python2_FIND_STRATEGY=LOCATION``, each location will be search first for
321 ``IronPython`` and second for ``CPython``.
325 When ``IronPython`` is specified, on platforms other than ``Windows``, the
326 ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available
327 through the ``PATH`` variable.
329 ``Python2_FIND_UNVERSIONED_NAMES``
330 .. versionadded:: 3.20
332 This variable defines how the generic names will be searched. Currently, it
333 only applies to the generic names of the interpreter, namely, ``python2`` and
335 The ``Python2_FIND_UNVERSIONED_NAMES`` variable can be set to one of the
338 * ``FIRST``: The generic names are searched before the more specialized ones
339 (such as ``python2.5`` for example).
340 * ``LAST``: The generic names are searched after the more specialized ones.
342 * ``NEVER``: The generic name are not searched at all.
344 Artifacts Specification
345 ^^^^^^^^^^^^^^^^^^^^^^^
347 .. versionadded:: 3.16
349 To solve special cases, it is possible to specify directly the artifacts by
350 setting the following variables:
352 ``Python2_EXECUTABLE``
353 The path to the interpreter.
356 The path to the compiler.
358 ``Python2_DOTNET_LAUNCHER``
359 .. versionadded:: 3.18
361 The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
364 The path to the library. It will be used to compute the
365 variables ``Python2_LIBRARIES``, ``Python2_LIBRARY_DIRS`` and
366 ``Python2_RUNTIME_LIBRARY_DIRS``.
368 ``Python2_INCLUDE_DIR``
369 The path to the directory of the ``Python`` headers. It will be used to
370 compute the variable ``Python2_INCLUDE_DIRS``.
372 ``Python2_NumPy_INCLUDE_DIR``
373 The path to the directory of the ``NumPy`` headers. It will be used to
374 compute the variable ``Python2_NumPy_INCLUDE_DIRS``.
378 All paths must be absolute. Any artifact specified with a relative path
383 When an artifact is specified, all ``HINTS`` will be ignored and no search
384 will be performed for this artifact.
386 If more than one artifact is specified, it is the user's responsibility to
387 ensure the consistency of the various artifacts.
389 By default, this module supports multiple calls in different directories of a
390 project with different version/component requirements while providing correct
391 and consistent results for each call. To support this behavior, ``CMake`` cache
392 is not used in the traditional way which can be problematic for interactive
393 specification. So, to enable also interactive specification, module behavior
394 can be controlled with the following variable:
396 ``Python2_ARTIFACTS_INTERACTIVE``
397 .. versionadded:: 3.18
399 Selects the behavior of the module. This is a boolean variable:
401 * If set to ``TRUE``: Create CMake cache entries for the above artifact
402 specification variables so that users can edit them interactively.
403 This disables support for multiple version/component requirements.
404 * If set to ``FALSE`` or undefined: Enable multiple version/component
410 This module defines the command ``Python2_add_library`` (when
411 :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
412 :command:`add_library` and adds a dependency to target ``Python2::Python`` or,
413 when library type is ``MODULE``, to target ``Python2::Module`` and takes care
414 of Python module naming rules::
416 Python2_add_library (<name> [STATIC | SHARED | MODULE]
417 <source1> [<source2> ...])
419 If library type is not specified, ``MODULE`` is assumed.
420 #]=======================================================================]
423 set (_PYTHON_PREFIX Python2)
425 set (_Python2_REQUIRED_VERSION_MAJOR 2)
427 include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
429 if (COMMAND __Python2_add_library)
430 macro (Python2_add_library)
431 __Python2_add_library (Python2 ${ARGV})
435 unset (_PYTHON_PREFIX)