FindPython2.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 FindPython2
6 -----------
7 
8 Find Python 2 interpreter, compiler and development environment (include
9 directories and libraries).
10 
11 The following components are supported:
12 
13 * ``Interpreter``: search for Python 2 interpreter
14 * ``Compiler``: search for Python 2 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 2 module
20  developments.
21  * ``Development.Embed``: search for artifacts for Python 2 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 (Python2 COMPONENTS Interpreter Development)
36 
37 This module looks only for version 2 of Python. This module can be used
38 concurrently with :module:`FindPython3` 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 ``Python2::Interpreter``
58  Python 2 interpreter. Target defined if component ``Interpreter`` is found.
59 ``Python2::Compiler``
60  Python 2 compiler. Target defined if component ``Compiler`` is found.
61 ``Python2::Module``
62  Python 2 library for Python module. Target defined if component
63  ``Development.Module`` is found.
64 ``Python2::Python``
65  Python 2 library for Python embedding. Target defined if component
66  ``Development.Embed`` is found.
67 ``Python2::NumPy``
68  NumPy library for Python 2. 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 ``Python2_FOUND``
77  System has the Python 2 requested components.
78 ``Python2_Interpreter_FOUND``
79  System has the Python 2 interpreter.
80 ``Python2_EXECUTABLE``
81  Path to the Python 2 interpreter.
82 ``Python2_INTERPRETER_ID``
83  A short string unique to the interpreter. Possible values include:
84  * Python
85  * ActivePython
86  * Anaconda
87  * Canopy
88  * IronPython
89 ``Python2_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 ``Python2_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 ``Python2_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 ``Python2_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 ``Python2_Compiler_FOUND``
114  System has the Python 2 compiler.
115 ``Python2_COMPILER``
116  Path to the Python 2 compiler. Only offered by IronPython.
117 ``Python2_COMPILER_ID``
118  A short string unique to the compiler. Possible values include:
119  * IronPython
120 ``Python2_Development_FOUND``
121  System has the Python 2 development artifacts.
122 ``Python2_Development.Module_FOUND``
123  System has the Python 2 development artifacts for Python module.
124 ``Python2_Development.Embed_FOUND``
125  System has the Python 2 development artifacts for Python embedding.
126 ``Python2_INCLUDE_DIRS``
127  The Python 2 include directories.
128 ``Python2_LIBRARIES``
129  The Python 2 libraries.
130 ``Python2_LIBRARY_DIRS``
131  The Python 2 library directories.
132 ``Python2_RUNTIME_LIBRARY_DIRS``
133  The Python 2 runtime library directories.
134 ``Python2_VERSION``
135  Python 2 version.
136 ``Python2_VERSION_MAJOR``
137  Python 2 major version.
138 ``Python2_VERSION_MINOR``
139  Python 2 minor version.
140 ``Python2_VERSION_PATCH``
141  Python 2 patch version.
142 ``Python2_NumPy_FOUND``
143  System has the NumPy.
144 ``Python2_NumPy_INCLUDE_DIRS``
145  The NumPy include directries.
146 ``Python2_NumPy_VERSION``
147  The NumPy version.
148 
149 Hints
150 ^^^^^
151 
152 ``Python2_ROOT_DIR``
153  Define the root directory of a Python 2 installation.
154 
155 ``Python2_USE_STATIC_LIBS``
156  * If not defined, search for shared libraries and static libraries in that
157  order.
158  * If set to TRUE, search **only** for static libraries.
159  * If set to FALSE, search **only** for shared libraries.
160 
161 ``Python2_FIND_STRATEGY``
162  This variable defines how lookup will be done.
163  The ``Python2_FIND_STRATEGY`` variable can be set to one of the following:
164 
165  * ``VERSION``: Try to find the most recent version in all specified
166  locations.
167  This is the default if policy :policy:`CMP0094` is undefined or set to
168  ``OLD``.
169  * ``LOCATION``: Stops lookup as soon as a version satisfying version
170  constraints is founded.
171  This is the default if policy :policy:`CMP0094` is set to ``NEW``.
172 
173 ``Python2_FIND_REGISTRY``
174  On Windows the ``Python2_FIND_REGISTRY`` variable determine the order
175  of preference between registry and environment variables.
176  the ``Python2_FIND_REGISTRY`` variable can be set to one of the following:
177 
178  * ``FIRST``: Try to use registry before environment variables.
179  This is the default.
180  * ``LAST``: Try to use registry after environment variables.
181  * ``NEVER``: Never try to use registry.
182 
183 ``Python2_FIND_FRAMEWORK``
184  On macOS the ``Python2_FIND_FRAMEWORK`` variable determine the order of
185  preference between Apple-style and unix-style package components.
186  This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
187  variable.
188 
189  .. note::
190 
191  Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
192 
193  If ``Python2_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
194  variable will be used, if any.
195 
196 ``Python2_FIND_VIRTUALENV``
197  This variable defines the handling of virtual environments managed by
198  ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
199  is active (i.e. the ``activate`` script has been evaluated). In this case, it
200  takes precedence over ``Python2_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
201  variables. The ``Python2_FIND_VIRTUALENV`` variable can be set to one of the
202  following:
203 
204  * ``FIRST``: The virtual environment is used before any other standard
205  paths to look-up for the interpreter. This is the default.
206  * ``ONLY``: Only the virtual environment is used to look-up for the
207  interpreter.
208  * ``STANDARD``: The virtual environment is not used to look-up for the
209  interpreter but environment variable ``PATH`` is always considered.
210  In this case, variable ``Python2_FIND_REGISTRY`` (Windows) or
211  ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
212  ``NEVER`` to select preferably the interpreter from the virtual
213  environment.
214 
215  .. note::
216 
217  If the component ``Development`` is requested, it is **strongly**
218  recommended to also include the component ``Interpreter`` to get expected
219  result.
220 
221 Artifacts Specification
222 ^^^^^^^^^^^^^^^^^^^^^^^
223 
224 To solve special cases, it is possible to specify directly the artifacts by
225 setting the following variables:
226 
227 ``Python2_EXECUTABLE``
228  The path to the interpreter.
229 
230 ``Python2_COMPILER``
231  The path to the compiler.
232 
233 ``Python2_LIBRARY``
234  The path to the library. It will be used to compute the
235  variables ``Python2_LIBRARIES``, ``Python2_LIBRAY_DIRS`` and
236  ``Python2_RUNTIME_LIBRARY_DIRS``.
237 
238 ``Python2_INCLUDE_DIR``
239  The path to the directory of the ``Python`` headers. It will be used to
240  compute the variable ``Python2_INCLUDE_DIRS``.
241 
242 ``Python2_NumPy_INCLUDE_DIR``
243  The path to the directory of the ``NumPy`` headers. It will be used to
244  compute the variable ``Python2_NumPy_INCLUDE_DIRS``.
245 
246 .. note::
247 
248  All paths must be absolute. Any artifact specified with a relative path
249  will be ignored.
250 
251 .. note::
252 
253  When an artifact is specified, all ``HINTS`` will be ignored and no search
254  will be performed for this artifact.
255 
256  If more than one artifact is specified, it is the user's responsability to
257  ensure the consistency of the various artifacts.
258 
259 By default, this module supports multiple calls in different directories of a
260 project with different version/component requirements while providing correct
261 and consistent results for each call. To support this behavior, ``CMake`` cache
262 is not used in the traditional way which can be problematic for interactive
263 specification. So, to enable also interactive specification, module behavior
264 can be controled with the following variable:
265 
266 ``Python2_ARTIFACTS_INTERACTIVE``
267  Selects the behavior of the module. This is a boolean variable:
268 
269  * If set to ``TRUE``: Create CMake cache entries for the above artifact
270  specification variables so that users can edit them interactively.
271  This disables support for multiple version/component requirements.
272  * If set to ``FALSE`` or undefined: Enable multiple version/component
273  requirements.
274 
275 Commands
276 ^^^^^^^^
277 
278 This module defines the command ``Python2_add_library`` (when
279 :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
280 :command:`add_library` and adds a dependency to target ``Python2::Python`` or,
281 when library type is ``MODULE``, to target ``Python2::Module`` and takes care
282 of Python module naming rules::
283 
284  Python2_add_library (<name> [STATIC | SHARED | MODULE]
285  <source1> [<source2> ...])
286 
287 If library type is not specified, ``MODULE`` is assumed.
288 #]=======================================================================]
289 
290 
291 set (_PYTHON_PREFIX Python2)
292 
293 set (_Python2_REQUIRED_VERSION_MAJOR 2)
294 
295 include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
296 
297 if (COMMAND __Python2_add_library)
298  macro (Python2_add_library)
299  __Python2_add_library (Python2 ${ARGV})
300  endmacro()
301 endif()
302 
303 unset (_PYTHON_PREFIX)
component
style
order
double get(vtkDataArray *const &arr, vtkIdType key)
version
string
#define VERSION
Definition: jconfigint.h:17
value