FIND_XXX.rst 10 KB

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