find_package.rst 45 KB

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