Salome HOME
Added a function to save all fields in signe phase flows
[tools/solverlab.git] / cmake_files / FindPYTHON.cmake
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 FindPython
6 ----------
7
8 Find Python interpreter, compiler and development environment (include
9 directories and libraries).
10
11 Three components are supported:
12
13 * ``Interpreter``: search for Python interpreter.
14 * ``Compiler``: search for Python compiler. Only offered by IronPython.
15 * ``Development``: search for development artifacts (include directories and
16   libraries).
17
18 If no ``COMPONENTS`` is specified, ``Interpreter`` is assumed.
19
20 To ensure consistent versions between components ``Interpreter``, ``Compiler``
21 and ``Development``, specify all components at the same time::
22
23   find_package (Python COMPONENTS Interpreter Development)
24
25 This module looks preferably for version 3 of Python. If not found, version 2
26 is searched.
27 To manage concurrent versions 3 and 2 of Python, use :module:`FindPython3` and
28 :module:`FindPython2` modules rather than this one.
29
30 Imported Targets
31 ^^^^^^^^^^^^^^^^
32
33 This module defines the following :ref:`Imported Targets <Imported Targets>`:
34
35 ``Python::Interpreter``
36   Python interpreter. Target defined if component ``Interpreter`` is found.
37 ``Python::Compiler``
38   Python compiler. Target defined if component ``Compiler`` is found.
39 ``Python::Python``
40   Python library. Target defined if component ``Development`` is found.
41
42 Result Variables
43 ^^^^^^^^^^^^^^^^
44
45 This module will set the following variables in your project
46 (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
47
48 ``Python_FOUND``
49   System has the Python requested components.
50 ``Python_Interpreter_FOUND``
51   System has the Python interpreter.
52 ``Python_EXECUTABLE``
53   Path to the Python interpreter.
54 ``Python_INTERPRETER_ID``
55   A short string unique to the interpreter. Possible values include:
56     * Python
57     * ActivePython
58     * Anaconda
59     * Canopy
60     * IronPython
61 ``Python_STDLIB``
62   Standard platform independent installation directory.
63
64   Information returned by
65   ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``.
66 ``Python_STDARCH``
67   Standard platform dependent installation directory.
68
69   Information returned by
70   ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``.
71 ``Python_SITELIB``
72   Third-party platform independent installation directory.
73
74   Information returned by
75   ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``.
76 ``Python_SITEARCH``
77   Third-party platform dependent installation directory.
78
79   Information returned by
80   ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``.
81 ``Python_Compiler_FOUND``
82   System has the Python compiler.
83 ``Python_COMPILER``
84   Path to the Python compiler. Only offered by IronPython.
85 ``Python_COMPILER_ID``
86   A short string unique to the compiler. Possible values include:
87     * IronPython
88 ``Python_Development_FOUND``
89   System has the Python development artifacts.
90 ``Python_INCLUDE_DIRS``
91   The Python include directories.
92 ``Python_LIBRARIES``
93   The Python libraries.
94 ``Python_LIBRARY_DIRS``
95   The Python library directories.
96 ``Python_RUNTIME_LIBRARY_DIRS``
97   The Python runtime library directories.
98 ``Python_VERSION``
99   Python version.
100 ``Python_VERSION_MAJOR``
101   Python major version.
102 ``Python_VERSION_MINOR``
103   Python minor version.
104 ``Python_VERSION_PATCH``
105   Python patch version.
106
107 Hints
108 ^^^^^
109
110 ``Python_ROOT_DIR``
111   Define the root directory of a Python installation.
112
113 ``Python_USE_STATIC_LIBS``
114   * If not defined, search for shared libraries and static libraries in that
115     order.
116   * If set to TRUE, search **only** for static libraries.
117   * If set to FALSE, search **only** for shared libraries.
118
119 Commands
120 ^^^^^^^^
121
122 This module defines the command ``Python_add_library`` which have the same
123 semantic as :command:`add_library` but take care of Python module naming rules
124 (only applied if library is of type ``MODULE``) and add dependency to target
125 ``Python::Python``::
126
127   Python_add_library (my_module MODULE src1.cpp)
128
129 If library type is not specified, ``MODULE`` is assumed.
130 #]=======================================================================]
131
132
133 set (_PYTHON_PREFIX Python)
134
135 if (DEFINED Python_FIND_VERSION)
136   set (_Python_REQUIRED_VERSION_MAJOR ${Python_FIND_VERSION_MAJOR})
137
138   include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
139 else()
140   # iterate over versions in quiet and NOT required modes to avoid multiple
141   # "Found" messages and prematurally failure.
142   set (_Python_QUIETLY ${Python_FIND_QUIETLY})
143   set (_Python_REQUIRED ${Python_FIND_REQUIRED})
144   set (Python_FIND_QUIETLY TRUE)
145   set (Python_FIND_REQUIRED FALSE)
146
147   set (_Python_REQUIRED_VERSIONS 3 2)
148   set (_Python_REQUIRED_VERSION_LAST 2)
149
150   foreach (_Python_REQUIRED_VERSION_MAJOR IN LISTS _Python_REQUIRED_VERSIONS)
151     set (Python_FIND_VERSION ${_Python_REQUIRED_VERSION_MAJOR})
152     include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
153     if (Python_FOUND OR
154         _Python_REQUIRED_VERSION_MAJOR EQUAL _Python_REQUIRED_VERSION_LAST)
155       break()
156     endif()
157     # clean-up some CACHE variables to ensure look-up restart from scratch
158     foreach (_Python_ITEM IN LISTS _Python_CACHED_VARS)
159       unset (${_Python_ITEM} CACHE)
160     endforeach()
161   endforeach()
162
163   unset (Python_FIND_VERSION)
164
165   set (Python_FIND_QUIETLY ${_Python_QUIETLY})
166   set (Python_FIND_REQUIRED ${_Python_REQUIRED})
167   if (Python_FIND_REQUIRED OR NOT Python_FIND_QUIETLY)
168     # call again validation command to get "Found" or error message
169     find_package_handle_standard_args (Python HANDLE_COMPONENTS
170                                               REQUIRED_VARS ${_Python_REQUIRED_VARS}
171                                               VERSION_VAR Python_VERSION)
172   endif()
173 endif()
174
175 if (COMMAND __Python_add_library)
176   macro (Python_add_library)
177     __Python_add_library (Python ${ARGV})
178   endmacro()
179 endif()
180
181 unset (_PYTHON_PREFIX)