find_program.rst 5.5 KB

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