find_package.rst 28 KB

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