Find Python 2 interpreter, compiler and development environment (include directories and libraries).
The following components are supported:
If no COMPONENTS are specified, Interpreter is assumed.
If component Development is specified, it implies sub-components Development.Module and Development.Embed.
To ensure consistent versions between components Interpreter, Compiler, Development (or one of its sub-components) and NumPy, specify all components at the same time:
find_package (Python2 COMPONENTS Interpreter Development)
This module looks only for version 2 of Python. This module can be used concurrently with FindPython3 module to use both Python versions.
The FindPython module can be used if Python version does not matter for you.
Note
If components Interpreter and Development (or one of its sub-components) are both specified, this module search only for interpreter with same platform architecture as the one defined by CMake configuration. This contraint does not apply if only Interpreter component is specified.
This module defines the following Imported Targets (when CMAKE_ROLE is PROJECT):
This module will set the following variables in your project (see Standard Variable Names):
Standard platform independent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True) or else sysconfig.get_path('stdlib').
Standard platform dependent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True) or else sysconfig.get_path('platstdlib').
Third-party platform independent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False) or else sysconfig.get_path('purelib').
Third-party platform dependent installation directory.
Information returned by distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False) or else sysconfig.get_path('platlib').
This variable defines how lookup will be done. The Python2_FIND_STRATEGY variable can be set to one of the following:
On Windows the Python2_FIND_REGISTRY variable determine the order of preference between registry and environment variables. the Python2_FIND_REGISTRY variable can be set to one of the following:
On macOS the Python2_FIND_FRAMEWORK variable determine the order of preference between Apple-style and unix-style package components. This variable can take same values as CMAKE_FIND_FRAMEWORK variable.
Note
Value ONLY is not supported so FIRST will be used instead.
If Python2_FIND_FRAMEWORK is not defined, CMAKE_FIND_FRAMEWORK variable will be used, if any.
This variable defines the handling of virtual environments managed by virtualenv or conda. It is meaningful only when a virtual environment is active (i.e. the activate script has been evaluated). In this case, it takes precedence over Python2_FIND_REGISTRY and CMAKE_FIND_FRAMEWORK variables. The Python2_FIND_VIRTUALENV variable can be set to one of the following:
Note
If the component Development is requested, it is strongly recommended to also include the component Interpreter to get expected result.
This variable defines, in an ordered list, the different implementations which will be searched. The Python2_FIND_IMPLEMENTATIONS variable can hold the following values:
The default value is:
Note
This hint has the lowest priority of all hints, so even if, for example, you specify IronPython first and CPython in second, a python product based on CPython can be selected because, for example with Python2_FIND_STRATEGY=LOCATION, each location will be search first for IronPython and second for CPython.
Note
When IronPython is specified, on platforms other than Windows, the .Net interpreter (i.e. mono command) is expected to be available through the PATH variable.
To solve special cases, it is possible to specify directly the artifacts by setting the following variables:
Note
All paths must be absolute. Any artifact specified with a relative path will be ignored.
Note
When an artifact is specified, all HINTS will be ignored and no search will be performed for this artifact.
If more than one artifact is specified, it is the user’s responsability to ensure the consistency of the various artifacts.
By default, this module supports multiple calls in different directories of a project with different version/component requirements while providing correct and consistent results for each call. To support this behavior, CMake cache is not used in the traditional way which can be problematic for interactive specification. So, to enable also interactive specification, module behavior can be controled with the following variable:
Selects the behavior of the module. This is a boolean variable:
This module defines the command Python2_add_library (when CMAKE_ROLE is PROJECT), which has the same semantics as add_library() and adds a dependency to target Python2::Python or, when library type is MODULE, to target Python2::Module and takes care of Python module naming rules:
Python2_add_library (<name> [STATIC | SHARED | MODULE]
<source1> [<source2> ...])
If library type is not specified, MODULE is assumed.