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 Three 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
17 * ``NumPy``: search for NumPy include directories.
19 If no ``COMPONENTS`` is specified, ``Interpreter`` is assumed.
21 To ensure consistent versions between components ``Interpreter``, ``Compiler``,
22 ``Development`` and ``NumPy``, specify all components at the same time::
24 find_package (Python3 COMPONENTS Interpreter Development)
26 This module looks only for version 3 of Python. This module can be used
27 concurrently with :module:`FindPython2` module to use both Python versions.
29 The :module:`FindPython` module can be used if Python version does not matter
34 If components ``Interpreter`` and ``Development`` are both specified, this
35 module search only for interpreter with same platform architecture as the one
36 defined by ``CMake`` configuration. This contraint does not apply if only
37 ``Interpreter`` component is specified.
42 This module defines the following :ref:`Imported Targets <Imported Targets>`
43 (when :prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
45 ``Python3::Interpreter``
46 Python 3 interpreter. Target defined if component ``Interpreter`` is found.
48 Python 3 compiler. Target defined if component ``Compiler`` is found.
50 Python 3 library. Target defined if component ``Development`` is found.
52 NumPy library for Python 3. Target defined if component ``NumPy`` is found.
57 This module will set the following variables in your project
58 (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
61 System has the Python 3 requested components.
62 ``Python3_Interpreter_FOUND``
63 System has the Python 3 interpreter.
64 ``Python3_EXECUTABLE``
65 Path to the Python 3 interpreter.
66 ``Python3_INTERPRETER_ID``
67 A short string unique to the interpreter. Possible values include:
74 Standard platform independent installation directory.
76 Information returned by
77 ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=True)``.
79 Standard platform dependent installation directory.
81 Information returned by
82 ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=True)``.
84 Third-party platform independent installation directory.
86 Information returned by
87 ``distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False)``.
89 Third-party platform dependent installation directory.
91 Information returned by
92 ``distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False)``.
93 ``Python3_Compiler_FOUND``
94 System has the Python 3 compiler.
96 Path to the Python 3 compiler. Only offered by IronPython.
97 ``Python3_COMPILER_ID``
98 A short string unique to the compiler. Possible values include:
100 ``Python3_Development_FOUND``
101 System has the Python 3 development artifacts.
102 ``Python3_INCLUDE_DIRS``
103 The Python 3 include directories.
104 ``Python3_LIBRARIES``
105 The Python 3 libraries.
106 ``Python3_LIBRARY_DIRS``
107 The Python 3 library directories.
108 ``Python3_RUNTIME_LIBRARY_DIRS``
109 The Python 3 runtime library directories.
112 ``Python3_VERSION_MAJOR``
113 Python 3 major version.
114 ``Python3_VERSION_MINOR``
115 Python 3 minor version.
116 ``Python3_VERSION_PATCH``
117 Python 3 patch version.
118 ``Python3_NumPy_FOUND``
119 System has the NumPy.
120 ``Python3_NumPy_INCLUDE_DIRS``
121 The NumPy include directries.
122 ``Python3_NumPy_VERSION``
129 Define the root directory of a Python 3 installation.
131 ``Python3_USE_STATIC_LIBS``
132 * If not defined, search for shared libraries and static libraries in that
134 * If set to TRUE, search **only** for static libraries.
135 * If set to FALSE, search **only** for shared libraries.
137 ``Python3_FIND_REGISTRY``
138 On Windows the ``Python3_FIND_REGISTRY`` variable determine the order
139 of preference between registry and environment variables.
140 the ``Python3_FIND_REGISTRY`` variable can be set to empty or one of the
143 * ``FIRST``: Try to use registry before environment variables.
145 * ``LAST``: Try to use registry after environment variables.
146 * ``NEVER``: Never try to use registry.
148 ``CMAKE_FIND_FRAMEWORK``
149 On OS X the :variable:`CMAKE_FIND_FRAMEWORK` variable determine the order of
150 preference between Apple-style and unix-style package components.
154 Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
158 If a Python virtual environment is configured, set variable
159 ``Python_FIND_REGISTRY`` (Windows) or ``CMAKE_FIND_FRAMEWORK`` (macOS) with
160 value ``LAST`` or ``NEVER`` to select it preferably.
165 This module defines the command ``Python3_add_library`` (when
166 :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
167 :command:`add_library`, but takes care of Python module naming rules
168 (only applied if library is of type ``MODULE``), and adds a dependency to target
169 ``Python3::Python``::
171 Python3_add_library (my_module MODULE src1.cpp)
173 If library type is not specified, ``MODULE`` is assumed.
174 #]=======================================================================]
177 set (_PYTHON_PREFIX Python3)
179 set (_Python3_REQUIRED_VERSION_MAJOR 3)
181 include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
183 if (COMMAND __Python3_add_library)
184 macro (Python3_add_library)
185 __Python3_add_library (Python3 ${ARGV})
189 unset (_PYTHON_PREFIX)