find_path.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. find_path
  2. ---------
  3. Find the directory containing a file.
  4. ::
  5. find_path(<VAR> name1 [path1 path2 ...])
  6. This is the short-hand signature for the command that is sufficient in
  7. many cases. It is the same as find_path(<VAR> name1 [PATHS path1
  8. path2 ...])
  9. ::
  10. find_path(
  11. <VAR>
  12. name | NAMES name1 [name2 ...]
  13. [HINTS path1 [path2 ... ENV var]]
  14. [PATHS path1 [path2 ... ENV var]]
  15. [PATH_SUFFIXES suffix1 [suffix2 ...]]
  16. [DOC "cache documentation string"]
  17. [NO_DEFAULT_PATH]
  18. [NO_CMAKE_ENVIRONMENT_PATH]
  19. [NO_CMAKE_PATH]
  20. [NO_SYSTEM_ENVIRONMENT_PATH]
  21. [NO_CMAKE_SYSTEM_PATH]
  22. [CMAKE_FIND_ROOT_PATH_BOTH |
  23. ONLY_CMAKE_FIND_ROOT_PATH |
  24. NO_CMAKE_FIND_ROOT_PATH]
  25. )
  26. This command is used to find a directory containing the named file. A
  27. cache entry named by <VAR> is created to store the result of this
  28. command. If the file in a directory is found the result is stored in
  29. the variable and the search will not be repeated unless the variable
  30. is cleared. If nothing is found, the result will be <VAR>-NOTFOUND,
  31. and the search will be attempted again the next time find_path is
  32. invoked with the same variable. The name of the file in a directory
  33. that is searched for is specified by the names listed after the NAMES
  34. argument. Additional search locations can be specified after the
  35. PATHS argument. If ENV var is found in the HINTS or PATHS section the
  36. environment variable var will be read and converted from a system
  37. environment variable to a cmake style list of paths. For example ENV
  38. PATH would be a way to list the system path variable. The argument
  39. after DOC will be used for the documentation string in the cache.
  40. PATH_SUFFIXES specifies additional subdirectories to check below each
  41. search path.
  42. If NO_DEFAULT_PATH is specified, then no additional paths are added to
  43. the search. If NO_DEFAULT_PATH is not specified, the search process
  44. is as follows:
  45. 1. Search paths specified in cmake-specific cache variables. These
  46. are intended to be used on the command line with a -DVAR=value. This
  47. can be skipped if NO_CMAKE_PATH is passed.
  48. ::
  49. <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
  50. <prefix>/include for each <prefix> in CMAKE_PREFIX_PATH
  51. CMAKE_INCLUDE_PATH
  52. CMAKE_FRAMEWORK_PATH
  53. 2. Search paths specified in cmake-specific environment variables.
  54. These are intended to be set in the user's shell configuration. This
  55. can be skipped if NO_CMAKE_ENVIRONMENT_PATH is passed.
  56. ::
  57. <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
  58. <prefix>/include for each <prefix> in CMAKE_PREFIX_PATH
  59. CMAKE_INCLUDE_PATH
  60. CMAKE_FRAMEWORK_PATH
  61. 3. Search the paths specified by the HINTS option. These should be
  62. paths computed by system introspection, such as a hint provided by the
  63. location of another item already found. Hard-coded guesses should be
  64. specified with the PATHS option.
  65. 4. Search the standard system environment variables. This can be
  66. skipped if NO_SYSTEM_ENVIRONMENT_PATH is an argument.
  67. ::
  68. PATH
  69. INCLUDE
  70. 5. Search cmake variables defined in the Platform files for the
  71. current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
  72. passed.
  73. ::
  74. <prefix>/include/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set, and
  75. <prefix>/include for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
  76. CMAKE_SYSTEM_INCLUDE_PATH
  77. CMAKE_SYSTEM_FRAMEWORK_PATH
  78. 6. Search the paths specified by the PATHS option or in the
  79. short-hand version of the command. These are typically hard-coded
  80. guesses.
  81. On Darwin or systems supporting OS X Frameworks, the cmake variable
  82. CMAKE_FIND_FRAMEWORK can be set to empty or one of the following:
  83. ::
  84. "FIRST" - Try to find frameworks before standard
  85. libraries or headers. This is the default on Darwin.
  86. "LAST" - Try to find frameworks after standard
  87. libraries or headers.
  88. "ONLY" - Only try to find frameworks.
  89. "NEVER" - Never try to find frameworks.
  90. On Darwin or systems supporting OS X Application Bundles, the cmake
  91. variable CMAKE_FIND_APPBUNDLE can be set to empty or one of the
  92. following:
  93. ::
  94. "FIRST" - Try to find application bundles before standard
  95. programs. This is the default on Darwin.
  96. "LAST" - Try to find application bundles after standard
  97. programs.
  98. "ONLY" - Only try to find application bundles.
  99. "NEVER" - Never try to find application bundles.
  100. The CMake variable CMAKE_FIND_ROOT_PATH specifies one or more
  101. directories to be prepended to all other search directories. This
  102. effectively "re-roots" the entire search under given locations. By
  103. default it is empty. It is especially useful when cross-compiling to
  104. point to the root directory of the target environment and CMake will
  105. search there too. By default at first the directories listed in
  106. CMAKE_FIND_ROOT_PATH and then the non-rooted directories will be
  107. searched. The default behavior can be adjusted by setting
  108. CMAKE_FIND_ROOT_PATH_MODE_INCLUDE. This behavior can be manually
  109. overridden on a per-call basis. By using CMAKE_FIND_ROOT_PATH_BOTH
  110. the search order will be as described above. If
  111. NO_CMAKE_FIND_ROOT_PATH is used then CMAKE_FIND_ROOT_PATH will not be
  112. used. If ONLY_CMAKE_FIND_ROOT_PATH is used then only the re-rooted
  113. directories will be searched.
  114. The default search order is designed to be most-specific to
  115. least-specific for common use cases. Projects may override the order
  116. by simply calling the command multiple times and using the NO_*
  117. options:
  118. ::
  119. find_path(<VAR> NAMES name PATHS paths... NO_DEFAULT_PATH)
  120. find_path(<VAR> NAMES name)
  121. Once one of the calls succeeds the result variable will be set and
  122. stored in the cache so that no call will search again.
  123. When searching for frameworks, if the file is specified as A/b.h, then
  124. the framework search will look for A.framework/Headers/b.h. If that
  125. is found the path will be set to the path to the framework. CMake
  126. will convert this to the correct -F option to include the file.