FindPython3.cmake 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindPython3
  5. -----------
  6. .. versionadded:: 3.12
  7. Finds Python 3 interpreter, compiler and development environment (include
  8. directories and libraries):
  9. .. code-block:: cmake
  10. find_package(Python3 [<version>] [COMPONENTS <components>...] [...])
  11. .. versionadded:: 3.19
  12. When a version is requested, it can be specified as a simple value or as a
  13. range. For a detailed description of version range usage and capabilities,
  14. refer to the :command:`find_package` command.
  15. The following components are supported:
  16. * ``Interpreter``: search for Python 3 interpreter
  17. * ``Compiler``: search for Python 3 compiler. Only offered by IronPython.
  18. * ``Development``: search for development artifacts (include directories and
  19. libraries).
  20. .. versionadded:: 3.18
  21. This component includes two sub-components which can be specified
  22. independently:
  23. * ``Development.Module``: search for artifacts for Python 3 module
  24. developments.
  25. * ``Development.Embed``: search for artifacts for Python 3 embedding
  26. developments.
  27. .. versionadded:: 3.26
  28. * ``Development.SABIModule``: search for artifacts for Python 3 module
  29. developments using the
  30. `Stable Application Binary Interface <https://docs.python.org/3/c-api/stable.html>`_.
  31. This component is available only for version ``3.2`` and upper.
  32. .. versionadded:: 3.14
  33. * ``NumPy``: search for NumPy include directories. Specifying this component
  34. imply also the components ``Interpreter`` and ``Development.Module``.
  35. .. versionchanged:: 4.2
  36. The component ``Development.Module`` is no longer implied when the policy
  37. :policy:`CMP0201` is set to ``NEW``.
  38. If no ``COMPONENTS`` are specified, ``Interpreter`` is assumed.
  39. If component ``Development`` is specified, it implies sub-components
  40. ``Development.Module`` and ``Development.Embed``.
  41. .. versionchanged:: 4.1
  42. In a cross-compiling mode (i.e. the :variable:`CMAKE_CROSSCOMPILING` variable
  43. is defined to true), the following constraints, when the policy
  44. :policy:`CMP0190` is set to ``NEW``, now apply to the requested components:
  45. * ``Interpreter`` or ``Compiler`` alone: the host artifacts will be searched.
  46. * ``Interpreter`` or ``Compiler`` with ``Development`` or any sub-component:
  47. The target artifacts will be searched. In this case, the
  48. :variable:`CMAKE_CROSSCOMPILING_EMULATOR` variable must be defined and will
  49. be used to execute the interpreter or the compiler.
  50. When both host and target artifacts are needed, two different calls to the
  51. :command:`find_package` command should be done. The
  52. ``Python_ARTIFACTS_PREFIX`` variable can be helpful in this situation.
  53. To ensure consistent versions between components ``Interpreter``, ``Compiler``,
  54. ``Development`` (or one of its sub-components) and ``NumPy``, specify all
  55. components at the same time:
  56. .. code-block:: cmake
  57. find_package (Python3 COMPONENTS Interpreter Development)
  58. This module looks only for version 3 of Python. This module can be used
  59. concurrently with :module:`FindPython2` module to use both Python versions.
  60. The :module:`FindPython` module can be used if Python version does not matter
  61. for you.
  62. .. note::
  63. If components ``Interpreter`` and ``Development`` (or one of its
  64. sub-components) are both specified, this module search only for interpreter
  65. with same platform architecture as the one defined by CMake
  66. configuration. This constraint does not apply if only ``Interpreter``
  67. component is specified.
  68. Imported Targets
  69. ^^^^^^^^^^^^^^^^
  70. This module provides the following :ref:`Imported Targets`:
  71. .. versionchanged:: 3.14
  72. :ref:`Imported Targets <Imported Targets>` are only created when
  73. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``.
  74. ``Python3::Interpreter``
  75. Python 3 interpreter. This target is defined only if the ``Interpreter``
  76. component is found.
  77. ``Python3::InterpreterDebug``
  78. .. versionadded:: 3.30
  79. Python 3 debug interpreter. This target is defined only if the
  80. ``Interpreter`` component is found and the ``Python3_EXECUTABLE_DEBUG``
  81. variable is defined. The target is only defined on the ``Windows`` platform.
  82. ``Python3::InterpreterMultiConfig``
  83. .. versionadded:: 3.30
  84. Python 3 interpreter. The release or debug version of the interpreter will be
  85. used, based on the context (platform, configuration).
  86. This target is defined only if the ``Interpreter`` component is found
  87. ``Python3::Compiler``
  88. Python 3 compiler. This target is defined only if the ``Compiler`` component
  89. is found.
  90. ``Python3::Module``
  91. .. versionadded:: 3.15
  92. Python 3 library for Python module. Target defined if component
  93. ``Development.Module`` is found.
  94. ``Python3::SABIModule``
  95. .. versionadded:: 3.26
  96. Python 3 library for Python module using the Stable Application Binary
  97. Interface. Target defined if component ``Development.SABIModule`` is found.
  98. ``Python3::Python``
  99. Python 3 library for Python embedding. Target defined if component
  100. ``Development.Embed`` is found.
  101. ``Python3::NumPy``
  102. .. versionadded:: 3.14
  103. NumPy library for Python 3. Target defined if component ``NumPy`` is found.
  104. Moreover, this target has the ``Python3::Module`` target as dependency.
  105. .. versionchanged:: 4.2
  106. This target does not have anymore the ``Python3::Module`` target as
  107. dependency when the policy :policy:`CMP0201` is set to ``NEW``.
  108. Result Variables
  109. ^^^^^^^^^^^^^^^^
  110. This module defines the following variables
  111. (see :ref:`Standard Variable Names <CMake Developer Standard Variable Names>`):
  112. ``Python3_FOUND``
  113. System has the Python 3 requested components.
  114. ``Python3_Interpreter_FOUND``
  115. System has the Python 3 interpreter.
  116. ``Python3_EXECUTABLE``
  117. Path to the Python 3 interpreter.
  118. ``Python3_EXECUTABLE_DEBUG``
  119. .. versionadded:: 3.30
  120. Path to the debug Python 3 interpreter. It is only defined on ``Windows``
  121. platform.
  122. ``Python3_INTERPRETER``
  123. .. versionadded:: 3.30
  124. Path to the Python 3 interpreter, defined as a
  125. :manual:`generator expression <cmake-generator-expressions(7)>` selecting
  126. the ``Python3_EXECUTABLE`` or ``Python3_EXECUTABLE_DEBUG`` variable based on
  127. the context (platform, configuration).
  128. ``Python3_INTERPRETER_ID``
  129. A short string unique to the interpreter. Possible values include:
  130. * Python
  131. * ActivePython
  132. * Anaconda
  133. * Canopy
  134. * IronPython
  135. * PyPy
  136. ``Python3_STDLIB``
  137. Standard platform independent installation directory.
  138. Information returned by ``sysconfig.get_path('stdlib')``.
  139. ``Python3_STDARCH``
  140. Standard platform dependent installation directory.
  141. Information returned by ``sysconfig.get_path('platstdlib')``.
  142. ``Python3_SITELIB``
  143. Third-party platform independent installation directory.
  144. Information returned by ``sysconfig.get_path('purelib')``.
  145. ``Python3_SITEARCH``
  146. Third-party platform dependent installation directory.
  147. Information returned by ``sysconfig.get_path('platlib')``.
  148. ``Python3_SOABI``
  149. .. versionadded:: 3.17
  150. Extension suffix for modules.
  151. Information computed from ``sysconfig.get_config_var('EXT_SUFFIX')`` or
  152. ``sysconfig.get_config_var('SOABI')`` or
  153. ``python3-config --extension-suffix``.
  154. ``Python3_SOSABI``
  155. .. versionadded:: 3.26
  156. Extension suffix for modules using the Stable Application Binary Interface.
  157. Information computed from ``importlib.machinery.EXTENSION_SUFFIXES`` if the
  158. COMPONENT ``Interpreter`` was specified. Otherwise, the extension is ``abi3``
  159. except for ``Windows``, ``MSYS`` and ``CYGWIN`` for which this is an empty
  160. string.
  161. ``Python3_Compiler_FOUND``
  162. System has the Python 3 compiler.
  163. ``Python3_COMPILER``
  164. Path to the Python 3 compiler. Only offered by IronPython.
  165. ``Python3_COMPILER_ID``
  166. A short string unique to the compiler. Possible values include:
  167. * IronPython
  168. ``Python3_DOTNET_LAUNCHER``
  169. .. versionadded:: 3.18
  170. The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
  171. ``Python3_Development_FOUND``
  172. System has the Python 3 development artifacts.
  173. ``Python3_Development.Module_FOUND``
  174. .. versionadded:: 3.18
  175. System has the Python 3 development artifacts for Python module.
  176. ``Python3_Development.SABIModule_FOUND``
  177. .. versionadded:: 3.26
  178. System has the Python 3 development artifacts for Python module using the
  179. Stable Application Binary Interface.
  180. ``Python3_Development.Embed_FOUND``
  181. .. versionadded:: 3.18
  182. System has the Python 3 development artifacts for Python embedding.
  183. ``Python3_INCLUDE_DIRS``
  184. The Python 3 include directories.
  185. ``Python3_DEFINITIONS``
  186. .. versionadded:: 3.30.3
  187. The Python 3 preprocessor definitions.
  188. ``Python3_DEBUG_POSTFIX``
  189. .. versionadded:: 3.30
  190. Postfix of debug python module. This variable can be used to define the
  191. :prop_tgt:`DEBUG_POSTFIX` target property.
  192. ``Python3_LINK_OPTIONS``
  193. .. versionadded:: 3.19
  194. The Python 3 link options. Some configurations require specific link options
  195. for a correct build and execution.
  196. ``Python3_LIBRARIES``
  197. The Python 3 libraries.
  198. ``Python3_LIBRARY_DIRS``
  199. The Python 3 library directories.
  200. ``Python3_RUNTIME_LIBRARY_DIRS``
  201. The Python 3 runtime library directories.
  202. ``Python3_SABI_LIBRARIES``
  203. .. versionadded:: 3.26
  204. The Python 3 libraries for the Stable Application Binary Interface.
  205. ``Python3_SABI_LIBRARY_DIRS``
  206. .. versionadded:: 3.26
  207. The Python 3 ``SABI`` library directories.
  208. ``Python3_RUNTIME_SABI_LIBRARY_DIRS``
  209. .. versionadded:: 3.26
  210. The Python 3 runtime ``SABI`` library directories.
  211. ``Python3_VERSION``
  212. Python 3 version.
  213. ``Python3_VERSION_MAJOR``
  214. Python 3 major version.
  215. ``Python3_VERSION_MINOR``
  216. Python 3 minor version.
  217. ``Python3_VERSION_PATCH``
  218. Python 3 patch version.
  219. ``Python3_PyPy_VERSION``
  220. .. versionadded:: 3.18
  221. Python 3 PyPy version.
  222. ``Python3_NumPy_FOUND``
  223. .. versionadded:: 3.14
  224. System has the NumPy.
  225. ``Python3_NumPy_INCLUDE_DIRS``
  226. .. versionadded:: 3.14
  227. The NumPy include directories.
  228. ``Python3_NumPy_VERSION``
  229. .. versionadded:: 3.14
  230. The NumPy version.
  231. Hints
  232. ^^^^^
  233. ``Python3_ROOT_DIR``
  234. Define the root directory of a Python 3 installation.
  235. ``Python3_USE_STATIC_LIBS``
  236. * If not defined, search for shared libraries and static libraries in that
  237. order.
  238. * If set to TRUE, search **only** for static libraries.
  239. * If set to FALSE, search **only** for shared libraries.
  240. .. note::
  241. This hint will be ignored on ``Windows`` because static libraries are not
  242. available on this platform.
  243. ``Python3_FIND_ABI``
  244. .. versionadded:: 3.16
  245. This variable defines which ABIs, as defined in :pep:`3149`, should be
  246. searched.
  247. The ``Python3_FIND_ABI`` variable is a 4-tuple specifying, in that order,
  248. ``pydebug`` (``d``), ``pymalloc`` (``m``), ``unicode`` (``u``) and
  249. ``gil_disabled`` (``t``) flags.
  250. .. versionadded:: 3.30
  251. A fourth element, specifying the ``gil_disabled`` flag (i.e. free
  252. threaded python), is added and is optional. If not specified, the value is
  253. ``OFF``.
  254. Each element can be set to one of the following:
  255. * ``ON``: Corresponding flag is selected.
  256. * ``OFF``: Corresponding flag is not selected.
  257. * ``ANY``: The two possibilities (``ON`` and ``OFF``) will be searched.
  258. .. note::
  259. If ``Python3_FIND_ABI`` is not defined, any ABI, excluding the
  260. ``gil_disabled`` flag, will be searched.
  261. From this 4-tuple, various ABIs will be searched starting from the most
  262. specialized to the most general. Moreover, when ``ANY`` is specified for
  263. ``pydebug`` and ``gil_disabled``, ``debug`` and ``free threaded`` versions
  264. will be searched **after** ``non-debug`` and ``non-gil-disabled`` ones.
  265. For example, if we have:
  266. .. code-block:: cmake
  267. set (Python3_FIND_ABI "ON" "ANY" "ANY" "ON")
  268. The following flags combinations will be appended, in that order, to the
  269. artifact names: ``tdmu``, ``tdm``, ``tdu``, and ``td``.
  270. And to search any possible ABIs:
  271. .. code-block:: cmake
  272. set (Python3_FIND_ABI "ANY" "ANY" "ANY" "ANY")
  273. The following combinations, in that order, will be used: ``mu``, ``m``,
  274. ``u``, ``<empty>``, ``dmu``, ``dm``, ``du``, ``d``, ``tmu``, ``tm``, ``tu``,
  275. ``t``, ``tdmu``, ``tdm``, ``tdu``, and ``td``.
  276. .. note::
  277. This hint is useful only on ``POSIX`` systems except for the
  278. ``gil_disabled`` flag. So, on ``Windows`` systems,
  279. when ``Python_FIND_ABI`` is defined, ``Python`` distributions from
  280. `python.org <https://www.python.org/>`_ will be found only if the value for
  281. each flag is ``OFF`` or ``ANY`` except for the fourth one
  282. (``gil_disabled``).
  283. ``Python3_FIND_STRATEGY``
  284. .. versionadded:: 3.15
  285. This variable defines how lookup will be done.
  286. The ``Python3_FIND_STRATEGY`` variable can be set to one of the following:
  287. * ``VERSION``: Try to find the most recent version in all specified
  288. locations.
  289. This is the default if policy :policy:`CMP0094` is undefined or set to
  290. ``OLD``.
  291. * ``LOCATION``: Stops lookup as soon as a version satisfying version
  292. constraints is founded.
  293. This is the default if policy :policy:`CMP0094` is set to ``NEW``.
  294. See also ``Python3_FIND_UNVERSIONED_NAMES``.
  295. ``Python3_FIND_REGISTRY``
  296. .. versionadded:: 3.13
  297. On Windows the ``Python3_FIND_REGISTRY`` variable determine the order
  298. of preference between registry and environment variables.
  299. The ``Python3_FIND_REGISTRY`` variable can be set to one of the following:
  300. * ``FIRST``: Try to use registry before environment variables.
  301. This is the default.
  302. * ``LAST``: Try to use registry after environment variables.
  303. * ``NEVER``: Never try to use registry.
  304. ``Python3_FIND_FRAMEWORK``
  305. .. versionadded:: 3.15
  306. On macOS the ``Python3_FIND_FRAMEWORK`` variable determine the order of
  307. preference between Apple-style and unix-style package components.
  308. This variable can take same values as :variable:`CMAKE_FIND_FRAMEWORK`
  309. variable.
  310. .. note::
  311. Value ``ONLY`` is not supported so ``FIRST`` will be used instead.
  312. If ``Python3_FIND_FRAMEWORK`` is not defined, :variable:`CMAKE_FIND_FRAMEWORK`
  313. variable will be used, if any.
  314. ``Python3_FIND_VIRTUALENV``
  315. .. versionadded:: 3.15
  316. This variable defines the handling of virtual environments managed by
  317. ``virtualenv`` or ``conda``. It is meaningful only when a virtual environment
  318. is active (i.e. the ``activate`` script has been evaluated). In this case, it
  319. takes precedence over ``Python3_FIND_REGISTRY`` and ``CMAKE_FIND_FRAMEWORK``
  320. variables. The ``Python3_FIND_VIRTUALENV`` variable can be set to one of the
  321. following:
  322. * ``FIRST``: The virtual environment is used before any other standard
  323. paths to look-up for the interpreter. This is the default.
  324. * ``ONLY``: Only the virtual environment is used to look-up for the
  325. interpreter.
  326. * ``STANDARD``: The virtual environment is not used to look-up for the
  327. interpreter but environment variable ``PATH`` is always considered.
  328. In this case, variable ``Python3_FIND_REGISTRY`` (Windows) or
  329. ``CMAKE_FIND_FRAMEWORK`` (macOS) can be set with value ``LAST`` or
  330. ``NEVER`` to select preferably the interpreter from the virtual
  331. environment.
  332. .. versionadded:: 3.17
  333. Added support for ``conda`` environments.
  334. .. note::
  335. If the component ``Development`` is requested (or one of its
  336. sub-components) and is not found or the wrong artifacts are returned,
  337. including also the component ``Interpreter`` may be helpful.
  338. ``Python3_FIND_IMPLEMENTATIONS``
  339. .. versionadded:: 3.18
  340. This variable defines, in an ordered list, the different implementations
  341. which will be searched. The ``Python3_FIND_IMPLEMENTATIONS`` variable can
  342. hold the following values:
  343. * ``CPython``: this is the standard implementation. Various products, like
  344. ``Anaconda`` or ``ActivePython``, rely on this implementation.
  345. * ``IronPython``: This implementation use the ``CSharp`` language for
  346. ``.NET Framework`` on top of the `Dynamic Language Runtime` (``DLR``).
  347. See `IronPython <https://ironpython.net>`_.
  348. * ``PyPy``: This implementation use ``RPython`` language and
  349. ``RPython translation toolchain`` to produce the python interpreter.
  350. See `PyPy <https://pypy.org>`_.
  351. The default value is:
  352. * Windows platform: ``CPython``, ``IronPython``
  353. * Other platforms: ``CPython``
  354. .. note::
  355. This hint has the lowest priority of all hints, so even if, for example,
  356. you specify ``IronPython`` first and ``CPython`` in second, a python
  357. product based on ``CPython`` can be selected because, for example with
  358. ``Python3_FIND_STRATEGY=LOCATION``, each location will be search first for
  359. ``IronPython`` and second for ``CPython``.
  360. .. note::
  361. When ``IronPython`` is specified, on platforms other than ``Windows``, the
  362. ``.Net`` interpreter (i.e. ``mono`` command) is expected to be available
  363. through the ``PATH`` variable.
  364. ``Python3_FIND_UNVERSIONED_NAMES``
  365. .. versionadded:: 3.20
  366. This variable defines how the generic names will be searched. Currently, it
  367. only applies to the generic names of the interpreter, namely, ``python3`` and
  368. ``python``.
  369. The ``Python3_FIND_UNVERSIONED_NAMES`` variable can be set to one of the
  370. following values:
  371. * ``FIRST``: The generic names are searched before the more specialized ones
  372. (such as ``python3.5`` for example).
  373. * ``LAST``: The generic names are searched after the more specialized ones.
  374. This is the default.
  375. * ``NEVER``: The generic name are not searched at all.
  376. See also ``Python3_FIND_STRATEGY``.
  377. Artifacts Specification
  378. ^^^^^^^^^^^^^^^^^^^^^^^
  379. .. versionadded:: 3.16
  380. To solve special cases, it is possible to specify directly the artifacts by
  381. setting the following variables:
  382. ``Python3_EXECUTABLE``
  383. The path to the interpreter.
  384. ``Python3_COMPILER``
  385. The path to the compiler.
  386. ``Python3_DOTNET_LAUNCHER``
  387. .. versionadded:: 3.18
  388. The ``.Net`` interpreter. Only used by ``IronPython`` implementation.
  389. ``Python3_LIBRARY``
  390. The path to the library. It will be used to compute the
  391. variables ``Python3_LIBRARIES``, ``Python3_LIBRARY_DIRS`` and
  392. ``Python3_RUNTIME_LIBRARY_DIRS``.
  393. ``Python3_SABI_LIBRARY``
  394. .. versionadded:: 3.26
  395. The path to the library for Stable Application Binary Interface. It will be
  396. used to compute the variables ``Python3_SABI_LIBRARIES``,
  397. ``Python3_SABI_LIBRARY_DIRS`` and ``Python3_RUNTIME_SABI_LIBRARY_DIRS``.
  398. ``Python3_INCLUDE_DIR``
  399. The path to the directory of the ``Python`` headers. It will be used to
  400. compute the variable ``Python3_INCLUDE_DIRS``.
  401. ``Python3_NumPy_INCLUDE_DIR``
  402. The path to the directory of the ``NumPy`` headers. It will be used to
  403. compute the variable ``Python3_NumPy_INCLUDE_DIRS``.
  404. .. note::
  405. All paths must be absolute. Any artifact specified with a relative path
  406. will be ignored.
  407. .. note::
  408. When an artifact is specified, all ``HINTS`` will be ignored and no search
  409. will be performed for this artifact.
  410. If more than one artifact is specified, it is the user's responsibility to
  411. ensure the consistency of the various artifacts.
  412. By default, this module supports multiple calls in different directories of a
  413. project with different version/component requirements while providing correct
  414. and consistent results for each call. To support this behavior, CMake cache
  415. is not used in the traditional way which can be problematic for interactive
  416. specification. So, to enable also interactive specification, module behavior
  417. can be controlled with the following variable:
  418. ``Python3_ARTIFACTS_INTERACTIVE``
  419. .. versionadded:: 3.18
  420. Selects the behavior of the module. This is a boolean variable:
  421. * If set to ``TRUE``: Create CMake cache entries for the above artifact
  422. specification variables so that users can edit them interactively.
  423. This disables support for multiple version/component requirements.
  424. * If set to ``FALSE`` or undefined: Enable multiple version/component
  425. requirements.
  426. ``Python3_ARTIFACTS_PREFIX``
  427. .. versionadded:: 4.0
  428. Define a custom prefix which will be used for the definition of all the
  429. result variables, targets, and commands. By using this variable, this module
  430. supports multiple calls in the same directory with different
  431. version/component requirements.
  432. For example, in case of cross-compilation, development components are needed
  433. but the native python interpreter can also be required:
  434. .. code-block:: cmake
  435. find_package(Python3 COMPONENTS Development)
  436. set(Python3_ARTIFACTS_PREFIX "_HOST")
  437. find_package(Python3 COMPONENTS Interpreter)
  438. # Here Python3_HOST_EXECUTABLE and Python3_HOST::Interpreter artifacts are defined
  439. .. note::
  440. For consistency with standard behavior of modules, the various standard
  441. ``_FOUND`` variables (i.e. without the custom prefix) are also defined by
  442. each call to the :command:`find_package` command.
  443. Commands
  444. ^^^^^^^^
  445. This module defines the command ``Python3_add_library`` (when
  446. :prop_gbl:`CMAKE_ROLE` is ``PROJECT``), which has the same semantics as
  447. :command:`add_library` and adds a dependency to target ``Python3::Python`` or,
  448. when library type is ``MODULE``, to target ``Python3::Module`` or
  449. ``Python3::SABIModule`` (when ``USE_SABI`` option is specified) and takes care
  450. of Python module naming rules:
  451. .. code-block:: cmake
  452. Python3_add_library (<name> [STATIC | SHARED | MODULE [USE_SABI <version>] [WITH_SOABI]]
  453. <source1> [<source2> ...])
  454. If the library type is not specified, ``MODULE`` is assumed.
  455. .. versionadded:: 3.17
  456. For ``MODULE`` library type, if option ``WITH_SOABI`` is specified, the
  457. module suffix will include the ``Python3_SOABI`` value, if any.
  458. .. versionadded:: 3.26
  459. For ``MODULE`` type, if the option ``USE_SABI`` is specified, the
  460. preprocessor definition ``Py_LIMITED_API`` will be specified, as ``PRIVATE``,
  461. for the target ``<name>`` with the value computed from ``<version>`` argument.
  462. The expected format for ``<version>`` is ``major[.minor]``, where each
  463. component is a numeric value. If ``minor`` component is specified, the
  464. version should be, at least, ``3.2`` which is the version where the
  465. `Stable Application Binary Interface <https://docs.python.org/3/c-api/stable.html>`_
  466. was introduced. Specifying only major version ``3`` is equivalent to ``3.2``.
  467. When option ``WITH_SOABI`` is also specified, the module suffix will include
  468. the ``Python3_SOSABI`` value, if any.
  469. .. versionadded:: 3.30
  470. For ``MODULE`` type, the :prop_tgt:`DEBUG_POSTFIX` target property is
  471. initialized with the value of ``Python3_DEBUG_POSTFIX`` variable if defined.
  472. #]=======================================================================]
  473. set (_PYTHON_BASE Python3)
  474. if(${_PYTHON_BASE}_ARTIFACTS_PREFIX)
  475. set(_PYTHON_PREFIX "${_PYTHON_BASE}${${_PYTHON_BASE}_ARTIFACTS_PREFIX}")
  476. else()
  477. set(_PYTHON_PREFIX "${_PYTHON_BASE}")
  478. endif()
  479. set (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR 3)
  480. include (${CMAKE_CURRENT_LIST_DIR}/FindPython/Support.cmake)
  481. if (COMMAND __${_PYTHON_PREFIX}_add_library AND NOT COMMAND ${_PYTHON_PREFIX}_add_library)
  482. cmake_language(EVAL CODE
  483. "macro (${_PYTHON_PREFIX}_add_library)
  484. __${_PYTHON_PREFIX}_add_library (${_PYTHON_PREFIX} \${ARGV})
  485. endmacro()")
  486. endif()
  487. unset (_PYTHON_BASE)
  488. unset (_PYTHON_PREFIX)