find_package.rst 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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, CMake will ignore it and search from scratch.
  280. Package maintainers providing package configuration files are encouraged to
  281. name and install them such that the :ref:`search procedure` outlined below
  282. will find them without requiring use of additional options.
  283. .. _`search procedure`:
  284. Config Mode Search Procedure
  285. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  286. .. note::
  287. When Config mode is used, this search procedure is applied regardless of
  288. whether the :ref:`full <full signature>` or :ref:`basic <basic signature>`
  289. signature was given.
  290. .. versionadded:: 3.24
  291. All calls to ``find_package()`` (even in Module mode) first look for a config
  292. package file in the :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` directory.
  293. The :module:`FetchContent` module, or even the project itself, may write files
  294. to that location to redirect ``find_package()`` calls to content already
  295. provided by the project. If no config package file is found in that location,
  296. the search proceeds with the logic described below.
  297. CMake constructs a set of possible installation prefixes for the
  298. package. Under each prefix several directories are searched for a
  299. configuration file. The tables below show the directories searched.
  300. Each entry is meant for installation trees following Windows (``W``), UNIX
  301. (``U``), or Apple (``A``) conventions:
  302. ==================================================================== ==========
  303. Entry Convention
  304. ==================================================================== ==========
  305. ``<prefix>/<name>/cps/`` [#p2]_ W
  306. ``<prefix>/<name>/*/cps/`` [#p2]_ W
  307. ``<prefix>/cps/<name>/`` [#p2]_ W
  308. ``<prefix>/cps/<name>/*/`` [#p2]_ W
  309. ``<prefix>/cps/`` [#p2]_ W
  310. ``<prefix>/`` W
  311. ``<prefix>/(cmake|CMake)/`` W
  312. ``<prefix>/<name>*/`` W
  313. ``<prefix>/<name>*/(cmake|CMake)/`` W
  314. ``<prefix>/<name>*/(cmake|CMake)/<name>*/`` [#p1]_ W
  315. ``<prefix>/(lib/<arch>|lib*|share)/cps/<name>/`` [#p2]_ U
  316. ``<prefix>/(lib/<arch>|lib*|share)/cps/<name>/*/`` [#p2]_ U
  317. ``<prefix>/(lib/<arch>|lib*|share)/cps/`` [#p2]_ U
  318. ``<prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/`` U
  319. ``<prefix>/(lib/<arch>|lib*|share)/<name>*/`` U
  320. ``<prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/`` U
  321. ``<prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/`` W/U
  322. ``<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/`` W/U
  323. ``<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/`` W/U
  324. ==================================================================== ==========
  325. .. [#p1] .. versionadded:: 3.25
  326. .. [#p2] .. versionadded:: 4.0
  327. On systems supporting macOS :prop_tgt:`FRAMEWORK` and :prop_tgt:`BUNDLE`, the
  328. following directories are searched for Frameworks or Application Bundles
  329. containing a configuration file:
  330. =============================================================== ==========
  331. Entry Convention
  332. =============================================================== ==========
  333. ``<prefix>/<name>.framework/Versions/*/Resources/CPS/`` [#p3]_ A
  334. ``<prefix>/<name>.framework/Resources/CPS/`` [#p3]_ A
  335. ``<prefix>/<name>.framework/Resources/`` A
  336. ``<prefix>/<name>.framework/Resources/CMake/`` A
  337. ``<prefix>/<name>.framework/Versions/*/Resources/`` A
  338. ``<prefix>/<name>.framework/Versions/*/Resources/CMake/`` A
  339. ``<prefix>/<name>.app/Contents/Resources/CPS/`` [#p3]_ A
  340. ``<prefix>/<name>.app/Contents/Resources/`` A
  341. ``<prefix>/<name>.app/Contents/Resources/CMake/`` A
  342. =============================================================== ==========
  343. .. [#p3] .. versionadded:: 4.0
  344. When searching the above paths, ``find_package`` will only look for ``.cps``
  345. files in search paths which contain ``/cps/``, and will only look for
  346. ``.cmake`` files otherwise. (This only applies to the paths as specified and
  347. does not consider the contents of ``<prefix>`` or ``<name>``.)
  348. In all cases the ``<name>`` is treated as case-insensitive and corresponds
  349. to any of the names specified (``<PackageName>`` or names given by ``NAMES``).
  350. If at least one compiled language has been enabled, the architecture-specific
  351. ``lib/<arch>`` and ``lib*`` directories may be searched based on the compiler's
  352. target architecture, in the following order:
  353. ``lib/<arch>``
  354. Searched if the :variable:`CMAKE_LIBRARY_ARCHITECTURE` variable is set.
  355. ``lib64``
  356. Searched on 64 bit platforms (:variable:`CMAKE_SIZEOF_VOID_P` is 8) and the
  357. :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` property is set to ``TRUE``.
  358. ``lib32``
  359. Searched on 32 bit platforms (:variable:`CMAKE_SIZEOF_VOID_P` is 4) and the
  360. :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` property is set to ``TRUE``.
  361. ``libx32``
  362. Searched on platforms using the x32 ABI
  363. if the :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS` property is set to ``TRUE``.
  364. ``lib``
  365. Always searched.
  366. .. versionchanged:: 3.24
  367. On ``Windows`` platform, it is possible to include registry queries as part
  368. of the directories specified through ``HINTS`` and ``PATHS`` keywords, using
  369. a :ref:`dedicated syntax <Find Using Windows Registry>`. Such specifications
  370. will be ignored on all other platforms.
  371. .. versionadded:: 3.24
  372. ``REGISTRY_VIEW`` can be specified to manage ``Windows`` registry queries
  373. specified as part of ``PATHS`` and ``HINTS``.
  374. .. include:: include/FIND_XXX_REGISTRY_VIEW.rst
  375. If ``PATH_SUFFIXES`` is specified, the suffixes are appended to each
  376. (``W``) or (``U``) directory entry one-by-one.
  377. This set of directories is intended to work in cooperation with
  378. projects that provide configuration files in their installation trees.
  379. Directories above marked with (``W``) are intended for installations on
  380. Windows where the prefix may point at the top of an application's
  381. installation directory. Those marked with (``U``) are intended for
  382. installations on UNIX platforms where the prefix is shared by multiple
  383. packages. This is merely a convention, so all (``W``) and (``U``) directories
  384. are still searched on all platforms. Directories marked with (``A``) are
  385. intended for installations on Apple platforms. The
  386. :variable:`CMAKE_FIND_FRAMEWORK` and :variable:`CMAKE_FIND_APPBUNDLE`
  387. variables determine the order of preference.
  388. .. warning::
  389. Setting :variable:`CMAKE_FIND_FRAMEWORK` or :variable:`CMAKE_FIND_APPBUNDLE`
  390. to values other than ``FIRST`` (the default) will cause CMake to search for
  391. |CPS| files in an order that is different from the order set forth in the
  392. specification.
  393. The set of installation prefixes is constructed using the following
  394. steps. If ``NO_DEFAULT_PATH`` is specified all ``NO_*`` options are
  395. enabled.
  396. 1. Search prefixes unique to the current ``<PackageName>`` being found.
  397. See policy :policy:`CMP0074`.
  398. .. versionadded:: 3.12
  399. Specifically, search prefixes specified by the following variables,
  400. in order:
  401. a. :variable:`<PackageName>_ROOT` CMake variable,
  402. where ``<PackageName>`` is the case-preserved package name.
  403. b. :variable:`<PACKAGENAME>_ROOT` CMake variable,
  404. where ``<PACKAGENAME>`` is the upper-cased package name.
  405. See policy :policy:`CMP0144`.
  406. .. versionadded:: 3.27
  407. c. :envvar:`<PackageName>_ROOT` environment variable,
  408. where ``<PackageName>`` is the case-preserved package name.
  409. d. :envvar:`<PACKAGENAME>_ROOT` environment variable,
  410. where ``<PACKAGENAME>`` is the upper-cased package name.
  411. See policy :policy:`CMP0144`.
  412. .. versionadded:: 3.27
  413. The package root variables are maintained as a stack so if
  414. called from within a find module, root paths from the parent's find
  415. module will also be searched after paths for the current package.
  416. This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed or by setting
  417. the :variable:`CMAKE_FIND_USE_PACKAGE_ROOT_PATH` to ``FALSE``.
  418. 2. Search paths specified in CMake-specific cache variables. These
  419. are intended to be used on the command line with a :option:`-DVAR=VALUE <cmake -D>`.
  420. The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
  421. This can be skipped if ``NO_CMAKE_PATH`` is passed or by setting the
  422. :variable:`CMAKE_FIND_USE_CMAKE_PATH` to ``FALSE``:
  423. * :variable:`CMAKE_PREFIX_PATH`
  424. * :variable:`CMAKE_FRAMEWORK_PATH`
  425. * :variable:`CMAKE_APPBUNDLE_PATH`
  426. 3. Search paths specified in CMake-specific environment variables.
  427. These are intended to be set in the user's shell configuration,
  428. and therefore use the host's native path separator
  429. (``;`` on Windows and ``:`` on UNIX).
  430. This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed or by setting
  431. the :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` to ``FALSE``:
  432. * ``<PackageName>_DIR``
  433. * :envvar:`CMAKE_PREFIX_PATH`
  434. * :envvar:`CMAKE_FRAMEWORK_PATH`
  435. * :envvar:`CMAKE_APPBUNDLE_PATH`
  436. 4. Search paths specified by the ``HINTS`` option. These should be paths
  437. computed by system introspection, such as a hint provided by the
  438. location of another item already found. Hard-coded guesses should
  439. be specified with the ``PATHS`` option.
  440. 5. Search the standard system environment variables. This can be
  441. skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed or by setting the
  442. :variable:`CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH` to ``FALSE``. Path entries
  443. ending in ``/bin`` or ``/sbin`` are automatically converted to their
  444. parent directories:
  445. * ``PATH``
  446. 6. Search paths stored in the CMake :ref:`User Package Registry`.
  447. This can be skipped if ``NO_CMAKE_PACKAGE_REGISTRY`` is passed or by
  448. setting the variable :variable:`CMAKE_FIND_USE_PACKAGE_REGISTRY`
  449. to ``FALSE`` or the deprecated variable
  450. :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` to ``TRUE``.
  451. See the :manual:`cmake-packages(7)` manual for details on the user
  452. package registry.
  453. 7. Search CMake variables defined in the Platform files for the
  454. current system. The searching of :variable:`CMAKE_INSTALL_PREFIX` and
  455. :variable:`CMAKE_STAGING_PREFIX` can be
  456. skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the
  457. :variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations
  458. can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the
  459. :variable:`CMAKE_FIND_USE_CMAKE_SYSTEM_PATH` to ``FALSE``:
  460. * :variable:`CMAKE_SYSTEM_PREFIX_PATH`
  461. * :variable:`CMAKE_SYSTEM_FRAMEWORK_PATH`
  462. * :variable:`CMAKE_SYSTEM_APPBUNDLE_PATH`
  463. The platform paths that these variables contain are locations that
  464. typically include installed software. An example being ``/usr/local`` for
  465. UNIX based platforms.
  466. 8. Search paths stored in the CMake :ref:`System Package Registry`.
  467. This can be skipped if ``NO_CMAKE_SYSTEM_PACKAGE_REGISTRY`` is passed
  468. or by setting the :variable:`CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY`
  469. variable to ``FALSE`` or the deprecated variable
  470. :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` to ``TRUE``.
  471. See the :manual:`cmake-packages(7)` manual for details on the system
  472. package registry.
  473. 9. Search paths specified by the ``PATHS`` option. These are typically
  474. hard-coded guesses.
  475. The :variable:`CMAKE_IGNORE_PATH`, :variable:`CMAKE_IGNORE_PREFIX_PATH`,
  476. :variable:`CMAKE_SYSTEM_IGNORE_PATH` and
  477. :variable:`CMAKE_SYSTEM_IGNORE_PREFIX_PATH` variables can also cause some
  478. of the above locations to be ignored.
  479. Paths are searched in the order described above. The first viable package
  480. configuration file found is used, even if a newer version of the package
  481. resides later in the list of search paths.
  482. For search paths which contain glob expressions (``*``), directories matching
  483. the glob are searched in natural, descending order by default. This behavior
  484. can be overridden by setting variables :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER`
  485. and :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION` accordingly. Those variables
  486. determine the order in which CMake considers glob matches. For example, if the
  487. file system contains the package configuration files
  488. ::
  489. <prefix>/example-1.2/example-config.cmake
  490. <prefix>/example-1.10/example-config.cmake
  491. <prefix>/share/example-2.0/example-config.cmake
  492. then ``find_package(example)`` will (when the aforementioned variables are
  493. unset) pick ``example-1.10`` (assuming both ``example-1.2`` and ``example-1.10``
  494. are viable). Note however that ``find_package`` will *not* find ``example-2.0``,
  495. because one of the other two will be found first.
  496. To control the order in which ``find_package`` searches directories that match
  497. a glob expression, use :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` and
  498. :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION`.
  499. For instance, to cause the above example to select ``example-1.2``,
  500. one can set
  501. .. code-block:: cmake
  502. set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
  503. set(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASC)
  504. before calling ``find_package``.
  505. .. versionadded:: 3.16
  506. Added the ``CMAKE_FIND_USE_<CATEGORY>`` variables to globally disable
  507. various search locations.
  508. .. versionchanged:: 4.0
  509. The variables :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` and
  510. :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION` now also control the order
  511. in which ``find_package`` searches directories matching the glob expression
  512. in the search paths ``<prefix>/<name>.framework/Versions/*/Resources/``
  513. and ``<prefix>/<name>.framework/Versions/*/Resources/CMake``. In previous
  514. versions of CMake, this order was unspecified.
  515. .. versionchanged:: 4.2
  516. When encountering multiple viable matches, ``find_package`` now picks the
  517. one with the most recent version by default. In previous versions of CMake,
  518. the result was unspecified. Accordingly, the default of
  519. :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` has changed from ``NONE`` to
  520. ``NATURAL`` and :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION`
  521. now defaults to ``DEC`` (descending) instead of ``ASC`` (ascending).
  522. .. include:: include/FIND_XXX_ROOT.rst
  523. .. include:: include/FIND_XXX_ORDER.rst
  524. By default the value stored in the result variable will be the path at
  525. which the file is found. The :variable:`CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS`
  526. variable may be set to ``TRUE`` before calling ``find_package`` in order
  527. to resolve symbolic links and store the real path to the file.
  528. Every non-REQUIRED ``find_package`` call can be disabled or made REQUIRED:
  529. * Setting the :variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable
  530. to ``TRUE`` disables the package. This also disables redirection to a
  531. package provided by :module:`FetchContent`.
  532. * Setting the :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable
  533. to ``TRUE`` makes the package REQUIRED.
  534. Setting both variables to ``TRUE`` simultaneously is an error.
  535. The :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable takes priority
  536. over the ``OPTIONAL`` keyword in determining whether a package is required.
  537. .. _`version selection`:
  538. Config Mode Version Selection
  539. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  540. .. note::
  541. When Config mode is used, this version selection process is applied
  542. regardless of whether the :ref:`full <full signature>` or
  543. :ref:`basic <basic signature>` signature was given.
  544. When the ``[version]`` argument is given, Config mode will only find a
  545. version of the package that claims compatibility with the requested
  546. version (see :ref:`format specification <FIND_PACKAGE_VERSION_FORMAT>`). If
  547. the ``EXACT`` option is given, only a version of the package claiming an exact
  548. match of the requested version may be found. CMake does not establish any
  549. convention for the meaning of version numbers.
  550. .. _`cmake script version selection`:
  551. CMake-script
  552. """"""""""""
  553. For CMake-script package configuration files, package version numbers are
  554. checked by "version" files provided by the packages themselves or by
  555. :module:`FetchContent`. For a candidate package configuration file
  556. ``<config-file>.cmake`` the corresponding version file is located next
  557. to it and named either ``<config-file>-version.cmake`` or
  558. ``<config-file>Version.cmake``. If no such version file is available
  559. then the configuration file is assumed to not be compatible with any
  560. requested version. A basic version file containing generic version
  561. matching code can be created using the
  562. :module:`CMakePackageConfigHelpers` module. When a version file
  563. is found it is loaded to check the requested version number. The
  564. version file is loaded in a nested scope in which the following
  565. variables have been defined:
  566. ``PACKAGE_FIND_NAME``
  567. The ``<PackageName>``
  568. ``PACKAGE_FIND_VERSION``
  569. Full requested version string
  570. ``PACKAGE_FIND_VERSION_MAJOR``
  571. Major version if requested, else 0
  572. ``PACKAGE_FIND_VERSION_MINOR``
  573. Minor version if requested, else 0
  574. ``PACKAGE_FIND_VERSION_PATCH``
  575. Patch version if requested, else 0
  576. ``PACKAGE_FIND_VERSION_TWEAK``
  577. Tweak version if requested, else 0
  578. ``PACKAGE_FIND_VERSION_COUNT``
  579. Number of version components, 0 to 4
  580. When a version range is specified, the above version variables will hold
  581. values based on the lower end of the version range. This is to preserve
  582. compatibility with packages that have not been implemented to expect version
  583. ranges. In addition, the version range will be described by the following
  584. variables:
  585. ``PACKAGE_FIND_VERSION_RANGE``
  586. Full requested version range string
  587. ``PACKAGE_FIND_VERSION_RANGE_MIN``
  588. This specifies whether the lower end point of the version range should be
  589. included or excluded. Currently, the only supported value for this variable
  590. is ``INCLUDE``.
  591. ``PACKAGE_FIND_VERSION_RANGE_MAX``
  592. This specifies whether the upper end point of the version range should be
  593. included or excluded. The supported values for this variable are
  594. ``INCLUDE`` and ``EXCLUDE``.
  595. ``PACKAGE_FIND_VERSION_MIN``
  596. Full requested version string of the lower end point of the range
  597. ``PACKAGE_FIND_VERSION_MIN_MAJOR``
  598. Major version of the lower end point if requested, else 0
  599. ``PACKAGE_FIND_VERSION_MIN_MINOR``
  600. Minor version of the lower end point if requested, else 0
  601. ``PACKAGE_FIND_VERSION_MIN_PATCH``
  602. Patch version of the lower end point if requested, else 0
  603. ``PACKAGE_FIND_VERSION_MIN_TWEAK``
  604. Tweak version of the lower end point if requested, else 0
  605. ``PACKAGE_FIND_VERSION_MIN_COUNT``
  606. Number of version components of the lower end point, 0 to 4
  607. ``PACKAGE_FIND_VERSION_MAX``
  608. Full requested version string of the upper end point of the range
  609. ``PACKAGE_FIND_VERSION_MAX_MAJOR``
  610. Major version of the upper end point if requested, else 0
  611. ``PACKAGE_FIND_VERSION_MAX_MINOR``
  612. Minor version of the upper end point if requested, else 0
  613. ``PACKAGE_FIND_VERSION_MAX_PATCH``
  614. Patch version of the upper end point if requested, else 0
  615. ``PACKAGE_FIND_VERSION_MAX_TWEAK``
  616. Tweak version of the upper end point if requested, else 0
  617. ``PACKAGE_FIND_VERSION_MAX_COUNT``
  618. Number of version components of the upper end point, 0 to 4
  619. Regardless of whether a single version or a version range is specified, the
  620. variable ``PACKAGE_FIND_VERSION_COMPLETE`` will be defined and will hold
  621. the full requested version string as specified.
  622. The version file checks whether it satisfies the requested version and
  623. sets these variables:
  624. ``PACKAGE_VERSION``
  625. Full provided version string
  626. ``PACKAGE_VERSION_EXACT``
  627. True if version is exact match
  628. ``PACKAGE_VERSION_COMPATIBLE``
  629. True if version is compatible
  630. ``PACKAGE_VERSION_UNSUITABLE``
  631. True if unsuitable as any version
  632. These variables are checked by the ``find_package`` command to determine
  633. whether the configuration file provides an acceptable version. They
  634. are not available after the ``find_package`` call returns. If the version
  635. is acceptable, the following variables are set:
  636. ``<PackageName>_VERSION``
  637. Full provided version string
  638. ``<PackageName>_VERSION_MAJOR``
  639. Major version if provided, else 0
  640. ``<PackageName>_VERSION_MINOR``
  641. Minor version if provided, else 0
  642. ``<PackageName>_VERSION_PATCH``
  643. Patch version if provided, else 0
  644. ``<PackageName>_VERSION_TWEAK``
  645. Tweak version if provided, else 0
  646. ``<PackageName>_VERSION_COUNT``
  647. Number of version components, 0 to 4
  648. and the corresponding package configuration file is loaded.
  649. .. note::
  650. While the exact behavior of version matching is determined by the individual
  651. package, many packages use :command:`write_basic_package_version_file` to
  652. supply this logic. The version check scripts this produces have some notable
  653. caveats with respect to version ranges:
  654. * The upper end of a version range acts as a hard limit on what versions will
  655. be accepted. Thus, while a request for version ``1.4.0`` might be
  656. satisfied by a package whose version is ``1.6.0`` and which advertises
  657. 'same major version' compatibility, the same package will be rejected if
  658. the requested version range is ``1.4.0...1.5.0``.
  659. * Both ends of the version range must match the package's advertised
  660. compatibility level. For example, if a package advertises 'same major and
  661. minor version' compatibility, requesting the version range
  662. ``1.4.0...<1.5.5`` or ``1.4.0...1.5.0`` will result in that package being
  663. rejected, even if the package version is ``1.4.1``.
  664. As a result, it is not possible to use a version range to extend the range
  665. of compatible package versions that will be accepted.
  666. .. _`cps version selection`:
  667. |CPS|
  668. """""
  669. For |CPS| package configuration files, package version numbers are checked by
  670. CMake according to the set of recognized version schemas. At present, the
  671. following schemas are recognized:
  672. ``simple``
  673. Version numbers are a tuple of integers followed by an optional trailing
  674. segment which is ignored with respect to version comparisons.
  675. ``custom``
  676. The mechanism for interpreting version numbers is unspecified. The version
  677. strings must match exactly for the package to be accepted.
  678. Refer to |cps-version_schema|_ for a more detailed explanation of each schema
  679. and how comparisons for each are performed. Note that the specification may
  680. include schemas that are not supported by CMake.
  681. In addition to the package's ``version``, CPS allows packages to optionally
  682. specify a |cps-compat_version|_, which is the oldest version for which the
  683. package provides compatibility. That is, the package warrants that a consumer
  684. expecting the ``compat_version`` should be able to use the package, even if the
  685. package's actual version is newer. If not specified, the ``compat_version``
  686. is implicitly equal to the package version, i.e. no backwards compatibility is
  687. provided.
  688. .. TODO Rework the preceding paragraph when COMPAT_VERSION has broader support
  689. in CMake.
  690. When a package uses a recognized schema, CMake will determine the package's
  691. acceptability according to the following rules:
  692. * If ``EXACT`` was specified, or if the package does not supply a
  693. ``compat_version``, the package's ``version`` must equal the requested
  694. version.
  695. * Otherwise:
  696. * The package's ``version`` must be greater than or equal to the requested
  697. (minimum) version, and
  698. * the package's ``compat_version`` must be less than or equal to the
  699. requested (minimum) version, and
  700. * if a requested maximum version was given, it must be greater than (or equal
  701. to, depending on whether the maximum version is specified as inclusive or
  702. exclusive) the package's ``version``.
  703. .. note::
  704. This implementation of range matching was chosen in order to most closely
  705. match the behavior of :command:`write_basic_package_version_file`, albeit
  706. without the case where an overly broad range matches nothing.
  707. For packages using the ``simple`` version schema, if the version is acceptable,
  708. the following variables are set:
  709. ``<PackageName>_VERSION``
  710. Full provided version string
  711. ``<PackageName>_VERSION_MAJOR``
  712. Major version if provided, else 0
  713. ``<PackageName>_VERSION_MINOR``
  714. Minor version if provided, else 0
  715. ``<PackageName>_VERSION_PATCH``
  716. Patch version if provided, else 0
  717. ``<PackageName>_VERSION_TWEAK``
  718. Tweak version if provided, else 0
  719. ``<PackageName>_VERSION_COUNT``
  720. Number of version components, non-negative
  721. Package File Interface Variables
  722. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  723. When loading a find module or CMake-script package configuration file,
  724. ``find_package`` defines variables to provide information about the call
  725. arguments (and restores their original state before returning):
  726. ``CMAKE_FIND_PACKAGE_NAME``
  727. The ``<PackageName>`` which is searched for
  728. ``<PackageName>_FIND_REQUIRED``
  729. True if ``REQUIRED`` option was given
  730. ``<PackageName>_FIND_QUIETLY``
  731. True if ``QUIET`` option was given
  732. ``<PackageName>_FIND_REGISTRY_VIEW``
  733. The requested view if ``REGISTRY_VIEW`` option was given
  734. ``<PackageName>_FIND_VERSION``
  735. Full requested version string
  736. ``<PackageName>_FIND_VERSION_MAJOR``
  737. Major version if requested, else 0
  738. ``<PackageName>_FIND_VERSION_MINOR``
  739. Minor version if requested, else 0
  740. ``<PackageName>_FIND_VERSION_PATCH``
  741. Patch version if requested, else 0
  742. ``<PackageName>_FIND_VERSION_TWEAK``
  743. Tweak version if requested, else 0
  744. ``<PackageName>_FIND_VERSION_COUNT``
  745. Number of version components, 0 to 4
  746. ``<PackageName>_FIND_VERSION_EXACT``
  747. True if ``EXACT`` option was given
  748. ``<PackageName>_FIND_COMPONENTS``
  749. List of specified components (required and optional)
  750. ``<PackageName>_FIND_REQUIRED_<c>``
  751. True if component ``<c>`` is required,
  752. false if component ``<c>`` is optional
  753. When a version range is specified, the above version variables will hold
  754. values based on the lower end of the version range. This is to preserve
  755. compatibility with packages that have not been implemented to expect version
  756. ranges. In addition, the version range will be described by the following
  757. variables:
  758. ``<PackageName>_FIND_VERSION_RANGE``
  759. Full requested version range string
  760. ``<PackageName>_FIND_VERSION_RANGE_MIN``
  761. This specifies whether the lower end point of the version range is
  762. included or excluded. Currently, ``INCLUDE`` is the only supported value.
  763. ``<PackageName>_FIND_VERSION_RANGE_MAX``
  764. This specifies whether the upper end point of the version range is
  765. included or excluded. The possible values for this variable are
  766. ``INCLUDE`` or ``EXCLUDE``.
  767. ``<PackageName>_FIND_VERSION_MIN``
  768. Full requested version string of the lower end point of the range
  769. ``<PackageName>_FIND_VERSION_MIN_MAJOR``
  770. Major version of the lower end point if requested, else 0
  771. ``<PackageName>_FIND_VERSION_MIN_MINOR``
  772. Minor version of the lower end point if requested, else 0
  773. ``<PackageName>_FIND_VERSION_MIN_PATCH``
  774. Patch version of the lower end point if requested, else 0
  775. ``<PackageName>_FIND_VERSION_MIN_TWEAK``
  776. Tweak version of the lower end point if requested, else 0
  777. ``<PackageName>_FIND_VERSION_MIN_COUNT``
  778. Number of version components of the lower end point, 0 to 4
  779. ``<PackageName>_FIND_VERSION_MAX``
  780. Full requested version string of the upper end point of the range
  781. ``<PackageName>_FIND_VERSION_MAX_MAJOR``
  782. Major version of the upper end point if requested, else 0
  783. ``<PackageName>_FIND_VERSION_MAX_MINOR``
  784. Minor version of the upper end point if requested, else 0
  785. ``<PackageName>_FIND_VERSION_MAX_PATCH``
  786. Patch version of the upper end point if requested, else 0
  787. ``<PackageName>_FIND_VERSION_MAX_TWEAK``
  788. Tweak version of the upper end point if requested, else 0
  789. ``<PackageName>_FIND_VERSION_MAX_COUNT``
  790. Number of version components of the upper end point, 0 to 4
  791. Regardless of whether a single version or a version range is specified, the
  792. variable ``<PackageName>_FIND_VERSION_COMPLETE`` will be defined and will hold
  793. the full requested version string as specified.
  794. In Module mode the loaded find module is responsible to honor the
  795. request detailed by these variables; see the find module for details.
  796. In Config mode ``find_package`` handles ``REQUIRED``, ``QUIET``, and
  797. ``[version]`` options automatically but leaves it to the package
  798. configuration file to handle components in a way that makes sense
  799. for the package. The package configuration file may set
  800. ``<PackageName>_FOUND`` to false to tell ``find_package`` that component
  801. requirements are not satisfied.
  802. .. _CPS: https://cps-org.github.io/cps/
  803. .. |CPS| replace:: Common Package Specification
  804. .. _cps-compat_version: https://cps-org.github.io/cps/schema.html#compat-version
  805. .. |cps-compat_version| replace:: ``compat_version``
  806. .. _cps-version_schema: https://cps-org.github.io/cps/schema.html#version-schema
  807. .. |cps-version_schema| replace:: ``version_schema``
  808. CPS Transitive Requirements
  809. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  810. A |CPS| package description consists of one or more components which may in
  811. turn depend on other components either internal or external to the package.
  812. When external components are required, the providing package is noted as
  813. a package-level requirement of the package. Additionally, the set of required
  814. components is typically noted in said external package requirement.
  815. Where a CMake-script package description would use the
  816. :command:`find_dependency` command to handle transitive dependencies, CMake
  817. handles transitive dependencies for CPS itself using an internally nested
  818. ``find_package`` call. This call can resolve CPS package dependencies via
  819. *either* another CPS package, or via a CMake-script package. The manner in
  820. which the CPS component dependencies are handled is subject to some caveats.
  821. When the candidate for resolving a transitive dependency is another CPS
  822. package, things are simple; ``COMPONENTS`` and CPS "components" are directly
  823. comparable (and are effectively synonymous with CMake "imported targets").
  824. CMake-script packages, however, are encouraged to (and often do) check that
  825. required components were found, whether or not the package describes separate
  826. components. Additionally, even those that do describe components typically do
  827. not have the same correlation to imported targets that is normal for CPS. As
  828. a result, passing the set of required components declared by a CPS package to
  829. ``COMPONENTS`` would result in spurious failures to resolve dependencies.
  830. To address this, if a candidate for resolving a CPS transitive dependency is a
  831. CMake-script package, CMake passes the required components as declared by the
  832. consuming CPS package as ``OPTIONAL_COMPONENTS`` and performs a separate,
  833. internal check that the candidate package supplied the required imported
  834. targets. Those targets must be named ``<PackageName>::<ComponentName>``, in
  835. conformance with CPS convention, or the check will consider the package not
  836. found.