find_package.rst 28 KB

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