FindPython3.cmake
Go to the documentation of this file.
1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3 
4 #[=======================================================================[.rst:
5 FindPython3
6 -----------
7 
8 Find Python 3 interpreter, compiler and development environment (include
9 directories and libraries).
10 
11 The following components are supported:
12 
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
17  independently:
18 
19  * ``Development.Module``: search for artifacts for Python 3 module
20  developments.
21  * ``Development.Embed``: search for artifacts for Python 3 embedding
22  developments.
23 
24 * ``NumPy``: search for NumPy include directories.
25 
26 If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
27 
28 If component ``Development`` is specified, it implies sub-components
29 ``Development.Module`` and ``Development.Embed``.
30 
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::
34 
35  find_package (Python3 COMPONENTS Interpreter Development)
36 
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.
39 
40 The :module:`FindPython` module can be used if Python version does not matter
41 for you.
42 
43 .. note::
44 
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.
50 
51 Imported Targets
52 ^^^^^^^^^^^^^^^^
53 
54 This module defines the following :ref:`Imported Targets <Imported Targets>`
55 (when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
56 
57 ``Python3::Interpreter``
58  Python 3 interpreter. Target defined if component ``Interpreter`` is found.
59 ``Python3::Compiler``
60  Python 3 compiler. Target defined if component ``Compiler`` is found.
61 ``Python3::Module``
62  Python 3 library for Python module. Target defined if component
63  ``Development.Module`` is found.
64 ``Python3::Python``
65  Python 3 library for Python embedding. Target defined if component
66  ``Development.Embed`` is found.
67 ``Python3::NumPy``
68  NumPy library for Python 3. Target defined if component ``NumPy`` is found.
69 
70 Result Variables
71 ^^^^^^^^^^^^^^^^
72 
73 This module will set the following variables in your project
74 (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
75 
76 ``Python3_FOUND``
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:
84  * Python
85  * ActivePython
86  * Anaconda
87  * Canopy
88  * IronPython
89 ``Python3_STDLIB``
90  Standard platform independent installation directory.
91 
92  Information returned by
93  ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``
94  or else ``sysconfig.get_path('stdlib')``.
95 ``Python3_STDARCH``
96  Standard platform dependent installation directory.
97 
98  Information returned by
99  ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``
100  or else ``sysconfig.get_path('platstdlib')``.
101 ``Python3_SITELIB``
102  Third-party platform independent installation directory.
103 
104  Information returned by
105  ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``
106  or else ``sysconfig.get_path('purelib')``.
107 ``Python3_SITEARCH``
108  Third-party platform dependent installation directory.
109 
110  Information returned by
111  ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``
112  or else ``sysconfig.get_path('platlib')``.
113 ``Python3_SOABI``
114  Extension suffix for modules.
115 
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.
124 ``Python3_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:
128  * IronPython
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.
143 ``Python3_VERSION``
144  Python 3 version.
145 ``Python3_VERSION_MAJOR``
146  Python 3 major version.
147 ``Python3_VERSION_MINOR``
148  Python 3 minor version.
149 ``Python3_VERSION_PATCH``
150  Python 3 patch version.
151 ``Python3_NumPy_FOUND``
152  System has the NumPy.
153 ``Python3_NumPy_INCLUDE_DIRS``
154  The NumPy include directries.
155 ``Python3_NumPy_VERSION``
156  The NumPy version.
157 
158 Hints
159 ^^^^^
160 
161 ``Python3_ROOT_DIR``
162  Define the root directory of a Python 3 installation.
163 
164 ``Python3_USE_STATIC_LIBS``
165  * If not defined, search for shared libraries and static libraries in that
166  order.
167  * If set to TRUE, search **only** for static libraries.
168  * If set to FALSE, search **only** for shared libraries.
169 
170 ``Python3_FIND_ABI``
171  This variable defines which ABIs, as defined in
172  `PEP 3149 <https://www.python.org/dev/peps/pep-3149/>`_, should be searched.
173 
174  .. note::
175 
176  If ``Python3_FIND_ABI`` is not defined, any ABI will be searched.
177 
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:
181 
182  * ``ON``: Corresponding flag is selected.
183  * ``OFF``: Corresponding flag is not selected.
184  * ``ANY``: The two posibilties (``ON`` and ``OFF``) will be searched.
185 
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.
189 
190  For example, if we have::
191 
192  set (Python3_FIND_ABI "ON" "ANY" "ANY")
193 
194  The following flags combinations will be appended, in that order, to the
195  artifact names: ``dmu``, ``dm``, ``du``, and ``d``.
196 
197  And to search any possible ABIs::
198 
199  set (Python3_FIND_ABI "ANY" "ANY" "ANY")
200 
201  The following combinations, in that order, will be used: ``mu``, ``m``,
202  ``u``, ``<empty>``, ``dmu``, ``dm``, ``du`` and ``d``.
203 
204  .. note::
205 
206  This hint is useful only on ``POSIX`` systems. So, on ``Windows`` systems,
207  when ``Python3_FIND_ABI`` is defined, ``Python`` distributions from
208  `python.org <https://www.python.org/>`_ will be found only if value for
209  each flag is ``OFF`` or ``ANY``.
210 
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:
214 
215  * ``VERSION``: Try to find the most recent version in all specified
216  locations.
217  This is the default if policy :policy:`CMP0094` is undefined or set to
218  ``OLD``.
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``.
222 
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:
227 
228  * ``FIRST``: Try to use registry before environment variables.
229  This is the default.
230  * ``LAST``: Try to use registry after environment variables.
231  * ``NEVER``: Never try to use registry.
232 
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`
237  variable.
238 
239  .. note::
240 
241  Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
242 
243  If ``Python3_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
244  variable will be used, if any.
245 
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
252  following:
253 
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
257  interpreter.
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
263  environment.
264 
265  .. note::
266 
267  If the component ``Development`` is requested, it is **strongly**
268  recommended to also include the component ``Interpreter`` to get expected
269  result.
270 
271 Artifacts Specification
272 ^^^^^^^^^^^^^^^^^^^^^^^
273 
274 To solve special cases, it is possible to specify directly the artifacts by
275 setting the following variables:
276 
277 ``Python3_EXECUTABLE``
278  The path to the interpreter.
279 
280 ``Python3_COMPILER``
281  The path to the compiler.
282 
283 ``Python3_LIBRARY``
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``.
287 
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``.
291 
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``.
295 
296 .. note::
297 
298  All paths must be absolute. Any artifact specified with a relative path
299  will be ignored.
300 
301 .. note::
302 
303  When an artifact is specified, all ``HINTS`` will be ignored and no search
304  will be performed for this artifact.
305 
306  If more than one artifact is specified, it is the user's responsability to
307  ensure the consistency of the various artifacts.
308 
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:
315 
316 ``Python3_ARTIFACTS_INTERACTIVE``
317  Selects the behavior of the module. This is a boolean variable:
318 
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
323  requirements.
324 
325 Commands
326 ^^^^^^^^
327 
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::
333 
334  Python3_add_library (<name> [STATIC | SHARED | MODULE [WITH_SOABI]]
335  <source1> [<source2> ...])
336 
337 If the library type is not specified, ``MODULE`` is assumed.
338 
339 For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the
340 module suffix will include the ``Python3_SOABI`` value, if any.
341 #]=======================================================================]
342 
343 
344 set (_PYTHON_PREFIX Python3)
345 
346 set (_Python3_REQUIRED_VERSION_MAJOR 3)
347 
348 include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
349 
350 if (COMMAND __Python3_add_library)
351  macro (Python3_add_library)
352  __Python3_add_library (Python3 ${ARGV})
353  endmacro()
354 endif()
355 
356 unset (_PYTHON_PREFIX)
component
style
order
double get(vtkDataArray *const &arr, vtkIdType key)
on
version
string
#define VERSION
Definition: jconfigint.h:17
value