find_package.rst 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. find_package
  2. ------------
  3. .. |FIND_XXX| replace:: find_package
  4. .. |FIND_ARGS_XXX| replace:: <PackageName>
  5. .. |FIND_XXX_REGISTRY_VIEW_DEFAULT| replace:: ``TARGET``
  6. .. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
  7. :variable:`CMAKE_FIND_ROOT_PATH_MODE_PACKAGE`
  8. .. only:: html
  9. .. contents::
  10. .. note:: The :guide:`Using Dependencies Guide` provides a high-level
  11. introduction to this general topic. It provides a broader overview of
  12. where the ``find_package()`` command fits into the bigger picture,
  13. including its relationship to the :module:`FetchContent` module.
  14. The guide is recommended pre-reading before moving on to the details below.
  15. Find a package (usually provided by something external to the project),
  16. and load its package-specific details. Calls to this command can also
  17. be intercepted by :ref:`dependency providers <dependency_providers>`.
  18. Typical Usage
  19. ^^^^^^^^^^^^^
  20. Most calls to ``find_package()`` typically have the following form:
  21. .. code-block:: cmake
  22. find_package(<PackageName> [<version>] [REQUIRED] [COMPONENTS <components>...])
  23. The ``<PackageName>`` is the only mandatory argument. The ``<version>`` is
  24. often omitted, and ``REQUIRED`` should be given if the project cannot be
  25. configured successfully without the package. Some more complicated packages
  26. support components which can be selected with the ``COMPONENTS`` keyword, but
  27. most packages don't have that level of complexity.
  28. The above is a reduced form of the `basic signature`_. Where possible,
  29. projects should find packages using this form. This reduces complexity and
  30. maximizes the ways in which the package can be found or provided.
  31. Understanding the `basic signature`_ should be enough for general usage of
  32. ``find_package()``. Project maintainers who intend to provide a package
  33. configuration file should understand the bigger picture, as explained in
  34. :ref:`Full Signature` and all subsequent sections on this page.
  35. Search Modes
  36. ^^^^^^^^^^^^
  37. The command has a few modes by which it searches for packages:
  38. .. _`Module mode`:
  39. **Module mode**
  40. In this mode, CMake searches for a file called ``Find<PackageName>.cmake``,
  41. looking first in the locations listed in the :variable:`CMAKE_MODULE_PATH`,
  42. then among the :ref:`Find Modules` provided by the CMake installation.
  43. If the file is found, it is read and processed by CMake. It is responsible
  44. for finding the package, checking the version, and producing any needed
  45. messages. Some Find modules provide limited or no support for versioning;
  46. check the Find module's documentation.
  47. The ``Find<PackageName>.cmake`` file is not typically provided by the
  48. package itself. Rather, it is normally provided by something external to
  49. the package, such as the operating system, CMake itself, or even the project
  50. from which the ``find_package()`` command was called. Being externally
  51. provided, :ref:`Find Modules` tend to be heuristic in nature and are
  52. susceptible to becoming out-of-date. They typically search for certain
  53. libraries, files and other package artifacts.
  54. Module mode is only supported by the
  55. :ref:`basic command signature <Basic Signature>`.
  56. .. _`Config mode`:
  57. **Config mode**
  58. In this mode, CMake searches for a file called
  59. ``<lowercasePackageName>-config.cmake`` or ``<PackageName>Config.cmake``.
  60. It will also look for ``<lowercasePackageName>-config-version.cmake`` or
  61. ``<PackageName>ConfigVersion.cmake`` if version details were specified
  62. (see :ref:`version selection` for an explanation of how these separate
  63. version files are used).
  64. .. note::
  65. If the experimental ``CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES`` is enabled,
  66. files named ``<PackageName>.cps`` and ``<lowercasePackageName>.cps`` are
  67. also considered. These files provide package information according to the
  68. |CPS|_ (CPS), which is more portable than CMake script. Aside from any
  69. explicitly noted exceptions, any references to "config files", "config
  70. mode", "package configuration files", and so forth refer equally to both
  71. CPS and CMake-script files. This functionality is a work in progress, and
  72. some features may be missing.
  73. Search is implemented in a manner that will tend to prefer |CPS| files
  74. over CMake-script config files in most cases. Specifying ``CONFIGS``
  75. suppresses consideration of CPS files.
  76. In config mode, the command can be given a list of names to search for
  77. as package names. The locations where CMake searches for the config and
  78. version files is considerably more complicated than for Module mode
  79. (see :ref:`search procedure`).
  80. The config and version files are typically installed as part of the
  81. package, so they tend to be more reliable than Find modules. They usually
  82. contain direct knowledge of the package contents, so no searching or
  83. heuristics are needed within the config or version files themselves.
  84. Config mode is supported by both the :ref:`basic <Basic Signature>` and
  85. :ref:`full <Full Signature>` command signatures.
  86. **FetchContent redirection mode**
  87. .. versionadded:: 3.24
  88. A call to ``find_package()`` can be redirected internally to a package
  89. provided by the :module:`FetchContent` module. To the caller, the behavior
  90. will appear similar to Config mode, except that the search logic is
  91. by-passed and the component information is not used. See
  92. :command:`FetchContent_Declare` and :command:`FetchContent_MakeAvailable`
  93. for further details.
  94. When not redirected to a package provided by :module:`FetchContent`, the
  95. command arguments determine whether Module or Config mode is used. When the
  96. `basic signature`_ is used, the command searches in Module mode first.
  97. If the package is not found, the search falls back to Config mode.
  98. A user may set the :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` variable
  99. to true to reverse the priority and direct CMake to search using Config mode
  100. first before falling back to Module mode. The basic signature can also be
  101. forced to use only Module mode with a ``MODULE`` keyword. If the
  102. `full signature`_ is used, the command only searches in Config mode.
  103. .. _`basic signature`:
  104. Basic Signature
  105. ^^^^^^^^^^^^^^^
  106. .. code-block:: cmake
  107. find_package(<PackageName> [version] [EXACT] [QUIET] [MODULE]
  108. [REQUIRED|OPTIONAL] [[COMPONENTS] [components...]]
  109. [OPTIONAL_COMPONENTS components...]
  110. [REGISTRY_VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  111. [GLOBAL]
  112. [NO_POLICY_SCOPE]
  113. [BYPASS_PROVIDER]
  114. [UNWIND_INCLUDE])
  115. The basic signature is supported by both Module and Config modes.
  116. The ``MODULE`` keyword implies that only Module mode can be used to find
  117. the package, with no fallback to Config mode.
  118. Regardless of the mode used, a ``<PackageName>_FOUND`` variable will be
  119. set to indicate whether the package was found. When the package is found,
  120. package-specific information may be provided through other variables and
  121. :ref:`Imported Targets` documented by the package itself. The
  122. ``QUIET`` option disables informational messages, including those indicating
  123. that the package cannot be found if it is not ``REQUIRED``. The ``REQUIRED``
  124. option stops processing with an error message if the package cannot be found.
  125. A package-specific list of required components may be listed after the
  126. ``COMPONENTS`` keyword. If any of these components are not able to be
  127. satisfied, the package overall is considered to be not found. If the
  128. ``REQUIRED`` option is also present, this is treated as a fatal error,
  129. otherwise execution still continues. As a form of shorthand, if the
  130. ``REQUIRED`` option is present, the ``COMPONENTS`` keyword can be omitted
  131. and the required components can be listed directly after ``REQUIRED``.
  132. The :variable:`CMAKE_FIND_REQUIRED` variable can be enabled to make this call
  133. ``REQUIRED`` by default. This behavior can be overridden by providing the
  134. ``OPTIONAL`` keyword. As with the ``REQUIRED`` option, a list of components
  135. can be listed directly after ``OPTIONAL``, which is equivalent to listing
  136. them after the ``COMPONENTS`` keyword. When the ``OPTIONAL`` keyword is given,
  137. the warning output when a package is not found is suppressed.
  138. Additional optional components may be listed after ``OPTIONAL_COMPONENTS``.
  139. If these cannot be satisfied, the package overall can still be considered
  140. found, as long as all required components are satisfied.
  141. The set of available components and their meaning are defined by the
  142. target package:
  143. * For CMake-script package configuration files, it is formally up to the target
  144. package how to interpret the component information given to it, but it should
  145. follow the expectations stated above. For calls where no components are
  146. specified, there is no single expected behavior and target packages should
  147. clearly define what occurs in such cases. Common arrangements include
  148. assuming it should find all components, no components or some well-defined
  149. subset of the available components.
  150. * |CPS| packages consist of a root configuration file and zero or more
  151. appendices, each of which provide components and may have dependencies.
  152. CMake always attempts to load the root configuration file. Appendices are
  153. only loaded if their dependencies can be satisfied, and if they either
  154. provide requested components, or if no components were requested. If the
  155. dependencies of an appendix providing a required component cannot be
  156. satisfied, the package is considered not found. Otherwise, that appendix
  157. is ignored.
  158. .. versionadded:: 3.24
  159. The ``REGISTRY_VIEW`` keyword specifies which registry views should be
  160. queried. This keyword is only meaningful on ``Windows`` platforms and will
  161. be ignored on all others. Formally, it is up to the target package how to
  162. interpret the registry view information given to it.
  163. .. versionadded:: 3.24
  164. Specifying the ``GLOBAL`` keyword will promote all imported targets to
  165. a global scope in the importing project. Alternatively, this functionality
  166. can be enabled by setting the :variable:`CMAKE_FIND_PACKAGE_TARGETS_GLOBAL`
  167. variable.
  168. .. _FIND_PACKAGE_VERSION_FORMAT:
  169. The ``[version]`` argument requests a version with which the package found
  170. should be compatible. There are two possible forms in which it may be
  171. specified:
  172. * A single version with the format ``major[.minor[.patch[.tweak]]]``, where
  173. each component is a numeric value.
  174. * A version range with the format ``versionMin...[<]versionMax`` where
  175. ``versionMin`` and ``versionMax`` have the same format and constraints on
  176. components being integers as the single version. By default, both end points
  177. are included. By specifying ``<``, the upper end point will be excluded.
  178. Version ranges are only supported with CMake 3.19 or later.
  179. .. note::
  180. With the exception of CPS packages, version support is currently provided
  181. only on a package-by-package basis. When a version range is specified but
  182. the package is only designed to expect a single version, the package will
  183. ignore the upper end point of the range and only take the single version at
  184. the lower end of the range into account. Non-CPS packages that do support
  185. version ranges do so in a manner that is determined by the individual
  186. package. See the `Version Selection`_ section below for details and
  187. important caveats.
  188. The ``EXACT`` option requests that the version be matched exactly. This option
  189. is incompatible with the specification of a version range.
  190. If no ``[version]`` and/or component list is given to a recursive invocation
  191. inside a find-module, the corresponding arguments are forwarded
  192. automatically from the outer call (including the ``EXACT`` flag for
  193. ``[version]``).
  194. See the :command:`cmake_policy` command documentation for discussion
  195. of the ``NO_POLICY_SCOPE`` option.
  196. .. versionadded:: 3.24
  197. The ``BYPASS_PROVIDER`` keyword is only allowed when ``find_package()`` is
  198. being called by a :ref:`dependency provider <dependency_providers>`.
  199. It can be used by providers to call the built-in ``find_package()``
  200. implementation directly and prevent that call from being re-routed back to
  201. itself. Future versions of CMake may detect attempts to use this keyword
  202. from places other than a dependency provider and halt with a fatal error.
  203. .. versionadded:: 4.2
  204. The ``UNWIND_INCLUDE`` keyword is only allowed when ``find_package()`` is
  205. being called within a parent call to ``find_package()``. When a call to
  206. ``find_package(UNWIND_INCLUDE)`` fails to find the desired package, it begins
  207. an "unwind" state. In this state further calls to ``find_package()`` and
  208. :command:`include()` are forbidden, and all parent :command:`include()`
  209. commands will immediately invoke :command:`return()` when their scope is
  210. reached. This "unwinding" will continue until the parent ``find_package()``
  211. is returned to.
  212. ``UNWIND_INCLUDE`` is only intended to be used by calls to ``find_package()``
  213. generated by :command:`install(EXPORT_PACKAGE_DEPENDENCIES)`, but may be
  214. useful to those who wish to manually manage their dependencies in a similar
  215. manner.
  216. .. _`full signature`:
  217. Full Signature
  218. ^^^^^^^^^^^^^^
  219. .. code-block:: cmake
  220. find_package(<PackageName> [version] [EXACT] [QUIET]
  221. [REQUIRED|OPTIONAL] [[COMPONENTS] [components...]]
  222. [OPTIONAL_COMPONENTS components...]
  223. [CONFIG|NO_MODULE]
  224. [GLOBAL]
  225. [NO_POLICY_SCOPE]
  226. [BYPASS_PROVIDER]
  227. [NAMES name1 [name2 ...]]
  228. [CONFIGS config1 [config2 ...]]
  229. [HINTS path1 [path2 ...]]
  230. [PATHS path1 [path2 ...]]
  231. [REGISTRY_VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  232. [PATH_SUFFIXES suffix1 [suffix2 ...]]
  233. [NO_DEFAULT_PATH]
  234. [NO_PACKAGE_ROOT_PATH]
  235. [NO_CMAKE_PATH]
  236. [NO_CMAKE_ENVIRONMENT_PATH]
  237. [NO_SYSTEM_ENVIRONMENT_PATH]
  238. [NO_CMAKE_PACKAGE_REGISTRY]
  239. [NO_CMAKE_BUILDS_PATH] # Deprecated; does nothing.
  240. [NO_CMAKE_SYSTEM_PATH]
  241. [NO_CMAKE_INSTALL_PREFIX]
  242. [NO_CMAKE_SYSTEM_PACKAGE_REGISTRY]
  243. [CMAKE_FIND_ROOT_PATH_BOTH |
  244. ONLY_CMAKE_FIND_ROOT_PATH |
  245. NO_CMAKE_FIND_ROOT_PATH])
  246. The ``CONFIG`` option, the synonymous ``NO_MODULE`` option, or the use
  247. of options not specified in the `basic signature`_ all enforce pure Config
  248. mode. In pure Config mode, the command skips Module mode search and
  249. proceeds at once with Config mode search.
  250. Config mode search attempts to locate a configuration file provided by the
  251. package to be found. A cache entry called ``<PackageName>_DIR`` is created to
  252. hold the directory containing the file. By default, the command searches for
  253. a package with the name ``<PackageName>``. If the ``NAMES`` option is given,
  254. the names following it are used instead of ``<PackageName>``. The names are
  255. also considered when determining whether to redirect the call to a package
  256. provided by :module:`FetchContent`.
  257. The command searches for a file called ``<PackageName>Config.cmake`` or
  258. ``<lowercasePackageName>-config.cmake`` for each name specified.
  259. A replacement set of possible configuration file names may be given
  260. using the ``CONFIGS`` option. The :ref:`search procedure` is specified below.
  261. Once found, any :ref:`version constraint <version selection>` is checked,
  262. and if satisfied, the configuration file is read and processed by CMake.
  263. Since the file is provided by the package it already knows the
  264. location of package contents. The full path to the configuration file
  265. is stored in the CMake variable ``<PackageName>_CONFIG``.
  266. .. note::
  267. If the experimental ``CMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES`` is enabled,
  268. files named ``<PackageName>.cps`` and ``<lowercasePackageName>.cps`` are
  269. also considered, unless ``CONFIGS`` is given.
  270. All configuration files which have been considered by CMake while
  271. searching for the package with an appropriate version are stored in the
  272. ``<PackageName>_CONSIDERED_CONFIGS`` variable, and the associated versions
  273. in the ``<PackageName>_CONSIDERED_VERSIONS`` variable.
  274. If the package configuration file cannot be found, CMake will generate
  275. an error describing the problem unless the ``QUIET`` argument is
  276. specified. If ``REQUIRED`` is specified and the package is not found, a
  277. fatal error is generated and the configure step stops executing. If
  278. ``<PackageName>_DIR`` has been set to a directory not containing a
  279. configuration file, or if the requested version is not compatible
  280. with the package found in that directory (see :ref:`version selection`),
  281. CMake will ignore it and search from scratch.
  282. Package maintainers providing package configuration files are encouraged to
  283. name and install them such that the :ref:`search procedure` outlined below
  284. will find them without requiring use of additional options.
  285. .. _`search procedure`:
  286. Config Mode Search Procedure
  287. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  288. .. note::
  289. When Config mode is used, this search procedure is applied regardless of
  290. whether the :ref:`full <full signature>` or :ref:`basic <basic signature>`
  291. signature was given.
  292. .. versionadded:: 3.24
  293. All calls to ``find_package()`` (even in Module mode) first look for a config
  294. package file in the :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` directory.
  295. The :module:`FetchContent` module, or even the project itself, may write files
  296. to that location to redirect ``find_package()`` calls to content already
  297. provided by the project. If no config package file is found in that location,
  298. the search proceeds with the logic described below.
  299. CMake constructs a set of possible installation prefixes for the
  300. package. Under each prefix several directories are searched for a
  301. configuration file. The tables below show the directories searched.
  302. Each entry is meant for installation trees following Windows (``W``), UNIX
  303. (``U``), or Apple (``A``) conventions:
  304. ==================================================================== ==========
  305. Entry Convention
  306. ==================================================================== ==========
  307. ``<prefix>/<name>/cps/`` [#p2]_ W
  308. ``<prefix>/<name>/*/cps/`` [#p2]_ W
  309. ``<prefix>/cps/<name>/`` [#p2]_ W
  310. ``<prefix>/cps/<name>/*/`` [#p2]_ W
  311. ``<prefix>/cps/`` [#p2]_ W
  312. ``<prefix>/`` W
  313. ``<prefix>/(cmake|CMake)/`` W
  314. ``<prefix>/<name>*/`` W
  315. ``<prefix>/<name>*/(cmake|CMake)/`` W
  316. ``<prefix>/<name>*/(cmake|CMake)/<name>*/`` [#p1]_ W
  317. ``<prefix>/(lib/<arch>|lib*|share)/cps/<name>/`` [#p2]_ U
  318. ``<prefix>/(lib/<arch>|lib*|share)/cps/<name>/*/`` [#p2]_ U
  319. ``<prefix>/(lib/<arch>|lib*|share)/cps/`` [#p2]_ U
  320. ``<prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/`` U
  321. ``<prefix>/(lib/<arch>|lib*|share)/<name>*/`` U
  322. ``<prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/`` U
  323. ``<prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/`` W/U
  324. ``<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/`` W/U
  325. ``<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/`` W/U
  326. ==================================================================== ==========
  327. .. [#p1] .. versionadded:: 3.25
  328. .. [#p2] .. versionadded:: 4.0
  329. On systems supporting macOS :prop_tgt:`FRAMEWORK` and :prop_tgt:`BUNDLE`, the
  330. following directories are searched for Frameworks or Application Bundles
  331. containing a configuration file:
  332. =============================================================== ==========
  333. Entry Convention
  334. =============================================================== ==========
  335. ``<prefix>/<name>.framework/Versions/*/Resources/CPS/`` [#p3]_ A
  336. ``<prefix>/<name>.framework/Resources/CPS/`` [#p3]_ A
  337. ``<prefix>/<name>.framework/Resources/`` A
  338. ``<prefix>/<name>.framework/Resources/CMake/`` A
  339. ``<prefix>/<name>.framework/Versions/*/Resources/`` A
  340. ``<prefix>/<name>.framework/Versions/*/Resources/CMake/`` A
  341. ``<prefix>/<name>.app/Contents/Resources/CPS/`` [#p3]_ A
  342. ``<prefix>/<name>.app/Contents/Resources/`` A
  343. ``<prefix>/<name>.app/Contents/Resources/CMake/`` A
  344. =============================================================== ==========
  345. .. [#p3] .. versionadded:: 4.0
  346. When searching the above paths, ``find_package`` will only look for ``.cps``
  347. files in search paths which contain ``/cps/``, and will only look for
  348. ``.cmake`` files otherwise. (This only applies to the paths as specified and
  349. does not consider the contents of ``<prefix>`` or ``<name>``.)
  350. In all cases the ``<name>`` is treated as case-insensitive and corresponds
  351. to any of the names specified (``<PackageName>`` or names given by ``NAMES``).
  352. If at least one compiled language has been enabled, the architecture-specific
  353. ``lib/<arch>`` and ``lib*`` directories may be searched based on the compiler's
  354. target architecture, in the following order:
  355. ``lib/<arch>``
  356. Searched if the :variable:`CMAKE_LIBRARY_ARCHITECTURE` variable is set.
  357. ``lib64``
  358. Searched on 64 bit platforms (:variable:`CMAKE_SIZEOF_VOID_P` is 8) and the
  359. :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` property is set to ``TRUE``.
  360. ``lib32``
  361. Searched on 32 bit platforms (:variable:`CMAKE_SIZEOF_VOID_P` is 4) and the
  362. :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` property is set to ``TRUE``.
  363. ``libx32``
  364. Searched on platforms using the x32 ABI
  365. if the :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS` property is set to ``TRUE``.
  366. ``lib``
  367. Always searched.
  368. .. versionchanged:: 3.24
  369. On ``Windows`` platform, it is possible to include registry queries as part
  370. of the directories specified through ``HINTS`` and ``PATHS`` keywords, using
  371. a :ref:`dedicated syntax <Find Using Windows Registry>`. Such specifications
  372. will be ignored on all other platforms.
  373. .. versionadded:: 3.24
  374. ``REGISTRY_VIEW`` can be specified to manage ``Windows`` registry queries
  375. specified as part of ``PATHS`` and ``HINTS``.
  376. .. include:: include/FIND_XXX_REGISTRY_VIEW.rst
  377. If ``PATH_SUFFIXES`` is specified, the suffixes are appended to each
  378. (``W``) or (``U``) directory entry one-by-one.
  379. This set of directories is intended to work in cooperation with
  380. projects that provide configuration files in their installation trees.
  381. Directories above marked with (``W``) are intended for installations on
  382. Windows where the prefix may point at the top of an application's
  383. installation directory. Those marked with (``U``) are intended for
  384. installations on UNIX platforms where the prefix is shared by multiple
  385. packages. This is merely a convention, so all (``W``) and (``U``) directories
  386. are still searched on all platforms. Directories marked with (``A``) are
  387. intended for installations on Apple platforms. The
  388. :variable:`CMAKE_FIND_FRAMEWORK` and :variable:`CMAKE_FIND_APPBUNDLE`
  389. variables determine the order of preference.
  390. .. warning::
  391. Setting :variable:`CMAKE_FIND_FRAMEWORK` or :variable:`CMAKE_FIND_APPBUNDLE`
  392. to values other than ``FIRST`` (the default) will cause CMake to search for
  393. |CPS| files in an order that is different from the order set forth in the
  394. specification.
  395. The set of installation prefixes is constructed using the following
  396. steps. If ``NO_DEFAULT_PATH`` is specified all ``NO_*`` options are
  397. enabled.
  398. 1. Search prefixes unique to the current ``<PackageName>`` being found.
  399. See policy :policy:`CMP0074`.
  400. .. versionadded:: 3.12
  401. Specifically, search prefixes specified by the following variables,
  402. in order:
  403. a. :variable:`<PackageName>_ROOT` CMake variable,
  404. where ``<PackageName>`` is the case-preserved package name.
  405. b. :variable:`<PACKAGENAME>_ROOT` CMake variable,
  406. where ``<PACKAGENAME>`` is the upper-cased package name.
  407. See policy :policy:`CMP0144`.
  408. .. versionadded:: 3.27
  409. c. :envvar:`<PackageName>_ROOT` environment variable,
  410. where ``<PackageName>`` is the case-preserved package name.
  411. d. :envvar:`<PACKAGENAME>_ROOT` environment variable,
  412. where ``<PACKAGENAME>`` is the upper-cased package name.
  413. See policy :policy:`CMP0144`.
  414. .. versionadded:: 3.27
  415. The package root variables are maintained as a stack so if
  416. called from within a find module, root paths from the parent's find
  417. module will also be searched after paths for the current package.
  418. This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed or by setting
  419. the :variable:`CMAKE_FIND_USE_PACKAGE_ROOT_PATH` to ``FALSE``.
  420. 2. Search paths specified in CMake-specific cache variables. These
  421. are intended to be used on the command line with a :option:`-DVAR=VALUE <cmake -D>`.
  422. The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
  423. This can be skipped if ``NO_CMAKE_PATH`` is passed or by setting the
  424. :variable:`CMAKE_FIND_USE_CMAKE_PATH` to ``FALSE``:
  425. * :variable:`CMAKE_PREFIX_PATH`
  426. * :variable:`CMAKE_FRAMEWORK_PATH`
  427. * :variable:`CMAKE_APPBUNDLE_PATH`
  428. 3. Search paths specified in CMake-specific environment variables.
  429. These are intended to be set in the user's shell configuration,
  430. and therefore use the host's native path separator
  431. (``;`` on Windows and ``:`` on UNIX).
  432. This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed or by setting
  433. the :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` to ``FALSE``:
  434. * ``<PackageName>_DIR``
  435. * :envvar:`CMAKE_PREFIX_PATH`
  436. * :envvar:`CMAKE_FRAMEWORK_PATH`
  437. * :envvar:`CMAKE_APPBUNDLE_PATH`
  438. 4. Search paths specified by the ``HINTS`` option. These should be paths
  439. computed by system introspection, such as a hint provided by the
  440. location of another item already found. Hard-coded guesses should
  441. be specified with the ``PATHS`` option.
  442. 5. Search the standard system environment variables. This can be
  443. skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed or by setting the
  444. :variable:`CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH` to ``FALSE``. Path entries
  445. ending in ``/bin`` or ``/sbin`` are automatically converted to their
  446. parent directories:
  447. * ``PATH``
  448. 6. Search paths stored in the CMake :ref:`User Package Registry`.
  449. This can be skipped if ``NO_CMAKE_PACKAGE_REGISTRY`` is passed or by
  450. setting the variable :variable:`CMAKE_FIND_USE_PACKAGE_REGISTRY`
  451. to ``FALSE`` or the deprecated variable
  452. :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` to ``TRUE``.
  453. See the :manual:`cmake-packages(7)` manual for details on the user
  454. package registry.
  455. 7. Search CMake variables defined in the Platform files for the
  456. current system. The searching of :variable:`CMAKE_INSTALL_PREFIX` and
  457. :variable:`CMAKE_STAGING_PREFIX` can be
  458. skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the
  459. :variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations
  460. can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the
  461. :variable:`CMAKE_FIND_USE_CMAKE_SYSTEM_PATH` to ``FALSE``:
  462. * :variable:`CMAKE_SYSTEM_PREFIX_PATH`
  463. * :variable:`CMAKE_SYSTEM_FRAMEWORK_PATH`
  464. * :variable:`CMAKE_SYSTEM_APPBUNDLE_PATH`
  465. The platform paths that these variables contain are locations that
  466. typically include installed software. An example being ``/usr/local`` for
  467. UNIX based platforms.
  468. 8. Search paths stored in the CMake :ref:`System Package Registry`.
  469. This can be skipped if ``NO_CMAKE_SYSTEM_PACKAGE_REGISTRY`` is passed
  470. or by setting the :variable:`CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY`
  471. variable to ``FALSE`` or the deprecated variable
  472. :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` to ``TRUE``.
  473. See the :manual:`cmake-packages(7)` manual for details on the system
  474. package registry.
  475. 9. Search paths specified by the ``PATHS`` option. These are typically
  476. hard-coded guesses.
  477. The :variable:`CMAKE_IGNORE_PATH`, :variable:`CMAKE_IGNORE_PREFIX_PATH`,
  478. :variable:`CMAKE_SYSTEM_IGNORE_PATH` and
  479. :variable:`CMAKE_SYSTEM_IGNORE_PREFIX_PATH` variables can also cause some
  480. of the above locations to be ignored.
  481. Paths are searched in the order described above. The first viable package
  482. configuration file found is used, even if a newer version of the package
  483. resides later in the list of search paths.
  484. For search paths which contain glob expressions (``*``), directories matching
  485. the glob are searched in natural, descending order by default. This behavior
  486. can be overridden by setting variables :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER`
  487. and :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION` accordingly. Those variables
  488. determine the order in which CMake considers glob matches. For example, if the
  489. file system contains the package configuration files
  490. ::
  491. <prefix>/example-1.2/example-config.cmake
  492. <prefix>/example-1.10/example-config.cmake
  493. <prefix>/share/example-2.0/example-config.cmake
  494. then ``find_package(example)`` will (when the aforementioned variables are
  495. unset) pick ``example-1.10`` (assuming both ``example-1.2`` and ``example-1.10``
  496. are viable). Note however that ``find_package`` will *not* find ``example-2.0``,
  497. because one of the other two will be found first.
  498. To control the order in which ``find_package`` searches directories that match
  499. a glob expression, use :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` and
  500. :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION`.
  501. For instance, to cause the above example to select ``example-1.2``,
  502. one can set
  503. .. code-block:: cmake
  504. set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
  505. set(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASC)
  506. before calling ``find_package``.
  507. .. versionadded:: 3.16
  508. Added the ``CMAKE_FIND_USE_<CATEGORY>`` variables to globally disable
  509. various search locations.
  510. .. versionchanged:: 4.0
  511. The variables :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` and
  512. :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION` now also control the order
  513. in which ``find_package`` searches directories matching the glob expression
  514. in the search paths ``<prefix>/<name>.framework/Versions/*/Resources/``
  515. and ``<prefix>/<name>.framework/Versions/*/Resources/CMake``. In previous
  516. versions of CMake, this order was unspecified.
  517. .. versionchanged:: 4.2
  518. When encountering multiple viable matches, ``find_package`` now picks the
  519. one with the most recent version by default. In previous versions of CMake,
  520. the result was unspecified. Accordingly, the default of
  521. :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` has changed from ``NONE`` to
  522. ``NATURAL`` and :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION`
  523. now defaults to ``DEC`` (descending) instead of ``ASC`` (ascending).
  524. .. include:: include/FIND_XXX_ROOT.rst
  525. .. include:: include/FIND_XXX_ORDER.rst
  526. By default the value stored in the result variable will be the path at
  527. which the file is found. The :variable:`CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS`
  528. variable may be set to ``TRUE`` before calling ``find_package`` in order
  529. to resolve symbolic links and store the real path to the file.
  530. Every non-REQUIRED ``find_package`` call can be disabled or made REQUIRED:
  531. * Setting the :variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable
  532. to ``TRUE`` disables the package. This also disables redirection to a
  533. package provided by :module:`FetchContent`.
  534. * Setting the :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable
  535. to ``TRUE`` makes the package REQUIRED.
  536. Setting both variables to ``TRUE`` simultaneously is an error.
  537. The :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable takes priority
  538. over the ``OPTIONAL`` keyword in determining whether a package is required.
  539. .. _`version selection`:
  540. Config Mode Version Selection
  541. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  542. .. note::
  543. When Config mode is used, this version selection process is applied
  544. regardless of whether the :ref:`full <full signature>` or
  545. :ref:`basic <basic signature>` signature was given.
  546. When the ``[version]`` argument is given, Config mode will only find a
  547. version of the package that claims compatibility with the requested
  548. version (see :ref:`format specification <FIND_PACKAGE_VERSION_FORMAT>`). If
  549. the ``EXACT`` option is given, only a version of the package claiming an exact
  550. match of the requested version may be found. CMake does not establish any
  551. convention for the meaning of version numbers.
  552. .. _`cmake script version selection`:
  553. CMake-script
  554. """"""""""""
  555. For CMake-script package configuration files, package version numbers are
  556. checked by "version" files provided by the packages themselves or by
  557. :module:`FetchContent`. For a candidate package configuration file
  558. ``<config-file>.cmake`` the corresponding version file is located next
  559. to it and named either ``<config-file>-version.cmake`` or
  560. ``<config-file>Version.cmake``. If no such version file is available
  561. then the configuration file is assumed to not be compatible with any
  562. requested version. A basic version file containing generic version
  563. matching code can be created using the
  564. :module:`CMakePackageConfigHelpers` module. When a version file
  565. is found it is loaded to check the requested version number. The
  566. version file is loaded in a nested scope in which the following
  567. variables have been defined:
  568. ``PACKAGE_FIND_NAME``
  569. The ``<PackageName>``
  570. ``PACKAGE_FIND_VERSION``
  571. Full requested version string
  572. ``PACKAGE_FIND_VERSION_MAJOR``
  573. Major version if requested, else 0
  574. ``PACKAGE_FIND_VERSION_MINOR``
  575. Minor version if requested, else 0
  576. ``PACKAGE_FIND_VERSION_PATCH``
  577. Patch version if requested, else 0
  578. ``PACKAGE_FIND_VERSION_TWEAK``
  579. Tweak version if requested, else 0
  580. ``PACKAGE_FIND_VERSION_COUNT``
  581. Number of version components, 0 to 4
  582. When a version range is specified, the above version variables will hold
  583. values based on the lower end of the version range. This is to preserve
  584. compatibility with packages that have not been implemented to expect version
  585. ranges. In addition, the version range will be described by the following
  586. variables:
  587. ``PACKAGE_FIND_VERSION_RANGE``
  588. Full requested version range string
  589. ``PACKAGE_FIND_VERSION_RANGE_MIN``
  590. This specifies whether the lower end point of the version range should be
  591. included or excluded. Currently, the only supported value for this variable
  592. is ``INCLUDE``.
  593. ``PACKAGE_FIND_VERSION_RANGE_MAX``
  594. This specifies whether the upper end point of the version range should be
  595. included or excluded. The supported values for this variable are
  596. ``INCLUDE`` and ``EXCLUDE``.
  597. ``PACKAGE_FIND_VERSION_MIN``
  598. Full requested version string of the lower end point of the range
  599. ``PACKAGE_FIND_VERSION_MIN_MAJOR``
  600. Major version of the lower end point if requested, else 0
  601. ``PACKAGE_FIND_VERSION_MIN_MINOR``
  602. Minor version of the lower end point if requested, else 0
  603. ``PACKAGE_FIND_VERSION_MIN_PATCH``
  604. Patch version of the lower end point if requested, else 0
  605. ``PACKAGE_FIND_VERSION_MIN_TWEAK``
  606. Tweak version of the lower end point if requested, else 0
  607. ``PACKAGE_FIND_VERSION_MIN_COUNT``
  608. Number of version components of the lower end point, 0 to 4
  609. ``PACKAGE_FIND_VERSION_MAX``
  610. Full requested version string of the upper end point of the range
  611. ``PACKAGE_FIND_VERSION_MAX_MAJOR``
  612. Major version of the upper end point if requested, else 0
  613. ``PACKAGE_FIND_VERSION_MAX_MINOR``
  614. Minor version of the upper end point if requested, else 0
  615. ``PACKAGE_FIND_VERSION_MAX_PATCH``
  616. Patch version of the upper end point if requested, else 0
  617. ``PACKAGE_FIND_VERSION_MAX_TWEAK``
  618. Tweak version of the upper end point if requested, else 0
  619. ``PACKAGE_FIND_VERSION_MAX_COUNT``
  620. Number of version components of the upper end point, 0 to 4
  621. Regardless of whether a single version or a version range is specified, the
  622. variable ``PACKAGE_FIND_VERSION_COMPLETE`` will be defined and will hold
  623. the full requested version string as specified.
  624. The version file checks whether it satisfies the requested version and
  625. sets these variables:
  626. ``PACKAGE_VERSION``
  627. Full provided version string
  628. ``PACKAGE_VERSION_EXACT``
  629. True if version is exact match
  630. ``PACKAGE_VERSION_COMPATIBLE``
  631. True if version is compatible
  632. ``PACKAGE_VERSION_UNSUITABLE``
  633. True if unsuitable as any version
  634. These variables are checked by the ``find_package`` command to determine
  635. whether the configuration file provides an acceptable version. They
  636. are not available after the ``find_package`` call returns. If the version
  637. is acceptable, the following variables are set:
  638. ``<PackageName>_VERSION``
  639. Full provided version string
  640. ``<PackageName>_VERSION_MAJOR``
  641. Major version if provided, else 0
  642. ``<PackageName>_VERSION_MINOR``
  643. Minor version if provided, else 0
  644. ``<PackageName>_VERSION_PATCH``
  645. Patch version if provided, else 0
  646. ``<PackageName>_VERSION_TWEAK``
  647. Tweak version if provided, else 0
  648. ``<PackageName>_VERSION_COUNT``
  649. Number of version components, 0 to 4
  650. and the corresponding package configuration file is loaded.
  651. .. note::
  652. While the exact behavior of version matching is determined by the individual
  653. package, many packages use :command:`write_basic_package_version_file` to
  654. supply this logic. The version check scripts this produces have some notable
  655. caveats with respect to version ranges:
  656. * The upper end of a version range acts as a hard limit on what versions will
  657. be accepted. Thus, while a request for version ``1.4.0`` might be
  658. satisfied by a package whose version is ``1.6.0`` and which advertises
  659. 'same major version' compatibility, the same package will be rejected if
  660. the requested version range is ``1.4.0...1.5.0``.
  661. * Both ends of the version range must match the package's advertised
  662. compatibility level. For example, if a package advertises 'same major and
  663. minor version' compatibility, requesting the version range
  664. ``1.4.0...<1.5.5`` or ``1.4.0...1.5.0`` will result in that package being
  665. rejected, even if the package version is ``1.4.1``.
  666. As a result, it is not possible to use a version range to extend the range
  667. of compatible package versions that will be accepted.
  668. .. _`cps version selection`:
  669. |CPS|
  670. """""
  671. For |CPS| package configuration files, package version numbers are checked by
  672. CMake according to the set of recognized version schemas. At present, the
  673. following schemas are recognized:
  674. ``simple``
  675. Version numbers are a tuple of integers followed by an optional trailing
  676. segment which is ignored with respect to version comparisons.
  677. ``custom``
  678. The mechanism for interpreting version numbers is unspecified. The version
  679. strings must match exactly for the package to be accepted.
  680. Refer to |cps-version_schema|_ for a more detailed explanation of each schema
  681. and how comparisons for each are performed. Note that the specification may
  682. include schemas that are not supported by CMake.
  683. In addition to the package's ``version``, CPS allows packages to optionally
  684. specify a |cps-compat_version|_, which is the oldest version for which the
  685. package provides compatibility. That is, the package warrants that a consumer
  686. expecting the ``compat_version`` should be able to use the package, even if the
  687. package's actual version is newer. If not specified, the ``compat_version``
  688. is implicitly equal to the package version, i.e. no backwards compatibility is
  689. provided.
  690. .. TODO Rework the preceding paragraph when COMPAT_VERSION has broader support
  691. in CMake.
  692. When a package uses a recognized schema, CMake will determine the package's
  693. acceptability according to the following rules:
  694. * If ``EXACT`` was specified, or if the package does not supply a
  695. ``compat_version``, the package's ``version`` must equal the requested
  696. version.
  697. * Otherwise:
  698. * The package's ``version`` must be greater than or equal to the requested
  699. (minimum) version, and
  700. * the package's ``compat_version`` must be less than or equal to the
  701. requested (minimum) version, and
  702. * if a requested maximum version was given, it must be greater than (or equal
  703. to, depending on whether the maximum version is specified as inclusive or
  704. exclusive) the package's ``version``.
  705. .. note::
  706. This implementation of range matching was chosen in order to most closely
  707. match the behavior of :command:`write_basic_package_version_file`, albeit
  708. without the case where an overly broad range matches nothing.
  709. For packages using the ``simple`` version schema, if the version is acceptable,
  710. the following variables are set:
  711. ``<PackageName>_VERSION``
  712. Full provided version string
  713. ``<PackageName>_VERSION_MAJOR``
  714. Major version if provided, else 0
  715. ``<PackageName>_VERSION_MINOR``
  716. Minor version if provided, else 0
  717. ``<PackageName>_VERSION_PATCH``
  718. Patch version if provided, else 0
  719. ``<PackageName>_VERSION_TWEAK``
  720. Tweak version if provided, else 0
  721. ``<PackageName>_VERSION_COUNT``
  722. Number of version components, non-negative
  723. Package File Interface Variables
  724. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  725. When loading a find module or CMake-script package configuration file,
  726. ``find_package`` defines variables to provide information about the call
  727. arguments (and restores their original state before returning):
  728. ``CMAKE_FIND_PACKAGE_NAME``
  729. The ``<PackageName>`` which is searched for
  730. ``<PackageName>_FIND_REQUIRED``
  731. True if ``REQUIRED`` option was given
  732. ``<PackageName>_FIND_QUIETLY``
  733. True if ``QUIET`` option was given
  734. ``<PackageName>_FIND_REGISTRY_VIEW``
  735. The requested view if ``REGISTRY_VIEW`` option was given
  736. ``<PackageName>_FIND_VERSION``
  737. Full requested version string
  738. ``<PackageName>_FIND_VERSION_MAJOR``
  739. Major version if requested, else 0
  740. ``<PackageName>_FIND_VERSION_MINOR``
  741. Minor version if requested, else 0
  742. ``<PackageName>_FIND_VERSION_PATCH``
  743. Patch version if requested, else 0
  744. ``<PackageName>_FIND_VERSION_TWEAK``
  745. Tweak version if requested, else 0
  746. ``<PackageName>_FIND_VERSION_COUNT``
  747. Number of version components, 0 to 4
  748. ``<PackageName>_FIND_VERSION_EXACT``
  749. True if ``EXACT`` option was given
  750. ``<PackageName>_FIND_COMPONENTS``
  751. List of specified components (required and optional)
  752. ``<PackageName>_FIND_REQUIRED_<c>``
  753. True if component ``<c>`` is required,
  754. false if component ``<c>`` is optional
  755. When a version range is specified, the above version variables will hold
  756. values based on the lower end of the version range. This is to preserve
  757. compatibility with packages that have not been implemented to expect version
  758. ranges. In addition, the version range will be described by the following
  759. variables:
  760. ``<PackageName>_FIND_VERSION_RANGE``
  761. Full requested version range string
  762. ``<PackageName>_FIND_VERSION_RANGE_MIN``
  763. This specifies whether the lower end point of the version range is
  764. included or excluded. Currently, ``INCLUDE`` is the only supported value.
  765. ``<PackageName>_FIND_VERSION_RANGE_MAX``
  766. This specifies whether the upper end point of the version range is
  767. included or excluded. The possible values for this variable are
  768. ``INCLUDE`` or ``EXCLUDE``.
  769. ``<PackageName>_FIND_VERSION_MIN``
  770. Full requested version string of the lower end point of the range
  771. ``<PackageName>_FIND_VERSION_MIN_MAJOR``
  772. Major version of the lower end point if requested, else 0
  773. ``<PackageName>_FIND_VERSION_MIN_MINOR``
  774. Minor version of the lower end point if requested, else 0
  775. ``<PackageName>_FIND_VERSION_MIN_PATCH``
  776. Patch version of the lower end point if requested, else 0
  777. ``<PackageName>_FIND_VERSION_MIN_TWEAK``
  778. Tweak version of the lower end point if requested, else 0
  779. ``<PackageName>_FIND_VERSION_MIN_COUNT``
  780. Number of version components of the lower end point, 0 to 4
  781. ``<PackageName>_FIND_VERSION_MAX``
  782. Full requested version string of the upper end point of the range
  783. ``<PackageName>_FIND_VERSION_MAX_MAJOR``
  784. Major version of the upper end point if requested, else 0
  785. ``<PackageName>_FIND_VERSION_MAX_MINOR``
  786. Minor version of the upper end point if requested, else 0
  787. ``<PackageName>_FIND_VERSION_MAX_PATCH``
  788. Patch version of the upper end point if requested, else 0
  789. ``<PackageName>_FIND_VERSION_MAX_TWEAK``
  790. Tweak version of the upper end point if requested, else 0
  791. ``<PackageName>_FIND_VERSION_MAX_COUNT``
  792. Number of version components of the upper end point, 0 to 4
  793. Regardless of whether a single version or a version range is specified, the
  794. variable ``<PackageName>_FIND_VERSION_COMPLETE`` will be defined and will hold
  795. the full requested version string as specified.
  796. In Module mode the loaded find module is responsible to honor the
  797. request detailed by these variables; see the find module for details.
  798. In Config mode ``find_package`` handles ``REQUIRED``, ``QUIET``, and
  799. ``[version]`` options automatically but leaves it to the package
  800. configuration file to handle components in a way that makes sense
  801. for the package. The package configuration file may set
  802. ``<PackageName>_FOUND`` to false to tell ``find_package`` that component
  803. requirements are not satisfied.
  804. .. _CPS: https://cps-org.github.io/cps/
  805. .. |CPS| replace:: Common Package Specification
  806. .. _cps-compat_version: https://cps-org.github.io/cps/schema.html#compat-version
  807. .. |cps-compat_version| replace:: ``compat_version``
  808. .. _cps-version_schema: https://cps-org.github.io/cps/schema.html#version-schema
  809. .. |cps-version_schema| replace:: ``version_schema``
  810. CPS Transitive Requirements
  811. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  812. A |CPS| package description consists of one or more components which may in
  813. turn depend on other components either internal or external to the package.
  814. When external components are required, the providing package is noted as
  815. a package-level requirement of the package. Additionally, the set of required
  816. components is typically noted in said external package requirement.
  817. Where a CMake-script package description would use the
  818. :command:`find_dependency` command to handle transitive dependencies, CMake
  819. handles transitive dependencies for CPS itself using an internally nested
  820. ``find_package`` call. This call can resolve CPS package dependencies via
  821. *either* another CPS package, or via a CMake-script package. The manner in
  822. which the CPS component dependencies are handled is subject to some caveats.
  823. When the candidate for resolving a transitive dependency is another CPS
  824. package, things are simple; ``COMPONENTS`` and CPS "components" are directly
  825. comparable (and are effectively synonymous with CMake "imported targets").
  826. CMake-script packages, however, are encouraged to (and often do) check that
  827. required components were found, whether or not the package describes separate
  828. components. Additionally, even those that do describe components typically do
  829. not have the same correlation to imported targets that is normal for CPS. As
  830. a result, passing the set of required components declared by a CPS package to
  831. ``COMPONENTS`` would result in spurious failures to resolve dependencies.
  832. To address this, if a candidate for resolving a CPS transitive dependency is a
  833. CMake-script package, CMake passes the required components as declared by the
  834. consuming CPS package as ``OPTIONAL_COMPONENTS`` and performs a separate,
  835. internal check that the candidate package supplied the required imported
  836. targets. Those targets must be named ``<PackageName>::<ComponentName>``, in
  837. conformance with CPS convention, or the check will consider the package not
  838. found.