cmake_pkg_config.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. cmake_pkg_config
  2. ----------------
  3. .. only:: html
  4. .. contents::
  5. Process pkg-config format package files.
  6. Synopsis
  7. ^^^^^^^^
  8. .. parsed-literal::
  9. cmake_pkg_config(EXTRACT <package> [<version>] [...])
  10. Introduction
  11. ^^^^^^^^^^^^
  12. This command generates CMake variables and targets from pkg-config format
  13. package files natively, without needing to invoke or even require the presence
  14. of a pkg-config implementation. A ``<package>`` is either an absolute path to a
  15. package file, or a package name to be searched for using the typical pkg-config
  16. search patterns. The optional ``<version>`` string has the same format and
  17. semantics as a pkg-config style version specifier, with the exception that if
  18. no comparison operator is specified ``=`` is assumed.
  19. .. _`common options`:
  20. There are multiple signatures for this command, and some of the options are
  21. common between them. They are:
  22. ``EXACT`` / ``QUIET`` / ``REQUIRED``
  23. The ``EXACT`` option requests that the version string be matched exactly
  24. (including empty string, if no version is provided), overriding the typical
  25. pkg-config version comparison algorithm. This will ignore any comparison
  26. operator attached to the version string.
  27. The ``QUIET`` option disables informational messages, including those
  28. indicating that the package cannot be found if it is not ``REQUIRED``. The
  29. ``REQUIRED`` option stops processing with an error message if the package
  30. cannot be found.
  31. ``STRICTNESS <mode>``
  32. Specify how strictly the contents of the package files will be verified during
  33. parsing and resolution. An invalid file, under the provided strictness mode,
  34. will cause the command to fail. Possible modes are:
  35. * ``STRICT``: Closely mirrors the behavior of the original FDO pkg-config.
  36. Variables and keywords must be unique. Variables must be defined before
  37. they are used. The Name, Description, and Version keywords must be present.
  38. The overall structure of the file must be valid and parsable.
  39. * ``PERMISSIVE``: Closely mirrors the behavior of the pkgconf implementation.
  40. Duplicate variables are overridden. Duplicate keywords are appended.
  41. Undefined variables resolve to empty strings. The Name, Description, and
  42. Version keywords must be present. The overall structure of the file must be
  43. valid and parsable.
  44. * ``BEST_EFFORT``: Same behavior as ``PERMISSIVE`` with regards to duplicate
  45. or uninitialized variables and keywords, but will not fail under any
  46. conditions. Package files which require BEST_EFFORT will fail validation
  47. under all other major implementations and should be fixed.
  48. The default strictness is ``PERMISSIVE``.
  49. ``ENV_MODE``
  50. Specifies which environment variables will be queried when running a given
  51. command. Possible modes are:
  52. * ``FDO``: Queries only the original set of ``PKG_CONFIG_*`` environment
  53. variables used by the freedesktop.org ``pkg-config`` implementation.
  54. * ``PKGCONF``: Queries the more extensive set of environment variables used
  55. by the ``pkgconf`` implementation.
  56. * ``IGNORE``: Ignores the presence, absence, and value of environment
  57. variables entirely. In all cases an environment variable would be queried
  58. its treated as defined, but with a value of empty string for the purpose
  59. of the operation. This does not modify the current environment. For boolean
  60. environment variables, such as ``PKG_CONFIG_ALLOW_*``, this means they are
  61. evaluated as truthy.
  62. ``PKG_CONFIG_SYSROOT_PATH`` is a minor exception. When ``ENV_MODE IGNORE``
  63. is used, no root path prepending will occur by default and ``pc_sysrootdir``
  64. remains defaulted to ``/``.
  65. Target-generating subcommands always ignore flag-filtering environment
  66. variables. The default environment mode is ``PKGCONF``.
  67. ``PC_LIBDIR <path>...``
  68. Overrides the default search location for package files; also used to derive
  69. the ``pc_path`` package variable.
  70. When this option is not provided, the default library directory is the first
  71. available of the following values:
  72. #. ``CMAKE_PKG_CONFIG_PC_LIB_DIRS``
  73. #. The ``PKG_CONFIG_LIBDIR`` environment variable
  74. #. The output of ``pkg-config --variable pc_path pkg-config``
  75. #. A platform-dependent default value
  76. ``PC_PATH <path>...``
  77. Overrides the supplemental package file directories which will be prepended
  78. to the search path; also used to derive the ``pc_path`` package variable.
  79. When this option is not provided, the default paths are the first available of
  80. the following values:
  81. #. ``CMAKE_PKG_CONFIG_PC_PATH``
  82. #. The ``PKG_CONFIG_PATH`` environment variable
  83. #. Empty list
  84. ``DISABLE_UNINSTALLED <bool>``
  85. Overrides the search behavior for "uninstalled" package files. These are
  86. package files with an "-uninstalled" suffix which describe packages integrated
  87. directly from a build tree.
  88. Normally such package files have higher priority than "installed" packages.
  89. When ``DISABLE_UNINSTALLED`` is true, searching for "uninstalled" packages
  90. is disabled.
  91. When this option is not provided, the default search behavior is determined
  92. by the first available of the following values:
  93. #. ``CMAKE_PKG_CONFIG_DISABLE_UNINSTALLED``
  94. #. If the ``PKG_CONFIG_DISABLE_UNINSTALLED`` environment variable is defined
  95. the search is disabled, otherwise it is enabled.
  96. ``PC_SYSROOT_DIR <path>``
  97. Overrides the root path which will be prepended to paths specified by ``-I``
  98. compile flags and ``-L`` library search locations; also used to derive the
  99. ``pc_sysrootdir`` package variable.
  100. When this option is not provided, the default root path is provided by the
  101. first available of the following values:
  102. #. ``CMAKE_PKG_CONFIG_SYSROOT_DIR``
  103. #. The ``PKG_CONFIG_SYSROOT_DIR`` environment variable
  104. #. If no root path is available, nothing will be prepended to include or
  105. library directory paths and ``pc_sysrootdir`` will be set to ``/``
  106. ``TOP_BUILD_DIR <path>``
  107. Overrides the top build directory path used to derived the ``pc_top_builddir``
  108. package variable.
  109. When this option is not provided, the default top build directory path is
  110. the first available of the following values:
  111. #. ``CMAKE_PKG_CONFIG_TOP_BUILD_DIR``
  112. #. The ``PKG_CONFIG_TOP_BUILD_DIR`` environment variable
  113. #. If no top build directory path is available, the ``pc_top_builddir``
  114. package variable is not set
  115. Signatures
  116. ^^^^^^^^^^
  117. .. signature::
  118. cmake_pkg_config(EXTRACT <package> [<version>] [...])
  119. Extract the contents of the package into variables.
  120. .. code-block:: cmake
  121. cmake_pkg_config(EXTRACT <package> [<version>]
  122. [REQUIRED] [EXACT] [QUIET]
  123. [STRICTNESS <mode>]
  124. [ENV_MODE <mode>]
  125. [PC_LIBDIR <path>...]
  126. [PC_PATH <path>...]
  127. [DISABLE_UNINSTALLED <bool>]
  128. [PC_SYSROOT_DIR <path>]
  129. [TOP_BUILD_DIR <path>]
  130. [SYSTEM_INCLUDE_DIRS <path>...]
  131. [SYSTEM_LIBRARY_DIRS <path>...]
  132. [ALLOW_SYSTEM_INCLUDES <bool>]
  133. [ALLOW_SYSTEM_LIBS <bool>])
  134. The following variables will be populated from the contents of package file:
  135. ==================================== ====== ========================================================================================
  136. Variable Type Definition
  137. ==================================== ====== ========================================================================================
  138. ``CMAKE_PKG_CONFIG_NAME`` String Value of the ``Name`` keyword
  139. ``CMAKE_PKG_CONFIG_DESCRIPTION`` String Value of the ``Description`` keyword
  140. ``CMAKE_PKG_CONFIG_VERSION`` String Value of the ``Version`` keyword
  141. ``CMAKE_PKG_CONFIG_PROVIDES`` List Value of the ``Provides`` keyword
  142. ``CMAKE_PKG_CONFIG_REQUIRES`` List Value of the ``Requires`` keyword
  143. ``CMAKE_PKG_CONFIG_CONFLICTS`` List Value of the ``Conflicts`` keyword
  144. ``CMAKE_PKG_CONFIG_CFLAGS`` String Value of the ``CFlags`` / ``Cflags`` keyword
  145. ``CMAKE_PKG_CONFIG_INCLUDES`` List All ``-I`` prefixed flags from ``CMAKE_PKG_CONFIG_CFLAGS``
  146. ``CMAKE_PKG_CONFIG_COMPILE_OPTIONS`` List All flags not prefixed with ``-I`` from ``CMAKE_PKG_CONFIG_CFLAGS``
  147. ``CMAKE_PKG_CONFIG_LIBS`` String Value of the ``Libs`` keyword
  148. ``CMAKE_PKG_CONFIG_LIBDIRS`` List All ``-L`` prefixed flags from ``CMAKE_PKG_CONFIG_LIBS``
  149. ``CMAKE_PKG_CONFIG_LIBNAMES`` List All ``-l`` prefixed flags from ``CMAKE_PKG_CONFIG_LIBS``
  150. ``CMAKE_PKG_CONFIG_LINK_OPTIONS`` List All flags not prefixed with ``-L`` or ``-l`` from ``CMAKE_PKG_CONFIG_LIBS``
  151. ``CMAKE_PKG_CONFIG_*_PRIVATE`` \* ``CFLAGS`` / ``LIBS`` / ``REQUIRES`` and derived, but in their ``.private`` suffix forms
  152. ==================================== ====== ========================================================================================
  153. ``SYSTEM_INCLUDE_DIRS``
  154. Overrides the "system" directories for the purpose of flag mangling include
  155. directories in ``CMAKE_PKG_CONFIG_CFLAGS`` and derived variables.
  156. When this option is not provided, the default directories are provided by the
  157. first available of the following values:
  158. #. ``CMAKE_PKG_CONFIG_SYS_INCLUDE_DIRS``
  159. #. The ``PKG_CONFIG_SYSTEM_INCLUDE_PATH`` environment variable
  160. #. The output of ``pkgconf --variable pc_system_includedirs pkg-config``
  161. #. A platform-dependent default value
  162. Additionally, when the ``ENV_MODE`` is ``PKGCONF`` the
  163. ``CMAKE_PKG_CONFIG_PKGCONF_INCLUDES`` variable will be concatenated to the
  164. list if available. If it is not available, the following environment variables
  165. will be queried and concatenated:
  166. * ``CPATH``
  167. * ``C_INCLUDE_PATH``
  168. * ``CPLUS_INCLUDE_PATH``
  169. * ``OBJC_INCLUDE_PATH``
  170. * ``INCLUDE`` (Windows Only)
  171. ``SYSTEM_LIBRARY_DIRS``
  172. Overrides the "system" directories for the purpose of flag mangling library
  173. directories in ``CMAKE_PKG_CONFIG_LIBS`` and derived variables.
  174. When this option is not provided, the default directories are provided by the
  175. first available of the following values:
  176. #. ``CMAKE_PKG_CONFIG_SYS_LIB_DIRS``
  177. #. The ``PKG_CONFIG_SYSTEM_LIBRARY_PATH`` environment variable
  178. #. The output of ``pkgconf --variable pc_system_libdirs pkg-config``
  179. #. A platform-dependent default value
  180. Additionally, when the ``ENV_MODE`` is ``PKGCONF`` the
  181. ``CMAKE_PKG_CONFIG_PKGCONF_LIB_DIRS`` variable will be concatenated to the
  182. list if available. If it is not available, the ``LIBRARY_PATH`` environment
  183. variable will be queried and concatenated.
  184. ``ALLOW_SYSTEM_INCLUDES``
  185. Preserves "system" directories during flag mangling of include directories
  186. in ``CMAKE_PKG_CONFIG_CFLAGS`` and derived variables.
  187. When this option is not provided, the default value is determined by the first
  188. available of the following values:
  189. #. ``CMAKE_PKG_CONFIG_ALLOW_SYS_INCLUDES``
  190. #. If the ``PKG_CONFIG_ALLOW_SYSTEM_CFLAGS`` environment variable is defined
  191. the flags are preserved, otherwise they are filtered during flag mangling.
  192. ``ALLOW_SYSTEM_LIBS``
  193. Preserves "system" directories during flag mangling of library directories
  194. in ``CMAKE_PKG_CONFIG_LIBS`` and derived variables.
  195. When this option is not provided, the default value is determined by the first
  196. available of the following values:
  197. #. ``CMAKE_PKG_CONFIG_ALLOW_SYS_LIBS``
  198. #. If the ``PKG_CONFIG_ALLOW_SYSTEM_LIBS`` environment variable is defined
  199. the flags are preserved, otherwise they are filtered during flag mangling.