find_package.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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. Find a package (usually provided by something external to the project),
  11. and load its package-specific details.
  12. Search Modes
  13. ^^^^^^^^^^^^
  14. The command has two very distinct ways of conducting the search:
  15. **Module mode**
  16. In this mode, CMake searches for a file called ``Find<PackageName>.cmake``,
  17. looking first in the locations listed in the :variable:`CMAKE_MODULE_PATH`,
  18. then among the :ref:`Find Modules` provided by the CMake installation.
  19. If the file is found, it is read and processed by CMake. It is responsible
  20. for finding the package, checking the version, and producing any needed
  21. messages. Some Find modules provide limited or no support for versioning;
  22. check the Find module's documentation.
  23. The ``Find<PackageName>.cmake`` file is not typically provided by the
  24. package itself. Rather, it is normally provided by something external to
  25. the package, such as the operating system, CMake itself, or even the project
  26. from which the ``find_package()`` command was called. Being externally
  27. provided, :ref:`Find Modules` tend to be heuristic in nature and are
  28. susceptible to becoming out-of-date. They typically search for certain
  29. libraries, files and other package artifacts.
  30. Module mode is only supported by the
  31. :ref:`basic command signature <Basic Signature>`.
  32. **Config mode**
  33. In this mode, CMake searches for a file called
  34. ``<lowercasePackageName>-config.cmake`` or ``<PackageName>Config.cmake``.
  35. It will also look for ``<lowercasePackageName>-config-version.cmake`` or
  36. ``<PackageName>ConfigVersion.cmake`` if version details were specified
  37. (see :ref:`version selection` for an explanation of how these separate
  38. version files are used).
  39. In config mode, the command can be given a list of names to search for
  40. as package names. The locations where CMake searches for the config and
  41. version files is considerably more complicated than for Module mode
  42. (see :ref:`search procedure`).
  43. The config and version files are typically installed as part of the
  44. package, so they tend to be more reliable than Find modules. They usually
  45. contain direct knowledge of the package contents, so no searching or
  46. heuristics are needed within the config or version files themselves.
  47. Config mode is supported by both the :ref:`basic <Basic Signature>` and
  48. :ref:`full <Full Signature>` command signatures.
  49. The command arguments determine which of the above modes is used. When the
  50. `basic signature`_ is used, the command searches in Module mode first.
  51. If the package is not found, the search falls back to Config mode.
  52. A user may set the :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` variable
  53. to true to reverse the priority and direct CMake to search using Config mode
  54. first before falling back to Module mode. The basic signature can also be
  55. forced to use only Module mode with a ``MODULE`` keyword. If the
  56. `full signature`_ is used, the command only searches in Config mode.
  57. Where possible, user code should generally look for packages using the
  58. `basic signature`_, since that allows the package to be found with either mode.
  59. Project maintainers wishing to provide a config package should understand
  60. the bigger picture, as explained in :ref:`Full Signature` and all subsequent
  61. sections on this page.
  62. .. _`basic signature`:
  63. Basic Signature
  64. ^^^^^^^^^^^^^^^
  65. .. parsed-literal::
  66. find_package(<PackageName> [version] [EXACT] [QUIET] [MODULE]
  67. [REQUIRED] [[COMPONENTS] [components...]]
  68. [OPTIONAL_COMPONENTS components...]
  69. [REGISTRY_VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  70. [NO_POLICY_SCOPE]
  71. [GLOBAL])
  72. The basic signature is supported by both Module and Config modes.
  73. The ``MODULE`` keyword implies that only Module mode can be used to find
  74. the package, with no fallback to Config mode.
  75. Regardless of the mode used, a ``<PackageName>_FOUND`` variable will be
  76. set to indicate whether the package was found. When the package is found,
  77. package-specific information may be provided through other variables and
  78. :ref:`Imported Targets` documented by the package itself. The
  79. ``QUIET`` option disables informational messages, including those indicating
  80. that the package cannot be found if it is not ``REQUIRED``. The ``REQUIRED``
  81. option stops processing with an error message if the package cannot be found.
  82. A package-specific list of required components may be listed after the
  83. ``COMPONENTS`` keyword. If any of these components are not able to be
  84. satisfied, the package overall is considered to be not found. If the
  85. ``REQUIRED`` option is also present, this is treated as a fatal error,
  86. otherwise execution still continues. As a form of shorthand, if the
  87. ``REQUIRED`` option is present, the ``COMPONENTS`` keyword can be omitted
  88. and the required components can be listed directly after ``REQUIRED``.
  89. Additional optional components may be listed after
  90. ``OPTIONAL_COMPONENTS``. If these cannot be satisfied, the package overall
  91. can still be considered found, as long as all required components are
  92. satisfied.
  93. The set of available components and their meaning are defined by the
  94. target package. Formally, it is up to the target package how to
  95. interpret the component information given to it, but it should follow
  96. the expectations stated above. For calls where no components are specified,
  97. there is no single expected behavior and target packages should clearly
  98. define what occurs in such cases. Common arrangements include assuming it
  99. should find all components, no components or some well-defined subset of the
  100. available components.
  101. .. versionadded:: 3.24
  102. The ``REGISTRY_VIEW`` keyword enables to specify which registry views must be
  103. queried. This keyword is only meaningful on ``Windows`` platform and will be
  104. ignored on all other ones. Formally, it is up to the target package how to
  105. interpret the registry view information given to it.
  106. Specifying the ``GLOBAL`` keyword will promote all imported targets to
  107. a global scope in the importing project. Alternatively this functionality
  108. can be enabled by setting the variable
  109. :variable:`CMAKE_FIND_PACKAGE_TARGETS_GLOBAL`
  110. .. _FIND_PACKAGE_VERSION_FORMAT:
  111. The ``[version]`` argument requests a version with which the package found
  112. should be compatible. There are two possible forms in which it may be
  113. specified:
  114. * A single version with the format ``major[.minor[.patch[.tweak]]]``, where
  115. each component is a numeric value.
  116. * A version range with the format ``versionMin...[<]versionMax`` where
  117. ``versionMin`` and ``versionMax`` have the same format and constraints
  118. on components being integers as the single version. By default, both end
  119. points are included. By specifying ``<``, the upper end point will be
  120. excluded. Version ranges are only supported with CMake 3.19 or later.
  121. The ``EXACT`` option requests that the version be matched exactly. This option
  122. is incompatible with the specification of a version range.
  123. If no ``[version]`` and/or component list is given to a recursive invocation
  124. inside a find-module, the corresponding arguments are forwarded
  125. automatically from the outer call (including the ``EXACT`` flag for
  126. ``[version]``). Version support is currently provided only on a
  127. package-by-package basis (see the `Version Selection`_ section below).
  128. When a version range is specified but the package is only designed to expect
  129. a single version, the package will ignore the upper end point of the range and
  130. only take the single version at the lower end of the range into account.
  131. See the :command:`cmake_policy` command documentation for discussion
  132. of the ``NO_POLICY_SCOPE`` option.
  133. .. _`full signature`:
  134. Full Signature
  135. ^^^^^^^^^^^^^^
  136. .. parsed-literal::
  137. find_package(<PackageName> [version] [EXACT] [QUIET]
  138. [REQUIRED] [[COMPONENTS] [components...]]
  139. [OPTIONAL_COMPONENTS components...]
  140. [CONFIG|NO_MODULE]
  141. [NO_POLICY_SCOPE]
  142. [GLOBAL]
  143. [NAMES name1 [name2 ...]]
  144. [CONFIGS config1 [config2 ...]]
  145. [HINTS path1 [path2 ... ]]
  146. [PATHS path1 [path2 ... ]]
  147. [REGISTRY_VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  148. [PATH_SUFFIXES suffix1 [suffix2 ...]]
  149. [NO_DEFAULT_PATH]
  150. [NO_PACKAGE_ROOT_PATH]
  151. [NO_CMAKE_PATH]
  152. [NO_CMAKE_ENVIRONMENT_PATH]
  153. [NO_SYSTEM_ENVIRONMENT_PATH]
  154. [NO_CMAKE_PACKAGE_REGISTRY]
  155. [NO_CMAKE_BUILDS_PATH] # Deprecated; does nothing.
  156. [NO_CMAKE_SYSTEM_PATH]
  157. [NO_CMAKE_INSTALL_PREFIX]
  158. [NO_CMAKE_SYSTEM_PACKAGE_REGISTRY]
  159. [CMAKE_FIND_ROOT_PATH_BOTH |
  160. ONLY_CMAKE_FIND_ROOT_PATH |
  161. NO_CMAKE_FIND_ROOT_PATH])
  162. The ``CONFIG`` option, the synonymous ``NO_MODULE`` option, or the use
  163. of options not specified in the `basic signature`_ all enforce pure Config
  164. mode. In pure Config mode, the command skips Module mode search and
  165. proceeds at once with Config mode search.
  166. Config mode search attempts to locate a configuration file provided by the
  167. package to be found. A cache entry called ``<PackageName>_DIR`` is created to
  168. hold the directory containing the file. By default the command
  169. searches for a package with the name ``<PackageName>``. If the ``NAMES`` option
  170. is given the names following it are used instead of ``<PackageName>``.
  171. The command searches for a file called ``<PackageName>Config.cmake`` or
  172. ``<lowercasePackageName>-config.cmake`` for each name specified.
  173. A replacement set of possible configuration file names may be given
  174. using the ``CONFIGS`` option. The :ref:`search procedure` is specified below.
  175. Once found, any :ref:`version constraint <version selection>` is checked,
  176. and if satisfied, the configuration file is read and processed by CMake.
  177. Since the file is provided by the package it already knows the
  178. location of package contents. The full path to the configuration file
  179. is stored in the cmake variable ``<PackageName>_CONFIG``.
  180. All configuration files which have been considered by CMake while
  181. searching for the package with an appropriate version are stored in the
  182. ``<PackageName>_CONSIDERED_CONFIGS`` variable, and the associated versions
  183. in the ``<PackageName>_CONSIDERED_VERSIONS`` variable.
  184. If the package configuration file cannot be found CMake will generate
  185. an error describing the problem unless the ``QUIET`` argument is
  186. specified. If ``REQUIRED`` is specified and the package is not found a
  187. fatal error is generated and the configure step stops executing. If
  188. ``<PackageName>_DIR`` has been set to a directory not containing a
  189. configuration file CMake will ignore it and search from scratch.
  190. Package maintainers providing CMake package configuration files are
  191. encouraged to name and install them such that the :ref:`search procedure`
  192. outlined below will find them without requiring use of additional options.
  193. .. _`search procedure`:
  194. Config Mode Search Procedure
  195. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  196. .. note::
  197. When Config mode is used, this search procedure is applied regardless of
  198. whether the :ref:`full <full signature>` or :ref:`basic <basic signature>`
  199. signature was given.
  200. CMake constructs a set of possible installation prefixes for the
  201. package. Under each prefix several directories are searched for a
  202. configuration file. The tables below show the directories searched.
  203. Each entry is meant for installation trees following Windows (``W``), UNIX
  204. (``U``), or Apple (``A``) conventions::
  205. <prefix>/ (W)
  206. <prefix>/(cmake|CMake)/ (W)
  207. <prefix>/<name>*/ (W)
  208. <prefix>/<name>*/(cmake|CMake)/ (W)
  209. <prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/ (U)
  210. <prefix>/(lib/<arch>|lib*|share)/<name>*/ (U)
  211. <prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (U)
  212. <prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/ (W/U)
  213. <prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/ (W/U)
  214. <prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (W/U)
  215. On systems supporting macOS :prop_tgt:`FRAMEWORK` and :prop_tgt:`BUNDLE`, the
  216. following directories are searched for Frameworks or Application Bundles
  217. containing a configuration file::
  218. <prefix>/<name>.framework/Resources/ (A)
  219. <prefix>/<name>.framework/Resources/CMake/ (A)
  220. <prefix>/<name>.framework/Versions/*/Resources/ (A)
  221. <prefix>/<name>.framework/Versions/*/Resources/CMake/ (A)
  222. <prefix>/<name>.app/Contents/Resources/ (A)
  223. <prefix>/<name>.app/Contents/Resources/CMake/ (A)
  224. In all cases the ``<name>`` is treated as case-insensitive and corresponds
  225. to any of the names specified (``<PackageName>`` or names given by ``NAMES``).
  226. Paths with ``lib/<arch>`` are enabled if the
  227. :variable:`CMAKE_LIBRARY_ARCHITECTURE` variable is set. ``lib*`` includes one
  228. or more of the values ``lib64``, ``lib32``, ``libx32`` or ``lib`` (searched in
  229. that order).
  230. * Paths with ``lib64`` are searched on 64 bit platforms if the
  231. :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` property is set to ``TRUE``.
  232. * Paths with ``lib32`` are searched on 32 bit platforms if the
  233. :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` property is set to ``TRUE``.
  234. * Paths with ``libx32`` are searched on platforms using the x32 ABI
  235. if the :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS` property is set to ``TRUE``.
  236. * The ``lib`` path is always searched.
  237. .. versionchanged:: 3.24
  238. On ``Windows`` platform, it is possible to include registry queries as part
  239. of the directories specified through ``HINTS`` and ``PATHS`` keywords. Such
  240. specifications will be ignored on all other platforms.
  241. .. include:: FIND_XXX_REGISTRY_QUERY.txt
  242. .. versionadded:: 3.24
  243. ``REGISTRY_VIEW`` can be specified to manage ``Windows`` registry queries
  244. specified as part of ``PATHS`` and ``HINTS``.
  245. .. include:: FIND_XXX_REGISTRY_VIEW.txt
  246. If ``PATH_SUFFIXES`` is specified, the suffixes are appended to each
  247. (``W``) or (``U``) directory entry one-by-one.
  248. This set of directories is intended to work in cooperation with
  249. projects that provide configuration files in their installation trees.
  250. Directories above marked with (``W``) are intended for installations on
  251. Windows where the prefix may point at the top of an application's
  252. installation directory. Those marked with (``U``) are intended for
  253. installations on UNIX platforms where the prefix is shared by multiple
  254. packages. This is merely a convention, so all (``W``) and (``U``) directories
  255. are still searched on all platforms. Directories marked with (``A``) are
  256. intended for installations on Apple platforms. The
  257. :variable:`CMAKE_FIND_FRAMEWORK` and :variable:`CMAKE_FIND_APPBUNDLE`
  258. variables determine the order of preference.
  259. The set of installation prefixes is constructed using the following
  260. steps. If ``NO_DEFAULT_PATH`` is specified all ``NO_*`` options are
  261. enabled.
  262. 1. .. versionadded:: 3.12
  263. Search paths specified in the :variable:`<PackageName>_ROOT` CMake
  264. variable and the :envvar:`<PackageName>_ROOT` environment variable,
  265. where ``<PackageName>`` is the package to be found.
  266. The package root variables are maintained as a stack so if
  267. called from within a find module, root paths from the parent's find
  268. module will also be searched after paths for the current package.
  269. This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed or by setting
  270. the :variable:`CMAKE_FIND_USE_PACKAGE_ROOT_PATH` to ``FALSE``.
  271. See policy :policy:`CMP0074`.
  272. 2. Search paths specified in cmake-specific cache variables. These
  273. are intended to be used on the command line with a ``-DVAR=value``.
  274. The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
  275. This can be skipped if ``NO_CMAKE_PATH`` is passed or by setting the
  276. :variable:`CMAKE_FIND_USE_CMAKE_PATH` to ``FALSE``:
  277. * :variable:`CMAKE_PREFIX_PATH`
  278. * :variable:`CMAKE_FRAMEWORK_PATH`
  279. * :variable:`CMAKE_APPBUNDLE_PATH`
  280. 3. Search paths specified in cmake-specific environment variables.
  281. These are intended to be set in the user's shell configuration,
  282. and therefore use the host's native path separator
  283. (``;`` on Windows and ``:`` on UNIX).
  284. This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed or by setting
  285. the :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` to ``FALSE``:
  286. * ``<PackageName>_DIR``
  287. * :envvar:`CMAKE_PREFIX_PATH`
  288. * ``CMAKE_FRAMEWORK_PATH``
  289. * ``CMAKE_APPBUNDLE_PATH``
  290. 4. Search paths specified by the ``HINTS`` option. These should be paths
  291. computed by system introspection, such as a hint provided by the
  292. location of another item already found. Hard-coded guesses should
  293. be specified with the ``PATHS`` option.
  294. 5. Search the standard system environment variables. This can be
  295. skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed or by setting the
  296. :variable:`CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH` to ``FALSE``. Path entries
  297. ending in ``/bin`` or ``/sbin`` are automatically converted to their
  298. parent directories:
  299. * ``PATH``
  300. 6. Search paths stored in the CMake :ref:`User Package Registry`.
  301. This can be skipped if ``NO_CMAKE_PACKAGE_REGISTRY`` is passed or by
  302. setting the variable :variable:`CMAKE_FIND_USE_PACKAGE_REGISTRY`
  303. to ``FALSE`` or the deprecated variable
  304. :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` to ``TRUE``.
  305. See the :manual:`cmake-packages(7)` manual for details on the user
  306. package registry.
  307. 7. Search cmake variables defined in the Platform files for the
  308. current system. The searching of ``CMAKE_INSTALL_PREFIX` can be skipped
  309. if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the
  310. :variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE. All these locations
  311. can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the
  312. :variable:`CMAKE_FIND_USE_CMAKE_SYSTEM_PATH` to ``FALSE``:
  313. * :variable:`CMAKE_SYSTEM_PREFIX_PATH`
  314. * :variable:`CMAKE_SYSTEM_FRAMEWORK_PATH`
  315. * :variable:`CMAKE_SYSTEM_APPBUNDLE_PATH`
  316. The platform paths that these variables contain are locations that
  317. typically include installed software. An example being ``/usr/local`` for
  318. UNIX based platforms.
  319. 8. Search paths stored in the CMake :ref:`System Package Registry`.
  320. This can be skipped if ``NO_CMAKE_SYSTEM_PACKAGE_REGISTRY`` is passed
  321. or by setting the :variable:`CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY`
  322. variable to ``FALSE`` or the deprecated variable
  323. :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` to ``TRUE``.
  324. See the :manual:`cmake-packages(7)` manual for details on the system
  325. package registry.
  326. 9. Search paths specified by the ``PATHS`` option. These are typically
  327. hard-coded guesses.
  328. The :variable:`CMAKE_IGNORE_PATH`, :variable:`CMAKE_IGNORE_PREFIX_PATH`,
  329. :variable:`CMAKE_SYSTEM_IGNORE_PATH` and
  330. :variable:`CMAKE_SYSTEM_IGNORE_PREFIX_PATH` variables can also cause some
  331. of the above locations to be ignored.
  332. .. versionadded:: 3.16
  333. Added the ``CMAKE_FIND_USE_<CATEGORY>`` variables to globally disable
  334. various search locations.
  335. .. include:: FIND_XXX_ROOT.txt
  336. .. include:: FIND_XXX_ORDER.txt
  337. By default the value stored in the result variable will be the path at
  338. which the file is found. The :variable:`CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS`
  339. variable may be set to ``TRUE`` before calling ``find_package`` in order
  340. to resolve symbolic links and store the real path to the file.
  341. Every non-REQUIRED ``find_package`` call can be disabled or made REQUIRED:
  342. * Setting the :variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable
  343. to ``TRUE`` disables the package.
  344. * Setting the :variable:`CMAKE_REQUIRE_FIND_PACKAGE_<PackageName>` variable
  345. to ``TRUE`` makes the package REQUIRED.
  346. Setting both variables to ``TRUE`` simultaneously is an error.
  347. .. _`version selection`:
  348. Config Mode Version Selection
  349. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  350. .. note::
  351. When Config mode is used, this version selection process is applied
  352. regardless of whether the :ref:`full <full signature>` or
  353. :ref:`basic <basic signature>` signature was given.
  354. When the ``[version]`` argument is given, Config mode will only find a
  355. version of the package that claims compatibility with the requested
  356. version (see :ref:`format specification <FIND_PACKAGE_VERSION_FORMAT>`). If the
  357. ``EXACT`` option is given, only a version of the package claiming an exact match
  358. of the requested version may be found. CMake does not establish any
  359. convention for the meaning of version numbers. Package version
  360. numbers are checked by "version" files provided by the packages
  361. themselves. For a candidate package configuration file
  362. ``<config-file>.cmake`` the corresponding version file is located next
  363. to it and named either ``<config-file>-version.cmake`` or
  364. ``<config-file>Version.cmake``. If no such version file is available
  365. then the configuration file is assumed to not be compatible with any
  366. requested version. A basic version file containing generic version
  367. matching code can be created using the
  368. :module:`CMakePackageConfigHelpers` module. When a version file
  369. is found it is loaded to check the requested version number. The
  370. version file is loaded in a nested scope in which the following
  371. variables have been defined:
  372. ``PACKAGE_FIND_NAME``
  373. The ``<PackageName>``
  374. ``PACKAGE_FIND_VERSION``
  375. Full requested version string
  376. ``PACKAGE_FIND_VERSION_MAJOR``
  377. Major version if requested, else 0
  378. ``PACKAGE_FIND_VERSION_MINOR``
  379. Minor version if requested, else 0
  380. ``PACKAGE_FIND_VERSION_PATCH``
  381. Patch version if requested, else 0
  382. ``PACKAGE_FIND_VERSION_TWEAK``
  383. Tweak version if requested, else 0
  384. ``PACKAGE_FIND_VERSION_COUNT``
  385. Number of version components, 0 to 4
  386. When a version range is specified, the above version variables will hold
  387. values based on the lower end of the version range. This is to preserve
  388. compatibility with packages that have not been implemented to expect version
  389. ranges. In addition, the version range will be described by the following
  390. variables:
  391. ``PACKAGE_FIND_VERSION_RANGE``
  392. Full requested version range string
  393. ``PACKAGE_FIND_VERSION_RANGE_MIN``
  394. This specifies whether the lower end point of the version range should be
  395. included or excluded. Currently, the only supported value for this variable
  396. is ``INCLUDE``.
  397. ``PACKAGE_FIND_VERSION_RANGE_MAX``
  398. This specifies whether the upper end point of the version range should be
  399. included or excluded. The supported values for this variable are
  400. ``INCLUDE`` and ``EXCLUDE``.
  401. ``PACKAGE_FIND_VERSION_MIN``
  402. Full requested version string of the lower end point of the range
  403. ``PACKAGE_FIND_VERSION_MIN_MAJOR``
  404. Major version of the lower end point if requested, else 0
  405. ``PACKAGE_FIND_VERSION_MIN_MINOR``
  406. Minor version of the lower end point if requested, else 0
  407. ``PACKAGE_FIND_VERSION_MIN_PATCH``
  408. Patch version of the lower end point if requested, else 0
  409. ``PACKAGE_FIND_VERSION_MIN_TWEAK``
  410. Tweak version of the lower end point if requested, else 0
  411. ``PACKAGE_FIND_VERSION_MIN_COUNT``
  412. Number of version components of the lower end point, 0 to 4
  413. ``PACKAGE_FIND_VERSION_MAX``
  414. Full requested version string of the upper end point of the range
  415. ``PACKAGE_FIND_VERSION_MAX_MAJOR``
  416. Major version of the upper end point if requested, else 0
  417. ``PACKAGE_FIND_VERSION_MAX_MINOR``
  418. Minor version of the upper end point if requested, else 0
  419. ``PACKAGE_FIND_VERSION_MAX_PATCH``
  420. Patch version of the upper end point if requested, else 0
  421. ``PACKAGE_FIND_VERSION_MAX_TWEAK``
  422. Tweak version of the upper end point if requested, else 0
  423. ``PACKAGE_FIND_VERSION_MAX_COUNT``
  424. Number of version components of the upper end point, 0 to 4
  425. Regardless of whether a single version or a version range is specified, the
  426. variable ``PACKAGE_FIND_VERSION_COMPLETE`` will be defined and will hold
  427. the full requested version string as specified.
  428. The version file checks whether it satisfies the requested version and
  429. sets these variables:
  430. ``PACKAGE_VERSION``
  431. Full provided version string
  432. ``PACKAGE_VERSION_EXACT``
  433. True if version is exact match
  434. ``PACKAGE_VERSION_COMPATIBLE``
  435. True if version is compatible
  436. ``PACKAGE_VERSION_UNSUITABLE``
  437. True if unsuitable as any version
  438. These variables are checked by the ``find_package`` command to determine
  439. whether the configuration file provides an acceptable version. They
  440. are not available after the ``find_package`` call returns. If the version
  441. is acceptable the following variables are set:
  442. ``<PackageName>_VERSION``
  443. Full provided version string
  444. ``<PackageName>_VERSION_MAJOR``
  445. Major version if provided, else 0
  446. ``<PackageName>_VERSION_MINOR``
  447. Minor version if provided, else 0
  448. ``<PackageName>_VERSION_PATCH``
  449. Patch version if provided, else 0
  450. ``<PackageName>_VERSION_TWEAK``
  451. Tweak version if provided, else 0
  452. ``<PackageName>_VERSION_COUNT``
  453. Number of version components, 0 to 4
  454. and the corresponding package configuration file is loaded.
  455. When multiple package configuration files are available whose version files
  456. claim compatibility with the version requested it is unspecified which
  457. one is chosen: unless the variable :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER`
  458. is set no attempt is made to choose a highest or closest version number.
  459. To control the order in which ``find_package`` checks for compatibility use
  460. the two variables :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` and
  461. :variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION`.
  462. For instance in order to select the highest version one can set
  463. .. code-block:: cmake
  464. SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
  465. SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
  466. before calling ``find_package``.
  467. Package File Interface Variables
  468. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  469. When loading a find module or package configuration file ``find_package``
  470. defines variables to provide information about the call arguments (and
  471. restores their original state before returning):
  472. ``CMAKE_FIND_PACKAGE_NAME``
  473. The ``<PackageName>`` which is searched for
  474. ``<PackageName>_FIND_REQUIRED``
  475. True if ``REQUIRED`` option was given
  476. ``<PackageName>_FIND_QUIETLY``
  477. True if ``QUIET`` option was given
  478. ``<PackageName>_FIND_REGISTRY_VIEW``
  479. The requested view if ``REGISTRY_VIEW`` option was given
  480. ``<PackageName>_FIND_VERSION``
  481. Full requested version string
  482. ``<PackageName>_FIND_VERSION_MAJOR``
  483. Major version if requested, else 0
  484. ``<PackageName>_FIND_VERSION_MINOR``
  485. Minor version if requested, else 0
  486. ``<PackageName>_FIND_VERSION_PATCH``
  487. Patch version if requested, else 0
  488. ``<PackageName>_FIND_VERSION_TWEAK``
  489. Tweak version if requested, else 0
  490. ``<PackageName>_FIND_VERSION_COUNT``
  491. Number of version components, 0 to 4
  492. ``<PackageName>_FIND_VERSION_EXACT``
  493. True if ``EXACT`` option was given
  494. ``<PackageName>_FIND_COMPONENTS``
  495. List of specified components (required and optional)
  496. ``<PackageName>_FIND_REQUIRED_<c>``
  497. True if component ``<c>`` is required,
  498. false if component ``<c>`` is optional
  499. When a version range is specified, the above version variables will hold
  500. values based on the lower end of the version range. This is to preserve
  501. compatibility with packages that have not been implemented to expect version
  502. ranges. In addition, the version range will be described by the following
  503. variables:
  504. ``<PackageName>_FIND_VERSION_RANGE``
  505. Full requested version range string
  506. ``<PackageName>_FIND_VERSION_RANGE_MIN``
  507. This specifies whether the lower end point of the version range is
  508. included or excluded. Currently, ``INCLUDE`` is the only supported value.
  509. ``<PackageName>_FIND_VERSION_RANGE_MAX``
  510. This specifies whether the upper end point of the version range is
  511. included or excluded. The possible values for this variable are
  512. ``INCLUDE`` or ``EXCLUDE``.
  513. ``<PackageName>_FIND_VERSION_MIN``
  514. Full requested version string of the lower end point of the range
  515. ``<PackageName>_FIND_VERSION_MIN_MAJOR``
  516. Major version of the lower end point if requested, else 0
  517. ``<PackageName>_FIND_VERSION_MIN_MINOR``
  518. Minor version of the lower end point if requested, else 0
  519. ``<PackageName>_FIND_VERSION_MIN_PATCH``
  520. Patch version of the lower end point if requested, else 0
  521. ``<PackageName>_FIND_VERSION_MIN_TWEAK``
  522. Tweak version of the lower end point if requested, else 0
  523. ``<PackageName>_FIND_VERSION_MIN_COUNT``
  524. Number of version components of the lower end point, 0 to 4
  525. ``<PackageName>_FIND_VERSION_MAX``
  526. Full requested version string of the upper end point of the range
  527. ``<PackageName>_FIND_VERSION_MAX_MAJOR``
  528. Major version of the upper end point if requested, else 0
  529. ``<PackageName>_FIND_VERSION_MAX_MINOR``
  530. Minor version of the upper end point if requested, else 0
  531. ``<PackageName>_FIND_VERSION_MAX_PATCH``
  532. Patch version of the upper end point if requested, else 0
  533. ``<PackageName>_FIND_VERSION_MAX_TWEAK``
  534. Tweak version of the upper end point if requested, else 0
  535. ``<PackageName>_FIND_VERSION_MAX_COUNT``
  536. Number of version components of the upper end point, 0 to 4
  537. Regardless of whether a single version or a version range is specified, the
  538. variable ``<PackageName>_FIND_VERSION_COMPLETE`` will be defined and will hold
  539. the full requested version string as specified.
  540. In Module mode the loaded find module is responsible to honor the
  541. request detailed by these variables; see the find module for details.
  542. In Config mode ``find_package`` handles ``REQUIRED``, ``QUIET``, and
  543. ``[version]`` options automatically but leaves it to the package
  544. configuration file to handle components in a way that makes sense
  545. for the package. The package configuration file may set
  546. ``<PackageName>_FOUND`` to false to tell ``find_package`` that component
  547. requirements are not satisfied.