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: 8 Find Python 3 interpreter, compiler and development environment (include
9 directories and libraries).
11 The following components are supported:
13 * ``Interpreter``: search
for Python 3 interpreter
14 * ``Compiler``: search
for Python 3 compiler. Only offered by IronPython.
15 * ``Development``: search
for development artifacts (include directories and
16 libraries). This
component includes two sub-components which can be specified
19 * ``Development.Module``: search
for artifacts
for Python 3 module
21 * ``Development.Embed``: search
for artifacts
for Python 3 embedding
24 * ``NumPy``: search
for NumPy include directories.
26 If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
28 If
component ``Development`` is specified, it implies sub-components
29 ``Development.Module`` and ``Development.Embed``.
31 To ensure consistent versions between components ``Interpreter``, ``Compiler``,
32 ``Development`` (or one of its sub-components) and ``NumPy``, specify all
33 components at the same time::
35 find_package (Python3 COMPONENTS Interpreter Development)
37 This module looks only
for version 3 of Python. This module can be used
38 concurrently with :module:`FindPython2` module to use both Python versions.
40 The :module:`FindPython` module can be used
if Python
version does not matter
45 If components ``Interpreter`` and ``Development`` (or one of its
46 sub-components) are both specified,
this module search only
for interpreter
47 with same platform architecture as the one defined by ``CMake``
48 configuration. This contraint does not apply
if only ``Interpreter``
49 component is specified.
54 This module defines the following :ref:`Imported Targets <Imported Targets>`
55 (when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
57 ``Python3::Interpreter``
58 Python 3 interpreter. Target defined
if component ``Interpreter`` is found.
60 Python 3 compiler. Target defined
if component ``Compiler`` is found.
62 Python 3 library
for Python module. Target defined
if component 63 ``Development.Module`` is found.
65 Python 3 library
for Python embedding. Target defined
if component 66 ``Development.Embed`` is found.
68 NumPy library
for Python 3. Target defined
if component ``NumPy`` is found.
73 This module will
set the following variables in your project
74 (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
77 System has the Python 3 requested components.
78 ``Python3_Interpreter_FOUND``
79 System has the Python 3 interpreter.
80 ``Python3_EXECUTABLE``
81 Path to the Python 3 interpreter.
82 ``Python3_INTERPRETER_ID``
83 A short
string unique to the interpreter. Possible values include:
90 Standard platform independent installation directory.
92 Information returned by
93 ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``
94 or else ``sysconfig.get_path(
'stdlib')``.
96 Standard platform dependent installation directory.
98 Information returned by
99 ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``
100 or else ``sysconfig.get_path(
'platstdlib')``.
102 Third-party platform independent installation directory.
104 Information returned by
105 ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``
106 or else ``sysconfig.get_path(
'purelib')``.
108 Third-party platform dependent installation directory.
110 Information returned by
111 ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``
112 or else ``sysconfig.get_path(
'platlib')``.
114 Extension suffix for modules.
116 Information returned by
117 ``distutils.sysconfig.get_config_var(
'SOABI')`` or computed from
118 ``distutils.sysconfig.get_config_var(
'EXT_SUFFIX')`` or
119 ``python3-config --extension-suffix``. If package ``distutils.sysconfig`` is
120 not available, ``sysconfig.get_config_var(
'SOABI')`` or
121 ``sysconfig.get_config_var(
'EXT_SUFFIX')`` are used.
122 ``Python3_Compiler_FOUND``
123 System has the Python 3 compiler.
125 Path to the Python 3 compiler. Only offered by IronPython.
126 ``Python3_COMPILER_ID``
127 A short
string unique to the compiler. Possible values include:
129 ``Python3_Development_FOUND``
130 System has the Python 3 development artifacts.
131 ``Python3_Development.Module_FOUND``
132 System has the Python 3 development artifacts for Python module.
133 ``Python3_Development.Embed_FOUND``
134 System has the Python 3 development artifacts for Python embedding.
135 ``Python3_INCLUDE_DIRS``
136 The Python 3 include directories.
137 ``Python3_LIBRARIES``
138 The Python 3 libraries.
139 ``Python3_LIBRARY_DIRS``
140 The Python 3 library directories.
141 ``Python3_RUNTIME_LIBRARY_DIRS``
142 The Python 3 runtime library directories.
145 ``Python3_VERSION_MAJOR``
147 ``Python3_VERSION_MINOR``
149 ``Python3_VERSION_PATCH``
151 ``Python3_NumPy_FOUND``
152 System has the NumPy.
153 ``Python3_NumPy_INCLUDE_DIRS``
154 The NumPy include directries.
155 ``Python3_NumPy_VERSION``
162 Define the root directory of a Python 3 installation.
164 ``Python3_USE_STATIC_LIBS``
165 * If not defined, search for shared libraries and static libraries in that
167 * If set to TRUE, search **only** for static libraries.
168 * If set to FALSE, search **only** for shared libraries.
171 This variable defines which ABIs, as defined in
176 If ``Python3_FIND_ABI`` is not defined, any ABI will be searched.
178 The ``Python3_FIND_ABI`` variable is a 3-tuple specifying, in that
order,
179 ``pydebug`` (``d``), ``pymalloc`` (``m``) and ``unicode`` (``u``) flags.
180 Each element can be set to one of the following:
182 * ``ON``: Corresponding flag is selected.
183 * ``OFF``: Corresponding flag is not selected.
184 * ``ANY``: The two posibilties (``ON`` and ``OFF``) will be searched.
186 From this 3-tuple, various ABIs will be searched starting from the most
187 specialized to the most general. Moreover, ``debug`` versions will be
188 searched **after** ``non-debug`` ones.
190 For example, if we have::
192 set (Python3_FIND_ABI
"ON" "ANY" "ANY")
194 The following flags combinations will be appended, in that
order, to the
195 artifact names: ``dmu``, ``dm``, ``du``, and ``d``.
197 And to search any possible ABIs::
199 set (Python3_FIND_ABI
"ANY" "ANY" "ANY")
201 The following combinations, in that
order, will be used: ``mu``, ``m``,
202 ``u``, ``<empty>``, ``dmu``, ``dm``, ``du`` and ``d``.
206 This hint is useful only
on ``POSIX`` systems. So,
on ``Windows`` systems,
207 when ``Python3_FIND_ABI`` is defined, ``Python`` distributions from
209 each flag is ``OFF`` or ``ANY``.
211 ``Python3_FIND_STRATEGY``
212 This variable defines how lookup will be done.
213 The ``Python3_FIND_STRATEGY`` variable can be set to one of the following:
215 * ``
VERSION``: Try to find the most recent
version in all specified
217 This is the default if policy :policy:`CMP0094` is undefined or set to
219 * ``LOCATION``: Stops lookup as soon as a
version satisfying
version 220 constraints is founded.
221 This is the default if policy :policy:`CMP0094` is set to ``NEW``.
223 ``Python3_FIND_REGISTRY``
224 On Windows the ``Python3_FIND_REGISTRY`` variable determine the
order 225 of preference between registry and environment variables.
226 The ``Python3_FIND_REGISTRY`` variable can be set to one of the following:
228 * ``FIRST``: Try to use registry before environment variables.
230 * ``LAST``: Try to use registry after environment variables.
231 * ``NEVER``: Never try to use registry.
233 ``Python3_FIND_FRAMEWORK``
234 On macOS the ``Python3_FIND_FRAMEWORK`` variable determine the
order of
235 preference between Apple-
style and unix-
style package components.
236 This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
241 Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
243 If ``Python3_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
244 variable will be used, if any.
246 ``Python3_FIND_VIRTUALENV``
247 This variable defines the handling of virtual environments managed by
248 ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
249 is active (i.e. the ``activate`` script has been evaluated). In this case, it
250 takes precedence over ``Python3_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
251 variables. The ``Python3_FIND_VIRTUALENV`` variable can be set to one of the
254 * ``FIRST``: The virtual environment is used before any other standard
255 paths to look-up for the interpreter. This is the default.
256 * ``ONLY``: Only the virtual environment is used to look-up for the
258 * ``STANDARD``: The virtual environment is not used to look-up for the
259 interpreter but environment variable ``PATH`` is always considered.
260 In this case, variable ``Python3_FIND_REGISTRY`` (Windows) or
261 ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with
value ``LAST`` or
262 ``NEVER`` to select preferably the interpreter from the virtual
267 If the
component ``Development`` is requested, it is **strongly**
268 recommended to also include the
component ``Interpreter`` to
get expected
271 Artifacts Specification
272 ^^^^^^^^^^^^^^^^^^^^^^^
274 To solve special cases, it is possible to specify directly the artifacts by
275 setting the following variables:
277 ``Python3_EXECUTABLE``
278 The path to the interpreter.
281 The path to the compiler.
284 The path to the library. It will be used to compute the
285 variables ``Python3_LIBRARIES``, ``Python3_LIBRAY_DIRS`` and
286 ``Python3_RUNTIME_LIBRARY_DIRS``.
288 ``Python3_INCLUDE_DIR``
289 The path to the directory of the ``Python`` headers. It will be used to
290 compute the variable ``Python3_INCLUDE_DIRS``.
292 ``Python3_NumPy_INCLUDE_DIR``
293 The path to the directory of the ``NumPy`` headers. It will be used to
294 compute the variable ``Python3_NumPy_INCLUDE_DIRS``.
298 All paths must be absolute. Any artifact specified with a relative path
303 When an artifact is specified, all ``HINTS`` will be ignored and no search
304 will be performed for this artifact.
306 If more than one artifact is specified, it is the user
's responsability to 307 ensure the consistency of the various artifacts. 309 By default, this module supports multiple calls in different directories of a 310 project with different version/component requirements while providing correct 311 and consistent results for each call. To support this behavior, ``CMake`` cache 312 is not used in the traditional way which can be problematic for interactive 313 specification. So, to enable also interactive specification, module behavior 314 can be controled with the following variable: 316 ``Python3_ARTIFACTS_INTERACTIVE`` 317 Selects the behavior of the module. This is a boolean variable: 319 * If set to ``TRUE``: Create CMake cache entries for the above artifact 320 specification variables so that users can edit them interactively. 321 This disables support for multiple version/component requirements. 322 * If set to ``FALSE`` or undefined: Enable multiple version/component 328 This module defines the command ``Python3_add_library`` (when 329 :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as 330 :command:`add_library` and adds a dependency to target ``Python3::Python`` or, 331 when library type is ``MODULE``, to target ``Python3::Module`` and takes care 332 of Python module naming rules:: 334 Python3_add_library (<name> [STATIC | SHARED | MODULE [WITH_SOABI]] 335 <source1> [<source2> ...]) 337 If the library type is not specified, ``MODULE`` is assumed. 339 For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the 340 module suffix will include the ``Python3_SOABI`` value, if any. 341 #]=======================================================================] 344 set (_PYTHON_PREFIX Python3) 346 set (_Python3_REQUIRED_VERSION_MAJOR 3) 348 include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake) 350 if (COMMAND __Python3_add_library) 351 macro (Python3_add_library) 352 __Python3_add_library (Python3 ${ARGV}) 356 unset (_PYTHON_PREFIX)
double get(vtkDataArray *const &arr, vtkIdType key)