FindPkgConfig.cmake 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[========================================[.rst:
  4. FindPkgConfig
  5. -------------
  6. A ``pkg-config`` module for CMake.
  7. Finds the ``pkg-config`` executable and adds the :command:`pkg_get_variable`,
  8. :command:`pkg_check_modules` and :command:`pkg_search_module` commands. The
  9. following variables will also be set:
  10. ``PKG_CONFIG_FOUND``
  11. True if a pkg-config executable was found.
  12. ``PKG_CONFIG_VERSION_STRING``
  13. .. versionadded:: 2.8.8
  14. The version of pkg-config that was found.
  15. ``PKG_CONFIG_EXECUTABLE``
  16. The pathname of the pkg-config program.
  17. ``PKG_CONFIG_ARGN``
  18. .. versionadded:: 3.22
  19. A list of arguments to pass to pkg-config.
  20. Both ``PKG_CONFIG_EXECUTABLE`` and ``PKG_CONFIG_ARGN`` are initialized by the
  21. module, but may be overridden by the user. See `Variables Affecting Behavior`_
  22. for how these variables are initialized.
  23. #]========================================]
  24. cmake_policy(PUSH)
  25. cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
  26. cmake_policy(SET CMP0057 NEW) # if IN_LIST
  27. ### Common stuff ####
  28. set(PKG_CONFIG_VERSION 1)
  29. # find pkg-config, use PKG_CONFIG if set
  30. if((NOT PKG_CONFIG_EXECUTABLE) AND (NOT "$ENV{PKG_CONFIG}" STREQUAL ""))
  31. separate_arguments(PKG_CONFIG_FROM_ENV_SPLIT NATIVE_COMMAND PROGRAM SEPARATE_ARGS "$ENV{PKG_CONFIG}")
  32. list(LENGTH PKG_CONFIG_FROM_ENV_SPLIT PKG_CONFIG_FROM_ENV_SPLIT_ARGC)
  33. if(PKG_CONFIG_FROM_ENV_SPLIT_ARGC GREATER 0)
  34. list(GET PKG_CONFIG_FROM_ENV_SPLIT 0 PKG_CONFIG_FROM_ENV_ARGV0)
  35. if(PKG_CONFIG_FROM_ENV_SPLIT_ARGC GREATER 1)
  36. list(SUBLIST PKG_CONFIG_FROM_ENV_SPLIT 1 -1 PKG_CONFIG_ARGN)
  37. endif()
  38. set(PKG_CONFIG_EXECUTABLE "${PKG_CONFIG_FROM_ENV_ARGV0}" CACHE FILEPATH "pkg-config executable")
  39. endif()
  40. endif()
  41. set(PKG_CONFIG_NAMES "pkg-config")
  42. if(CMAKE_HOST_WIN32)
  43. list(PREPEND PKG_CONFIG_NAMES "pkg-config.bat")
  44. endif()
  45. list(APPEND PKG_CONFIG_NAMES "pkgconf")
  46. find_program(PKG_CONFIG_EXECUTABLE
  47. NAMES ${PKG_CONFIG_NAMES}
  48. NAMES_PER_DIR
  49. DOC "pkg-config executable")
  50. mark_as_advanced(PKG_CONFIG_EXECUTABLE)
  51. set(PKG_CONFIG_ARGN "${PKG_CONFIG_ARGN}" CACHE STRING "Arguments to supply to pkg-config")
  52. mark_as_advanced(PKG_CONFIG_ARGN)
  53. set(_PKG_CONFIG_FAILURE_MESSAGE "")
  54. if (PKG_CONFIG_EXECUTABLE)
  55. execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} ${PKG_CONFIG_ARGN} --version
  56. OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE
  57. ERROR_VARIABLE _PKG_CONFIG_VERSION_ERROR ERROR_STRIP_TRAILING_WHITESPACE
  58. RESULT_VARIABLE _PKG_CONFIG_VERSION_RESULT
  59. )
  60. if (NOT _PKG_CONFIG_VERSION_RESULT EQUAL 0)
  61. string(REPLACE "\n" "\n " _PKG_CONFIG_VERSION_ERROR " ${_PKG_CONFIG_VERSION_ERROR}")
  62. if(PKG_CONFIG_ARGN)
  63. string(REPLACE ";" " " PKG_CONFIG_ARGN " ${PKG_CONFIG_ARGN}")
  64. endif()
  65. string(APPEND _PKG_CONFIG_FAILURE_MESSAGE
  66. "The command\n"
  67. " \"${PKG_CONFIG_EXECUTABLE}\"${PKG_CONFIG_ARGN} --version\n"
  68. " failed with output:\n${PKG_CONFIG_VERSION_STRING}\n"
  69. " stderr: \n${_PKG_CONFIG_VERSION_ERROR}\n"
  70. " result: \n${_PKG_CONFIG_VERSION_RESULT}"
  71. )
  72. set(PKG_CONFIG_EXECUTABLE "")
  73. set(PKG_CONFIG_ARGN "")
  74. unset(PKG_CONFIG_VERSION_STRING)
  75. endif ()
  76. unset(_PKG_CONFIG_VERSION_RESULT)
  77. endif ()
  78. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  79. find_package_handle_standard_args(PkgConfig
  80. REQUIRED_VARS PKG_CONFIG_EXECUTABLE
  81. REASON_FAILURE_MESSAGE "${_PKG_CONFIG_FAILURE_MESSAGE}"
  82. VERSION_VAR PKG_CONFIG_VERSION_STRING)
  83. # This is needed because the module name is "PkgConfig" but the name of
  84. # this variable has always been PKG_CONFIG_FOUND so this isn't automatically
  85. # handled by FPHSA.
  86. set(PKG_CONFIG_FOUND "${PKGCONFIG_FOUND}")
  87. # Unsets the given variables
  88. macro(_pkgconfig_unset var)
  89. # Clear normal variable (possibly set by project code).
  90. unset(${var})
  91. # Store as cache variable.
  92. # FIXME: Add a policy to switch to a normal variable.
  93. set(${var} "" CACHE INTERNAL "")
  94. endmacro()
  95. macro(_pkgconfig_set var value)
  96. # Clear normal variable (possibly set by project code).
  97. unset(${var})
  98. # Store as cache variable.
  99. # FIXME: Add a policy to switch to a normal variable.
  100. set(${var} ${value} CACHE INTERNAL "")
  101. endmacro()
  102. # Invokes pkgconfig, cleans up the result and sets variables
  103. macro(_pkgconfig_invoke _pkglist _prefix _varname _regexp)
  104. set(_pkgconfig_invoke_result)
  105. execute_process(
  106. COMMAND ${PKG_CONFIG_EXECUTABLE} ${PKG_CONFIG_ARGN} ${ARGN} ${_pkglist}
  107. OUTPUT_VARIABLE _pkgconfig_invoke_result
  108. RESULT_VARIABLE _pkgconfig_failed
  109. OUTPUT_STRIP_TRAILING_WHITESPACE)
  110. if (_pkgconfig_failed)
  111. set(_pkgconfig_${_varname} "")
  112. _pkgconfig_unset(${_prefix}_${_varname})
  113. else()
  114. string(REGEX REPLACE "[\r\n]" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}")
  115. if (NOT ${_regexp} STREQUAL "")
  116. string(REGEX REPLACE "${_regexp}" " " _pkgconfig_invoke_result "${_pkgconfig_invoke_result}")
  117. endif()
  118. # pkg-config can represent "spaces within an argument" by backslash-escaping the space.
  119. # UNIX_COMMAND mode treats backslash-escaped spaces as "not a space that delimits arguments".
  120. separate_arguments(_pkgconfig_invoke_result UNIX_COMMAND "${_pkgconfig_invoke_result}")
  121. #message(STATUS " ${_varname} ... ${_pkgconfig_invoke_result}")
  122. set(_pkgconfig_${_varname} ${_pkgconfig_invoke_result})
  123. _pkgconfig_set(${_prefix}_${_varname} "${_pkgconfig_invoke_result}")
  124. endif()
  125. endmacro()
  126. # Internal version of pkg_get_variable; expects PKG_CONFIG_PATH to already be set
  127. function (_pkg_get_variable result pkg variable)
  128. _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}")
  129. set("${result}"
  130. "${prefix_result}"
  131. PARENT_SCOPE)
  132. endfunction ()
  133. # Invokes pkgconfig two times; once without '--static' and once with
  134. # '--static'
  135. macro(_pkgconfig_invoke_dyn _pkglist _prefix _varname cleanup_regexp)
  136. _pkgconfig_invoke("${_pkglist}" ${_prefix} ${_varname} "${cleanup_regexp}" ${ARGN})
  137. _pkgconfig_invoke("${_pkglist}" ${_prefix} STATIC_${_varname} "${cleanup_regexp}" --static ${ARGN})
  138. endmacro()
  139. # Splits given arguments into options and a package list
  140. macro(_pkgconfig_parse_options _result _is_req _is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global)
  141. set(${_is_req} 0)
  142. set(${_is_silent} 0)
  143. set(${_no_cmake_path} 0)
  144. set(${_no_cmake_environment_path} 0)
  145. set(${_imp_target} 0)
  146. set(${_imp_target_global} 0)
  147. if(DEFINED PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
  148. if(NOT PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
  149. set(${_no_cmake_path} 1)
  150. set(${_no_cmake_environment_path} 1)
  151. endif()
  152. elseif(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 3.1)
  153. set(${_no_cmake_path} 1)
  154. set(${_no_cmake_environment_path} 1)
  155. endif()
  156. foreach(_pkg ${ARGN})
  157. if (_pkg STREQUAL "REQUIRED")
  158. set(${_is_req} 1)
  159. endif ()
  160. if (_pkg STREQUAL "QUIET")
  161. set(${_is_silent} 1)
  162. endif ()
  163. if (_pkg STREQUAL "NO_CMAKE_PATH")
  164. set(${_no_cmake_path} 1)
  165. endif()
  166. if (_pkg STREQUAL "NO_CMAKE_ENVIRONMENT_PATH")
  167. set(${_no_cmake_environment_path} 1)
  168. endif()
  169. if (_pkg STREQUAL "IMPORTED_TARGET")
  170. set(${_imp_target} 1)
  171. endif()
  172. if (_pkg STREQUAL "GLOBAL")
  173. set(${_imp_target_global} 1)
  174. endif()
  175. endforeach()
  176. if (${_imp_target_global} AND NOT ${_imp_target})
  177. message(SEND_ERROR "the argument GLOBAL may only be used together with IMPORTED_TARGET")
  178. endif()
  179. set(${_result} ${ARGN})
  180. list(REMOVE_ITEM ${_result} "REQUIRED")
  181. list(REMOVE_ITEM ${_result} "QUIET")
  182. list(REMOVE_ITEM ${_result} "NO_CMAKE_PATH")
  183. list(REMOVE_ITEM ${_result} "NO_CMAKE_ENVIRONMENT_PATH")
  184. list(REMOVE_ITEM ${_result} "IMPORTED_TARGET")
  185. list(REMOVE_ITEM ${_result} "GLOBAL")
  186. endmacro()
  187. # Add the content of a variable or an environment variable to a list of
  188. # paths
  189. # Usage:
  190. # - _pkgconfig_add_extra_path(_extra_paths VAR)
  191. # - _pkgconfig_add_extra_path(_extra_paths ENV VAR)
  192. function(_pkgconfig_add_extra_path _extra_paths_var _var)
  193. set(_is_env 0)
  194. if(ARGC GREATER 2 AND _var STREQUAL "ENV")
  195. set(_var ${ARGV2})
  196. set(_is_env 1)
  197. endif()
  198. if(NOT _is_env)
  199. if(NOT "${${_var}}" STREQUAL "")
  200. list(APPEND ${_extra_paths_var} ${${_var}})
  201. endif()
  202. else()
  203. if(NOT "$ENV{${_var}}" STREQUAL "")
  204. file(TO_CMAKE_PATH "$ENV{${_var}}" _path)
  205. list(APPEND ${_extra_paths_var} ${_path})
  206. unset(_path)
  207. endif()
  208. endif()
  209. set(${_extra_paths_var} ${${_extra_paths_var}} PARENT_SCOPE)
  210. endfunction()
  211. # scan the LDFLAGS returned by pkg-config for library directories and
  212. # libraries, figure out the absolute paths of that libraries in the
  213. # given directories
  214. function(_pkg_find_libs _prefix _no_cmake_path _no_cmake_environment_path)
  215. unset(_libs)
  216. unset(_find_opts)
  217. # set the options that are used as long as the .pc file does not provide a library
  218. # path to look into
  219. if(_no_cmake_path)
  220. list(APPEND _find_opts "NO_CMAKE_PATH")
  221. endif()
  222. if(_no_cmake_environment_path)
  223. list(APPEND _find_opts "NO_CMAKE_ENVIRONMENT_PATH")
  224. endif()
  225. unset(_search_paths)
  226. unset(_next_is_framework)
  227. foreach (flag IN LISTS ${_prefix}_LDFLAGS)
  228. if (_next_is_framework)
  229. list(APPEND _libs "-framework ${flag}")
  230. unset(_next_is_framework)
  231. continue()
  232. endif ()
  233. if (flag MATCHES "^-L(.*)")
  234. list(APPEND _search_paths ${CMAKE_MATCH_1})
  235. continue()
  236. endif()
  237. if (flag MATCHES "^-l(.*)")
  238. set(_pkg_search "${CMAKE_MATCH_1}")
  239. else()
  240. if (flag STREQUAL "-framework")
  241. set(_next_is_framework TRUE)
  242. endif ()
  243. continue()
  244. endif()
  245. if(_search_paths)
  246. # Firstly search in -L paths
  247. find_library(pkgcfg_lib_${_prefix}_${_pkg_search}
  248. NAMES ${_pkg_search}
  249. HINTS ${_search_paths} NO_DEFAULT_PATH)
  250. endif()
  251. find_library(pkgcfg_lib_${_prefix}_${_pkg_search}
  252. NAMES ${_pkg_search}
  253. ${_find_opts})
  254. mark_as_advanced(pkgcfg_lib_${_prefix}_${_pkg_search})
  255. if(pkgcfg_lib_${_prefix}_${_pkg_search})
  256. list(APPEND _libs "${pkgcfg_lib_${_prefix}_${_pkg_search}}")
  257. else()
  258. list(APPEND _libs ${_pkg_search})
  259. endif()
  260. endforeach()
  261. set(${_prefix}_LINK_LIBRARIES "${_libs}" PARENT_SCOPE)
  262. endfunction()
  263. # create an imported target from all the information returned by pkg-config
  264. function(_pkg_create_imp_target _prefix _imp_target_global)
  265. if (NOT TARGET PkgConfig::${_prefix})
  266. if(${_imp_target_global})
  267. set(_global_opt "GLOBAL")
  268. else()
  269. unset(_global_opt)
  270. endif()
  271. add_library(PkgConfig::${_prefix} INTERFACE IMPORTED ${_global_opt})
  272. if(${_prefix}_INCLUDE_DIRS)
  273. set_property(TARGET PkgConfig::${_prefix} PROPERTY
  274. INTERFACE_INCLUDE_DIRECTORIES "${${_prefix}_INCLUDE_DIRS}")
  275. endif()
  276. if(${_prefix}_LINK_LIBRARIES)
  277. set_property(TARGET PkgConfig::${_prefix} PROPERTY
  278. INTERFACE_LINK_LIBRARIES "${${_prefix}_LINK_LIBRARIES}")
  279. endif()
  280. if(${_prefix}_LDFLAGS_OTHER)
  281. set_property(TARGET PkgConfig::${_prefix} PROPERTY
  282. INTERFACE_LINK_OPTIONS "${${_prefix}_LDFLAGS_OTHER}")
  283. endif()
  284. if(${_prefix}_CFLAGS_OTHER)
  285. set_property(TARGET PkgConfig::${_prefix} PROPERTY
  286. INTERFACE_COMPILE_OPTIONS "${${_prefix}_CFLAGS_OTHER}")
  287. endif()
  288. endif()
  289. endfunction()
  290. # recalculate the dynamic output
  291. # this is a macro and not a function so the result of _pkg_find_libs is automatically propagated
  292. macro(_pkg_recalculate _prefix _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global)
  293. _pkg_find_libs(${_prefix} ${_no_cmake_path} ${_no_cmake_environment_path})
  294. if(${_imp_target})
  295. _pkg_create_imp_target(${_prefix} ${_imp_target_global})
  296. endif()
  297. endmacro()
  298. ###
  299. macro(_pkg_set_path_internal)
  300. set(_extra_paths)
  301. if(NOT _no_cmake_path)
  302. _pkgconfig_add_extra_path(_extra_paths CMAKE_PREFIX_PATH)
  303. _pkgconfig_add_extra_path(_extra_paths CMAKE_FRAMEWORK_PATH)
  304. _pkgconfig_add_extra_path(_extra_paths CMAKE_APPBUNDLE_PATH)
  305. endif()
  306. if(NOT _no_cmake_environment_path)
  307. _pkgconfig_add_extra_path(_extra_paths ENV CMAKE_PREFIX_PATH)
  308. _pkgconfig_add_extra_path(_extra_paths ENV CMAKE_FRAMEWORK_PATH)
  309. _pkgconfig_add_extra_path(_extra_paths ENV CMAKE_APPBUNDLE_PATH)
  310. endif()
  311. if(NOT _extra_paths STREQUAL "")
  312. # Save the PKG_CONFIG_PATH environment variable, and add paths
  313. # from the CMAKE_PREFIX_PATH variables
  314. set(_pkgconfig_path_old "$ENV{PKG_CONFIG_PATH}")
  315. set(_pkgconfig_path "${_pkgconfig_path_old}")
  316. if(NOT _pkgconfig_path STREQUAL "")
  317. file(TO_CMAKE_PATH "${_pkgconfig_path}" _pkgconfig_path)
  318. endif()
  319. # Create a list of the possible pkgconfig subfolder (depending on
  320. # the system
  321. set(_lib_dirs)
  322. if(NOT DEFINED CMAKE_SYSTEM_NAME
  323. OR (CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
  324. AND NOT CMAKE_CROSSCOMPILING))
  325. if(EXISTS "/etc/debian_version") # is this a debian system ?
  326. if(CMAKE_LIBRARY_ARCHITECTURE)
  327. list(APPEND _lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig")
  328. endif()
  329. else()
  330. # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
  331. get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
  332. if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
  333. list(APPEND _lib_dirs "lib32/pkgconfig")
  334. endif()
  335. get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
  336. if(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
  337. list(APPEND _lib_dirs "lib64/pkgconfig")
  338. endif()
  339. get_property(uselibx32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS)
  340. if(uselibx32 AND CMAKE_INTERNAL_PLATFORM_ABI STREQUAL "ELF X32")
  341. list(APPEND _lib_dirs "libx32/pkgconfig")
  342. endif()
  343. endif()
  344. endif()
  345. if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT CMAKE_CROSSCOMPILING)
  346. list(APPEND _lib_dirs "libdata/pkgconfig")
  347. endif()
  348. list(APPEND _lib_dirs "lib/pkgconfig")
  349. list(APPEND _lib_dirs "share/pkgconfig")
  350. # Check if directories exist and eventually append them to the
  351. # pkgconfig path list
  352. foreach(_prefix_dir ${_extra_paths})
  353. foreach(_lib_dir ${_lib_dirs})
  354. if(EXISTS "${_prefix_dir}/${_lib_dir}")
  355. list(APPEND _pkgconfig_path "${_prefix_dir}/${_lib_dir}")
  356. list(REMOVE_DUPLICATES _pkgconfig_path)
  357. endif()
  358. endforeach()
  359. endforeach()
  360. # Prepare and set the environment variable
  361. if(NOT _pkgconfig_path STREQUAL "")
  362. # remove empty values from the list
  363. list(REMOVE_ITEM _pkgconfig_path "")
  364. file(TO_NATIVE_PATH "${_pkgconfig_path}" _pkgconfig_path)
  365. if(CMAKE_HOST_UNIX)
  366. string(REPLACE ";" ":" _pkgconfig_path "${_pkgconfig_path}")
  367. string(REPLACE "\\ " " " _pkgconfig_path "${_pkgconfig_path}")
  368. endif()
  369. set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path}")
  370. endif()
  371. # Unset variables
  372. unset(_lib_dirs)
  373. unset(_pkgconfig_path)
  374. endif()
  375. # Tell pkg-config not to strip any -L paths so we can search them all.
  376. if(DEFINED ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS})
  377. set(_pkgconfig_allow_system_libs_old "$ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS}")
  378. else()
  379. unset(_pkgconfig_allow_system_libs_old)
  380. endif()
  381. set(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS} 0)
  382. endmacro()
  383. macro(_pkg_restore_path_internal)
  384. if(NOT _extra_paths STREQUAL "")
  385. # Restore the environment variable
  386. set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path_old}")
  387. endif()
  388. if(DEFINED _pkgconfig_allow_system_libs_old)
  389. set(ENV{PKG_CONFIG_ALLOW_SYSTEM_LIBS} "${_pkgconfig_allow_system_libs_old}")
  390. unset(_pkgconfig_allow_system_libs_old)
  391. endif()
  392. unset(_extra_paths)
  393. unset(_pkgconfig_path_old)
  394. endmacro()
  395. # pkg-config returns frameworks in --libs-only-other
  396. # they need to be in ${_prefix}_LIBRARIES so "-framework a -framework b" does
  397. # not incorrectly be combined to "-framework a b"
  398. function(_pkgconfig_extract_frameworks _prefix)
  399. set(ldflags "${${_prefix}_LDFLAGS_OTHER}")
  400. list(FIND ldflags "-framework" FR_POS)
  401. list(LENGTH ldflags LD_LENGTH)
  402. # reduce length by 1 as we need "-framework" and the next entry
  403. math(EXPR LD_LENGTH "${LD_LENGTH} - 1")
  404. while (FR_POS GREATER -1 AND LD_LENGTH GREATER FR_POS)
  405. list(REMOVE_AT ldflags ${FR_POS})
  406. list(GET ldflags ${FR_POS} HEAD)
  407. list(REMOVE_AT ldflags ${FR_POS})
  408. math(EXPR LD_LENGTH "${LD_LENGTH} - 2")
  409. list(APPEND LIBS "-framework ${HEAD}")
  410. list(FIND ldflags "-framework" FR_POS)
  411. endwhile ()
  412. set(${_prefix}_LIBRARIES ${${_prefix}_LIBRARIES} ${LIBS} PARENT_SCOPE)
  413. set(${_prefix}_LDFLAGS_OTHER "${ldflags}" PARENT_SCOPE)
  414. endfunction()
  415. # pkg-config returns -isystem include directories in --cflags-only-other,
  416. # depending on the version and if there is a space between -isystem and
  417. # the actual path
  418. function(_pkgconfig_extract_isystem _prefix)
  419. set(cflags "${${_prefix}_CFLAGS_OTHER}")
  420. set(outflags "")
  421. set(incdirs "${${_prefix}_INCLUDE_DIRS}")
  422. set(next_is_isystem FALSE)
  423. foreach (THING IN LISTS cflags)
  424. # This may filter "-isystem -isystem". That would not work anyway,
  425. # so let it happen.
  426. if (THING STREQUAL "-isystem")
  427. set(next_is_isystem TRUE)
  428. continue()
  429. endif ()
  430. if (next_is_isystem)
  431. set(next_is_isystem FALSE)
  432. list(APPEND incdirs "${THING}")
  433. elseif (THING MATCHES "^-isystem")
  434. string(SUBSTRING "${THING}" 8 -1 THING)
  435. list(APPEND incdirs "${THING}")
  436. else ()
  437. list(APPEND outflags "${THING}")
  438. endif ()
  439. endforeach ()
  440. set(${_prefix}_CFLAGS_OTHER "${outflags}" PARENT_SCOPE)
  441. set(${_prefix}_INCLUDE_DIRS "${incdirs}" PARENT_SCOPE)
  442. endfunction()
  443. ###
  444. macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global _prefix)
  445. _pkgconfig_unset(${_prefix}_FOUND)
  446. _pkgconfig_unset(${_prefix}_VERSION)
  447. _pkgconfig_unset(${_prefix}_PREFIX)
  448. _pkgconfig_unset(${_prefix}_INCLUDEDIR)
  449. _pkgconfig_unset(${_prefix}_LIBDIR)
  450. _pkgconfig_unset(${_prefix}_MODULE_NAME)
  451. _pkgconfig_unset(${_prefix}_LIBS)
  452. _pkgconfig_unset(${_prefix}_LIBS_L)
  453. _pkgconfig_unset(${_prefix}_LIBS_PATHS)
  454. _pkgconfig_unset(${_prefix}_LIBS_OTHER)
  455. _pkgconfig_unset(${_prefix}_CFLAGS)
  456. _pkgconfig_unset(${_prefix}_CFLAGS_I)
  457. _pkgconfig_unset(${_prefix}_CFLAGS_OTHER)
  458. _pkgconfig_unset(${_prefix}_STATIC_LIBDIR)
  459. _pkgconfig_unset(${_prefix}_STATIC_LIBS)
  460. _pkgconfig_unset(${_prefix}_STATIC_LIBS_L)
  461. _pkgconfig_unset(${_prefix}_STATIC_LIBS_PATHS)
  462. _pkgconfig_unset(${_prefix}_STATIC_LIBS_OTHER)
  463. _pkgconfig_unset(${_prefix}_STATIC_CFLAGS)
  464. _pkgconfig_unset(${_prefix}_STATIC_CFLAGS_I)
  465. _pkgconfig_unset(${_prefix}_STATIC_CFLAGS_OTHER)
  466. # create a better addressable variable of the modules and calculate its size
  467. set(_pkg_check_modules_list ${ARGN})
  468. list(LENGTH _pkg_check_modules_list _pkg_check_modules_cnt)
  469. if(PKG_CONFIG_EXECUTABLE)
  470. # give out status message telling checked module
  471. if (NOT ${_is_silent})
  472. if (_pkg_check_modules_cnt EQUAL 1)
  473. message(STATUS "Checking for module '${_pkg_check_modules_list}'")
  474. else()
  475. message(STATUS "Checking for modules '${_pkg_check_modules_list}'")
  476. endif()
  477. endif()
  478. set(_pkg_check_modules_packages)
  479. set(_pkg_check_modules_failed)
  480. _pkg_set_path_internal()
  481. # iterate through module list and check whether they exist and match the required version
  482. foreach (_pkg_check_modules_pkg ${_pkg_check_modules_list})
  483. set(_pkg_check_modules_exist_query)
  484. # check whether version is given
  485. if (_pkg_check_modules_pkg MATCHES "(.*[^><])(=|[><]=?)(.*)")
  486. set(_pkg_check_modules_pkg_name "${CMAKE_MATCH_1}")
  487. set(_pkg_check_modules_pkg_op "${CMAKE_MATCH_2}")
  488. set(_pkg_check_modules_pkg_ver "${CMAKE_MATCH_3}")
  489. else()
  490. set(_pkg_check_modules_pkg_name "${_pkg_check_modules_pkg}")
  491. set(_pkg_check_modules_pkg_op)
  492. set(_pkg_check_modules_pkg_ver)
  493. endif()
  494. _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_VERSION)
  495. _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_PREFIX)
  496. _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_INCLUDEDIR)
  497. _pkgconfig_unset(${_prefix}_${_pkg_check_modules_pkg_name}_LIBDIR)
  498. list(APPEND _pkg_check_modules_packages "${_pkg_check_modules_pkg_name}")
  499. # create the final query which is of the format:
  500. # * <pkg-name> > <version>
  501. # * <pkg-name> >= <version>
  502. # * <pkg-name> = <version>
  503. # * <pkg-name> <= <version>
  504. # * <pkg-name> < <version>
  505. # * --exists <pkg-name>
  506. list(APPEND _pkg_check_modules_exist_query --print-errors --short-errors)
  507. if (_pkg_check_modules_pkg_op)
  508. list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name} ${_pkg_check_modules_pkg_op} ${_pkg_check_modules_pkg_ver}")
  509. else()
  510. list(APPEND _pkg_check_modules_exist_query --exists)
  511. list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_name}")
  512. endif()
  513. # execute the query
  514. execute_process(
  515. COMMAND ${PKG_CONFIG_EXECUTABLE} ${PKG_CONFIG_ARGN} ${_pkg_check_modules_exist_query}
  516. RESULT_VARIABLE _pkgconfig_retval
  517. ERROR_VARIABLE _pkgconfig_error
  518. ERROR_STRIP_TRAILING_WHITESPACE)
  519. # evaluate result and tell failures
  520. if (_pkgconfig_retval)
  521. if(NOT ${_is_silent})
  522. message(STATUS " ${_pkgconfig_error}")
  523. endif()
  524. set(_pkg_check_modules_failed 1)
  525. endif()
  526. endforeach()
  527. if(_pkg_check_modules_failed)
  528. # fail when requested
  529. if (${_is_required})
  530. message(FATAL_ERROR "A required package was not found")
  531. endif ()
  532. else()
  533. # when we are here, we checked whether requested modules
  534. # exist. Now, go through them and set variables
  535. _pkgconfig_set(${_prefix}_FOUND 1)
  536. list(LENGTH _pkg_check_modules_packages pkg_count)
  537. # iterate through all modules again and set individual variables
  538. foreach (_pkg_check_modules_pkg ${_pkg_check_modules_packages})
  539. # handle case when there is only one package required
  540. if (pkg_count EQUAL 1)
  541. set(_pkg_check_prefix "${_prefix}")
  542. else()
  543. set(_pkg_check_prefix "${_prefix}_${_pkg_check_modules_pkg}")
  544. endif()
  545. _pkgconfig_invoke(${_pkg_check_modules_pkg} "${_pkg_check_prefix}" VERSION "" --modversion )
  546. pkg_get_variable("${_pkg_check_prefix}_PREFIX" ${_pkg_check_modules_pkg} "prefix")
  547. pkg_get_variable("${_pkg_check_prefix}_INCLUDEDIR" ${_pkg_check_modules_pkg} "includedir")
  548. pkg_get_variable("${_pkg_check_prefix}_LIBDIR" ${_pkg_check_modules_pkg} "libdir")
  549. foreach (variable IN ITEMS PREFIX INCLUDEDIR LIBDIR)
  550. _pkgconfig_set("${_pkg_check_prefix}_${variable}" "${${_pkg_check_prefix}_${variable}}")
  551. endforeach ()
  552. _pkgconfig_set("${_pkg_check_prefix}_MODULE_NAME" "${_pkg_check_modules_pkg}")
  553. if (NOT ${_is_silent})
  554. message(STATUS " Found ${_pkg_check_modules_pkg}, version ${_pkgconfig_VERSION}")
  555. endif ()
  556. endforeach()
  557. # set variables which are combined for multiple modules
  558. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARIES "(^| )-l" --libs-only-l )
  559. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LIBRARY_DIRS "(^| )-L" --libs-only-L )
  560. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS "" --libs )
  561. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" LDFLAGS_OTHER "" --libs-only-other )
  562. if (APPLE AND "-framework" IN_LIST ${_prefix}_LDFLAGS_OTHER)
  563. _pkgconfig_extract_frameworks("${_prefix}")
  564. endif()
  565. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" INCLUDE_DIRS "(^| )(-I|-isystem ?)" --cflags-only-I )
  566. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS "" --cflags )
  567. _pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER "" --cflags-only-other )
  568. if (${_prefix}_CFLAGS_OTHER MATCHES "-isystem")
  569. _pkgconfig_extract_isystem("${_prefix}")
  570. endif ()
  571. _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global})
  572. endif()
  573. _pkg_restore_path_internal()
  574. else()
  575. if (${_is_required})
  576. message(SEND_ERROR "pkg-config tool not found")
  577. endif ()
  578. endif()
  579. endmacro()
  580. #[========================================[.rst:
  581. .. command:: pkg_check_modules
  582. Checks for all the given modules, setting a variety of result variables in
  583. the calling scope.
  584. .. code-block:: cmake
  585. pkg_check_modules(<prefix>
  586. [REQUIRED] [QUIET]
  587. [NO_CMAKE_PATH]
  588. [NO_CMAKE_ENVIRONMENT_PATH]
  589. [IMPORTED_TARGET [GLOBAL]]
  590. <moduleSpec> [<moduleSpec>...])
  591. When the ``REQUIRED`` argument is given, the command will fail with an error
  592. if module(s) could not be found.
  593. When the ``QUIET`` argument is given, no status messages will be printed.
  594. .. versionadded:: 3.1
  595. The :variable:`CMAKE_PREFIX_PATH`,
  596. :variable:`CMAKE_FRAMEWORK_PATH`, and :variable:`CMAKE_APPBUNDLE_PATH` cache
  597. and environment variables will be added to the ``pkg-config`` search path.
  598. The ``NO_CMAKE_PATH`` and ``NO_CMAKE_ENVIRONMENT_PATH`` arguments
  599. disable this behavior for the cache variables and environment variables
  600. respectively.
  601. The :variable:`PKG_CONFIG_USE_CMAKE_PREFIX_PATH` variable set to ``FALSE``
  602. disables this behavior globally.
  603. .. This didn't actually work until 3.3.
  604. .. versionadded:: 3.6
  605. The ``IMPORTED_TARGET`` argument will create an imported target named
  606. ``PkgConfig::<prefix>`` that can be passed directly as an argument to
  607. :command:`target_link_libraries`.
  608. .. This didn't actually work until 3.7.
  609. .. versionadded:: 3.13
  610. The ``GLOBAL`` argument will make the
  611. imported target available in global scope.
  612. .. versionadded:: 3.15
  613. Non-library linker options reported by ``pkg-config`` are stored in the
  614. :prop_tgt:`INTERFACE_LINK_OPTIONS` target property.
  615. .. versionchanged:: 3.18
  616. Include directories specified with ``-isystem`` are stored in the
  617. :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property. Previous
  618. versions of CMake left them in the :prop_tgt:`INTERFACE_COMPILE_OPTIONS`
  619. property.
  620. Each ``<moduleSpec>`` can be either a bare module name or it can be a
  621. module name with a version constraint (operators ``=``, ``<``, ``>``,
  622. ``<=`` and ``>=`` are supported). The following are examples for a module
  623. named ``foo`` with various constraints:
  624. - ``foo`` matches any version.
  625. - ``foo<2`` only matches versions before 2.
  626. - ``foo>=3.1`` matches any version from 3.1 or later.
  627. - ``foo=1.2.3`` requires that foo must be exactly version 1.2.3.
  628. The following variables may be set upon return. Two sets of values exist:
  629. One for the common case (``<XXX> = <prefix>``) and another for the
  630. information ``pkg-config`` provides when called with the ``--static``
  631. option (``<XXX> = <prefix>_STATIC``).
  632. ``<XXX>_FOUND``
  633. set to 1 if module(s) exist
  634. ``<XXX>_LIBRARIES``
  635. only the libraries (without the '-l')
  636. ``<XXX>_LINK_LIBRARIES``
  637. the libraries and their absolute paths
  638. ``<XXX>_LIBRARY_DIRS``
  639. the paths of the libraries (without the '-L')
  640. ``<XXX>_LDFLAGS``
  641. all required linker flags
  642. ``<XXX>_LDFLAGS_OTHER``
  643. all other linker flags
  644. ``<XXX>_INCLUDE_DIRS``
  645. the '-I' preprocessor flags (without the '-I')
  646. ``<XXX>_CFLAGS``
  647. all required cflags
  648. ``<XXX>_CFLAGS_OTHER``
  649. the other compiler flags
  650. All but ``<XXX>_FOUND`` may be a :ref:`;-list <CMake Language Lists>` if the
  651. associated variable returned from ``pkg-config`` has multiple values.
  652. .. versionchanged:: 3.18
  653. Include directories specified with ``-isystem`` are stored in the
  654. ``<XXX>_INCLUDE_DIRS`` variable. Previous versions of CMake left them
  655. in ``<XXX>_CFLAGS_OTHER``.
  656. There are some special variables whose prefix depends on the number of
  657. ``<moduleSpec>`` given. When there is only one ``<moduleSpec>``,
  658. ``<YYY>`` will simply be ``<prefix>``, but if two or more ``<moduleSpec>``
  659. items are given, ``<YYY>`` will be ``<prefix>_<moduleName>``.
  660. ``<YYY>_VERSION``
  661. version of the module
  662. ``<YYY>_PREFIX``
  663. prefix directory of the module
  664. ``<YYY>_INCLUDEDIR``
  665. include directory of the module
  666. ``<YYY>_LIBDIR``
  667. lib directory of the module
  668. .. versionchanged:: 3.8
  669. For any given ``<prefix>``, ``pkg_check_modules()`` can be called multiple
  670. times with different parameters. Previous versions of CMake cached and
  671. returned the first successful result.
  672. .. versionchanged:: 3.16
  673. If a full path to the found library can't be determined, but it's still
  674. visible to the linker, pass it through as ``-l<name>``. Previous versions
  675. of CMake failed in this case.
  676. Examples:
  677. .. code-block:: cmake
  678. pkg_check_modules (GLIB2 glib-2.0)
  679. Looks for any version of glib2. If found, the output variable
  680. ``GLIB2_VERSION`` will hold the actual version found.
  681. .. code-block:: cmake
  682. pkg_check_modules (GLIB2 glib-2.0>=2.10)
  683. Looks for at least version 2.10 of glib2. If found, the output variable
  684. ``GLIB2_VERSION`` will hold the actual version found.
  685. .. code-block:: cmake
  686. pkg_check_modules (FOO glib-2.0>=2.10 gtk+-2.0)
  687. Looks for both glib2-2.0 (at least version 2.10) and any version of
  688. gtk2+-2.0. Only if both are found will ``FOO`` be considered found.
  689. The ``FOO_glib-2.0_VERSION`` and ``FOO_gtk+-2.0_VERSION`` variables will be
  690. set to their respective found module versions.
  691. .. code-block:: cmake
  692. pkg_check_modules (XRENDER REQUIRED xrender)
  693. Requires any version of ``xrender``. Example output variables set by a
  694. successful call::
  695. XRENDER_LIBRARIES=Xrender;X11
  696. XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp
  697. #]========================================]
  698. macro(pkg_check_modules _prefix _module0)
  699. _pkgconfig_parse_options(_pkg_modules _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global "${_module0}" ${ARGN})
  700. # check cached value
  701. if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND OR
  702. (NOT "${ARGN}" STREQUAL "" AND NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0};${ARGN}") OR
  703. ( "${ARGN}" STREQUAL "" AND NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0}"))
  704. _pkg_check_modules_internal("${_pkg_is_required}" "${_pkg_is_silent}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global} "${_prefix}" ${_pkg_modules})
  705. _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION})
  706. if (${_prefix}_FOUND)
  707. _pkgconfig_set(__pkg_config_arguments_${_prefix} "${_module0};${ARGN}")
  708. endif()
  709. else()
  710. if (${_prefix}_FOUND)
  711. _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global})
  712. endif()
  713. endif()
  714. endmacro()
  715. #[========================================[.rst:
  716. .. command:: pkg_search_module
  717. The behavior of this command is the same as :command:`pkg_check_modules`,
  718. except that rather than checking for all the specified modules, it searches
  719. for just the first successful match.
  720. .. code-block:: cmake
  721. pkg_search_module(<prefix>
  722. [REQUIRED] [QUIET]
  723. [NO_CMAKE_PATH]
  724. [NO_CMAKE_ENVIRONMENT_PATH]
  725. [IMPORTED_TARGET [GLOBAL]]
  726. <moduleSpec> [<moduleSpec>...])
  727. .. versionadded:: 3.16
  728. If a module is found, the ``<prefix>_MODULE_NAME`` variable will contain the
  729. name of the matching module. This variable can be used if you need to run
  730. :command:`pkg_get_variable`.
  731. Example:
  732. .. code-block:: cmake
  733. pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2)
  734. #]========================================]
  735. macro(pkg_search_module _prefix _module0)
  736. _pkgconfig_parse_options(_pkg_modules_alt _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global "${_module0}" ${ARGN})
  737. # check cached value
  738. if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND)
  739. set(_pkg_modules_found 0)
  740. if (NOT ${_pkg_is_silent})
  741. message(STATUS "Checking for one of the modules '${_pkg_modules_alt}'")
  742. endif ()
  743. # iterate through all modules and stop at the first working one.
  744. foreach(_pkg_alt ${_pkg_modules_alt})
  745. if(NOT _pkg_modules_found)
  746. _pkg_check_modules_internal(0 1 ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global} "${_prefix}" "${_pkg_alt}")
  747. endif()
  748. if (${_prefix}_FOUND)
  749. set(_pkg_modules_found 1)
  750. break()
  751. endif()
  752. endforeach()
  753. if (NOT ${_prefix}_FOUND)
  754. if(${_pkg_is_required})
  755. message(SEND_ERROR "None of the required '${_pkg_modules_alt}' found")
  756. endif()
  757. endif()
  758. _pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION})
  759. elseif (${_prefix}_FOUND)
  760. _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global})
  761. endif()
  762. endmacro()
  763. #[========================================[.rst:
  764. .. command:: pkg_get_variable
  765. .. versionadded:: 3.4
  766. Retrieves the value of a pkg-config variable ``varName`` and stores it in the
  767. result variable ``resultVar`` in the calling scope.
  768. .. code-block:: cmake
  769. pkg_get_variable(<resultVar> <moduleName> <varName>)
  770. If ``pkg-config`` returns multiple values for the specified variable,
  771. ``resultVar`` will contain a :ref:`;-list <CMake Language Lists>`.
  772. For example:
  773. .. code-block:: cmake
  774. pkg_get_variable(GI_GIRDIR gobject-introspection-1.0 girdir)
  775. #]========================================]
  776. function (pkg_get_variable result pkg variable)
  777. _pkg_set_path_internal()
  778. _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}")
  779. set("${result}"
  780. "${prefix_result}"
  781. PARENT_SCOPE)
  782. _pkg_restore_path_internal()
  783. endfunction ()
  784. #[========================================[.rst:
  785. Variables Affecting Behavior
  786. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  787. .. variable:: PKG_CONFIG_EXECUTABLE
  788. This cache variable can be set to the path of the pkg-config executable.
  789. :command:`find_program` is called internally by the module with this
  790. variable.
  791. .. versionadded:: 3.1
  792. The ``PKG_CONFIG`` environment variable can be used as a hint if
  793. ``PKG_CONFIG_EXECUTABLE`` has not yet been set.
  794. .. versionchanged:: 3.22
  795. If the ``PKG_CONFIG`` environment variable is set, only the first
  796. argument is taken from it when using it as a hint.
  797. .. variable:: PKG_CONFIG_ARGN
  798. .. versionadded:: 3.22
  799. This cache variable can be set to a list of arguments to additionally pass
  800. to pkg-config if needed. If not provided, it will be initialized from the
  801. ``PKG_CONFIG`` environment variable, if set. The first argument in that
  802. environment variable is assumed to be the pkg-config program, while all
  803. remaining arguments after that are used to initialize ``PKG_CONFIG_ARGN``.
  804. If no such environment variable is defined, ``PKG_CONFIG_ARGN`` is
  805. initialized to an empty string. The module does not update the variable once
  806. it has been set in the cache.
  807. .. variable:: PKG_CONFIG_USE_CMAKE_PREFIX_PATH
  808. .. versionadded:: 3.1
  809. Specifies whether :command:`pkg_check_modules` and
  810. :command:`pkg_search_module` should add the paths in the
  811. :variable:`CMAKE_PREFIX_PATH`, :variable:`CMAKE_FRAMEWORK_PATH` and
  812. :variable:`CMAKE_APPBUNDLE_PATH` cache and environment variables to the
  813. ``pkg-config`` search path.
  814. If this variable is not set, this behavior is enabled by default if
  815. :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` is 3.1 or later, disabled
  816. otherwise.
  817. #]========================================]
  818. ### Local Variables:
  819. ### mode: cmake
  820. ### End:
  821. cmake_policy(POP)