FIND_XXX.rst 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. A short-hand signature is:
  2. .. parsed-literal::
  3. |FIND_XXX| (<VAR> name1 [path1 path2 ...])
  4. The general signature is:
  5. .. parsed-literal::
  6. |FIND_XXX| (
  7. <VAR>
  8. name | |NAMES|
  9. [HINTS [path | ENV var]...]
  10. [PATHS [path | ENV var]...]
  11. [REGISTRY_VIEW (64|32|64_32|32_64|HOST|TARGET|BOTH)]
  12. [PATH_SUFFIXES suffix1 [suffix2 ...]]
  13. [VALIDATOR function]
  14. [DOC "cache documentation string"]
  15. [NO_CACHE]
  16. [REQUIRED|OPTIONAL]
  17. [NO_DEFAULT_PATH]
  18. [NO_PACKAGE_ROOT_PATH]
  19. [NO_CMAKE_PATH]
  20. [NO_CMAKE_ENVIRONMENT_PATH]
  21. [NO_SYSTEM_ENVIRONMENT_PATH]
  22. [NO_CMAKE_SYSTEM_PATH]
  23. [NO_CMAKE_INSTALL_PREFIX]
  24. [CMAKE_FIND_ROOT_PATH_BOTH |
  25. ONLY_CMAKE_FIND_ROOT_PATH |
  26. NO_CMAKE_FIND_ROOT_PATH]
  27. )
  28. This command is used to find a |SEARCH_XXX_DESC|.
  29. A cache entry, or a normal variable if ``NO_CACHE`` is specified,
  30. named by ``<VAR>`` is created to store the result of this command.
  31. If the |SEARCH_XXX| is found the result is stored in the variable
  32. and the search will not be repeated unless the variable is cleared.
  33. If nothing is found, the result will be ``<VAR>-NOTFOUND``.
  34. Options include:
  35. ``NAMES``
  36. Specify one or more possible names for the |SEARCH_XXX|.
  37. When using this to specify names with and without a version
  38. suffix, we recommend specifying the unversioned name first
  39. so that locally-built packages can be found before those
  40. provided by distributions.
  41. ``HINTS``, ``PATHS``
  42. Specify directories to search in addition to the default locations.
  43. The ``ENV var`` sub-option reads paths from a system environment
  44. variable.
  45. .. versionchanged:: 3.24
  46. On ``Windows`` platform, it is possible to include registry queries as part
  47. of the directories, using a :ref:`dedicated syntax <Find Using Windows Registry>`.
  48. Such specifications will be ignored on all other platforms.
  49. ``REGISTRY_VIEW``
  50. .. versionadded:: 3.24
  51. .. include:: include/FIND_XXX_REGISTRY_VIEW.rst
  52. ``PATH_SUFFIXES``
  53. Specify additional subdirectories to check below each directory
  54. location otherwise considered.
  55. ``VALIDATOR``
  56. .. versionadded:: 3.25
  57. Specify a :command:`function` to be called for each candidate item found
  58. (a :command:`macro` cannot be provided, that will result in an error).
  59. Two arguments will be passed to the validator function: the name of a
  60. result variable, and the absolute path to the candidate item. The item
  61. will be accepted and the search will end unless the function sets the
  62. value in the result variable to false in the calling scope. The result
  63. variable will hold a true value when the validator function is entered.
  64. .. parsed-literal::
  65. function(my_check validator_result_var item)
  66. if(NOT item MATCHES ...)
  67. set(${validator_result_var} FALSE PARENT_SCOPE)
  68. endif()
  69. endfunction()
  70. |FIND_XXX| (result NAMES ... VALIDATOR my_check)
  71. Note that if a cached result is used, the search is skipped and any
  72. ``VALIDATOR`` is ignored. The cached result is not required to pass the
  73. validation function.
  74. ``DOC``
  75. Specify the documentation string for the ``<VAR>`` cache entry.
  76. ``NO_CACHE``
  77. .. versionadded:: 3.21
  78. The result of the search will be stored in a normal variable rather than
  79. a cache entry.
  80. .. note::
  81. If the variable is already set before the call (as a normal or cache
  82. variable) then the search will not occur.
  83. .. warning::
  84. This option should be used with caution because it can greatly increase
  85. the cost of repeated configure steps.
  86. ``REQUIRED``
  87. .. versionadded:: 3.18
  88. Stop processing with an error message if nothing is found, otherwise
  89. the search will be attempted again the next time |FIND_XXX| is invoked
  90. with the same variable.
  91. .. versionadded:: 4.1
  92. Every |FIND_XXX| command will be treated as ``REQUIRED`` when the
  93. :variable:`CMAKE_FIND_REQUIRED` variable is enabled.
  94. ``OPTIONAL``
  95. .. versionadded:: 4.1
  96. Ignore the value of :variable:`CMAKE_FIND_REQUIRED` and
  97. continue without an error message if nothing is found.
  98. Incompatible with ``REQUIRED``.
  99. If ``NO_DEFAULT_PATH`` is specified, then no additional paths are
  100. added to the search.
  101. If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows:
  102. .. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR| replace::
  103. |prefix_XXX_SUBDIR| for each ``<prefix>`` in the
  104. :variable:`<PackageName>_ROOT` CMake variable and the
  105. :envvar:`<PackageName>_ROOT` environment variable if
  106. called from within a find module loaded by
  107. :command:`find_package(<PackageName>)`
  108. .. |CMAKE_PREFIX_PATH_XXX_SUBDIR| replace::
  109. |prefix_XXX_SUBDIR| for each ``<prefix>`` in :variable:`CMAKE_PREFIX_PATH`
  110. .. |ENV_CMAKE_PREFIX_PATH_XXX_SUBDIR| replace::
  111. |prefix_XXX_SUBDIR| for each ``<prefix>`` in :envvar:`CMAKE_PREFIX_PATH`
  112. .. |SYSTEM_ENVIRONMENT_PREFIX_PATH_XXX_SUBDIR| replace::
  113. |prefix_XXX_SUBDIR| for each ``<prefix>/[s]bin`` in ``PATH``, and
  114. |entry_XXX_SUBDIR| for other entries in ``PATH``
  115. .. |CMAKE_SYSTEM_PREFIX_PATH_XXX_SUBDIR| replace::
  116. |prefix_XXX_SUBDIR| for each ``<prefix>`` in
  117. :variable:`CMAKE_SYSTEM_PREFIX_PATH`
  118. 1. If called from within a find module or any other script loaded by a call to
  119. :command:`find_package(<PackageName>)`, search prefixes unique to the
  120. current package being found. See policy :policy:`CMP0074`.
  121. .. versionadded:: 3.12
  122. Specifically, search paths specified by the following variables, in order:
  123. a. :variable:`<PackageName>_ROOT` CMake variable,
  124. where ``<PackageName>`` is the case-preserved package name.
  125. b. :variable:`<PACKAGENAME>_ROOT` CMake variable,
  126. where ``<PACKAGENAME>`` is the upper-cased package name.
  127. See policy :policy:`CMP0144`.
  128. .. versionadded:: 3.27
  129. c. :envvar:`<PackageName>_ROOT` environment variable,
  130. where ``<PackageName>`` is the case-preserved package name.
  131. d. :envvar:`<PACKAGENAME>_ROOT` environment variable,
  132. where ``<PACKAGENAME>`` is the upper-cased package name.
  133. See policy :policy:`CMP0144`.
  134. .. versionadded:: 3.27
  135. The package root variables are maintained as a stack, so if called from
  136. nested find modules or config packages, root paths from the parent's find
  137. module or config package will be searched after paths from the current
  138. module or package. In other words, the search order would be
  139. ``<CurrentPackage>_ROOT``, ``ENV{<CurrentPackage>_ROOT}``,
  140. ``<ParentPackage>_ROOT``, ``ENV{<ParentPackage>_ROOT}``, etc.
  141. This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed or by setting
  142. the :variable:`CMAKE_FIND_USE_PACKAGE_ROOT_PATH` to ``FALSE``.
  143. * |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX|
  144. 2. Search paths specified in cmake-specific cache variables.
  145. These are intended to be used on the command line with a ``-DVAR=value``.
  146. The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
  147. This can be skipped if ``NO_CMAKE_PATH`` is passed or by setting the
  148. :variable:`CMAKE_FIND_USE_CMAKE_PATH` to ``FALSE``.
  149. * |CMAKE_PREFIX_PATH_XXX|
  150. * |CMAKE_XXX_PATH|
  151. * |CMAKE_XXX_MAC_PATH|
  152. 3. Search paths specified in cmake-specific environment variables.
  153. These are intended to be set in the user's shell configuration,
  154. and therefore use the host's native path separator
  155. (``;`` on Windows and ``:`` on UNIX).
  156. This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed or
  157. by setting the :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` to ``FALSE``.
  158. * |ENV_CMAKE_PREFIX_PATH_XXX|
  159. * |ENV_CMAKE_XXX_PATH|
  160. * |ENV_CMAKE_XXX_MAC_PATH|
  161. 4. Search the paths specified by the ``HINTS`` option.
  162. These should be paths computed by system introspection, such as a
  163. hint provided by the location of another item already found.
  164. Hard-coded guesses should be specified with the ``PATHS`` option.
  165. 5. Search the standard system environment variables.
  166. This can be skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed or by
  167. setting the :variable:`CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH` to ``FALSE``.
  168. * |SYSTEM_ENVIRONMENT_PATH_XXX|
  169. |SYSTEM_ENVIRONMENT_PATH_WINDOWS_XXX|
  170. 6. Search cmake variables defined in the Platform files
  171. for the current system. The searching of ``CMAKE_INSTALL_PREFIX`` and
  172. ``CMAKE_STAGING_PREFIX`` can be
  173. skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the
  174. :variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations
  175. can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the
  176. :variable:`CMAKE_FIND_USE_CMAKE_SYSTEM_PATH` to ``FALSE``.
  177. * |CMAKE_SYSTEM_PREFIX_PATH_XXX|
  178. * |CMAKE_SYSTEM_XXX_PATH|
  179. * |CMAKE_SYSTEM_XXX_MAC_PATH|
  180. The platform paths that these variables contain are locations that
  181. typically include installed software. An example being ``/usr/local`` for
  182. UNIX based platforms.
  183. 7. Search the paths specified by the PATHS option
  184. or in the short-hand version of the command.
  185. These are typically hard-coded guesses.
  186. The :variable:`CMAKE_IGNORE_PATH`, :variable:`CMAKE_IGNORE_PREFIX_PATH`,
  187. :variable:`CMAKE_SYSTEM_IGNORE_PATH` and
  188. :variable:`CMAKE_SYSTEM_IGNORE_PREFIX_PATH` variables can also cause some
  189. of the above locations to be ignored.
  190. .. versionadded:: 3.16
  191. Added ``CMAKE_FIND_USE_<CATEGORY>_PATH`` variables to globally disable
  192. various search locations.
  193. .. |FIND_ARGS_XXX| replace:: <VAR> NAMES name
  194. On macOS the :variable:`CMAKE_FIND_FRAMEWORK` and
  195. :variable:`CMAKE_FIND_APPBUNDLE` variables determine the order of
  196. preference between Apple-style and unix-style package components.
  197. .. include:: include/FIND_XXX_ROOT.rst
  198. .. include:: include/FIND_XXX_ORDER.rst