File: cmake_pkg_config.rst

package info (click to toggle)
cmake 3.31.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 142,992 kB
  • sloc: ansic: 393,437; cpp: 288,767; sh: 3,958; yacc: 3,240; python: 3,015; lex: 1,337; asm: 438; f90: 429; lisp: 375; cs: 270; java: 266; perl: 217; objc: 212; xml: 198; fortran: 137; makefile: 96; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (263 lines) | stat: -rw-r--r-- 11,621 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
cmake_pkg_config
----------------

.. versionadded:: 3.31

.. only:: html

   .. contents::

Process pkg-config format package files.

Synopsis
^^^^^^^^

.. parsed-literal::

  cmake_pkg_config(EXTRACT <package> [<version>] [...])

Introduction
^^^^^^^^^^^^

This command generates CMake variables and targets from pkg-config format
package files natively, without needing to invoke or even require the presence
of a pkg-config implementation. A ``<package>`` is either an absolute path to a
package file, or a package name to be searched for using the typical pkg-config
search patterns. The optional ``<version>`` string has the same format and
semantics as a pkg-config style version specifier, with the exception that if
no comparison operator is specified ``=`` is assumed.

.. _`common options`:

There are multiple signatures for this command, and some of the options are
common between them. They are:

``EXACT`` / ``QUIET`` / ``REQUIRED``
  The ``EXACT`` option requests that the version string be matched exactly
  (including empty string, if no version is provided), overriding the typical
  pkg-config version comparison algorithm. This will ignore any comparison
  operator attached to the version string.

  The ``QUIET`` option disables informational messages, including those
  indicating that the package cannot be found if it is not ``REQUIRED``. The
  ``REQUIRED`` option stops processing with an error message if the package
  cannot be found.

``STRICTNESS <mode>``
  Specify how strictly the contents of the package files will be verified during
  parsing and resolution. An invalid file, under the provided strictness mode,
  will cause the command to fail. Possible modes are:

  * ``STRICT``: Closely mirrors the behavior of the original FDO pkg-config.
    Variables and keywords must be unique. Variables must be defined before
    they are used. The Name, Description, and Version keywords must be present.
    The overall structure of the file must be valid and parsable.

  * ``PERMISSIVE``: Closely mirrors the behavior of the pkgconf implementation.
    Duplicate variables are overridden. Duplicate keywords are appended.
    Undefined variables resolve to empty strings. The Name, Description, and
    Version keywords must be present. The overall structure of the file must be
    valid and parsable.

  * ``BEST_EFFORT``: Same behavior as ``PERMISSIVE`` with regards to duplicate
    or uninitialized variables and keywords, but will not fail under any
    conditions. Package files which require BEST_EFFORT will fail validation
    under all other major implementations and should be fixed.

  The default strictness is ``PERMISSIVE``.

``ENV_MODE``
  Specifies which environment variables will be queried when running a given
  command. Possible modes are:

  * ``FDO``: Queries only the original set of ``PKG_CONFIG_*`` environment
    variables used by the freedesktop.org ``pkg-config`` implementation.

  * ``PKGCONF``: Queries the more extensive set of environment variables used
    by the ``pkgconf`` implementation.

  * ``IGNORE``: Ignores the presence, absence, and value of environment
    variables entirely. In all cases an environment variable would be queried
    its treated as defined, but with a value of empty string for the purpose
    of the operation. This does not modify the current environment. For boolean
    environment variables, such as ``PKG_CONFIG_ALLOW_*``, this means they are
    evaluated as truthy.

    ``PKG_CONFIG_SYSROOT_PATH`` is a minor exception. When ``ENV_MODE IGNORE``
    is used, no root path prepending will occur by default and ``pc_sysrootdir``
    remains defaulted to ``/``.

  Target-generating subcommands always ignore flag-filtering environment
  variables. The default environment mode is ``PKGCONF``.

``PC_LIBDIR <path>...``
  Overrides the default search location for package files; also used to derive
  the ``pc_path`` package variable.

  When this option is not provided, the default library directory is the first
  available of the following values:

  #. ``CMAKE_PKG_CONFIG_PC_LIB_DIRS``
  #. The ``PKG_CONFIG_LIBDIR`` environment variable
  #. The output of ``pkg-config --variable pc_path pkg-config``
  #. A platform-dependent default value

``PC_PATH <path>...``
  Overrides the supplemental package file directories which will be prepended
  to the search path; also used to derive the ``pc_path`` package variable.

  When this option is not provided, the default paths are the first available of
  the following values:

  #. ``CMAKE_PKG_CONFIG_PC_PATH``
  #. The ``PKG_CONFIG_PATH`` environment variable
  #. Empty list

``DISABLE_UNINSTALLED <bool>``
  Overrides the search behavior for "uninstalled" package files. These are
  package files with an "-uninstalled" suffix which describe packages integrated
  directly from a build tree.

  Normally such package files have higher priority than "installed" packages.
  When ``DISABLE_UNINSTALLED`` is true, searching for "uninstalled" packages
  is disabled.

  When this option is not provided, the default search behavior is determined
  by the first available of the following values:

  #. ``CMAKE_PKG_CONFIG_DISABLE_UNINSTALLED``
  #. If the ``PKG_CONFIG_DISABLE_UNINSTALLED`` environment variable is defined
     the search is disabled, otherwise it is enabled.

``PC_SYSROOT_DIR <path>``
  Overrides the root path which will be prepended to paths specified by ``-I``
  compile flags and ``-L`` library search locations; also used to derive the
  ``pc_sysrootdir`` package variable.

  When this option is not provided, the default root path is provided by the
  first available of the following values:

  #. ``CMAKE_PKG_CONFIG_SYSROOT_DIR``
  #. The ``PKG_CONFIG_SYSROOT_DIR`` environment variable
  #. If no root path is available, nothing will be prepended to include or
     library directory paths and ``pc_sysrootdir`` will be set to ``/``

``TOP_BUILD_DIR <path>``
  Overrides the top build directory path used to derived the ``pc_top_builddir``
  package variable.

  When this option is not provided, the default top build directory path is
  the first available of the following values:

  #. ``CMAKE_PKG_CONFIG_TOP_BUILD_DIR``
  #. The ``PKG_CONFIG_TOP_BUILD_DIR`` environment variable
  #. If no top build directory path is available, the ``pc_top_builddir``
     package variable is not set

Signatures
^^^^^^^^^^

.. signature::
  cmake_pkg_config(EXTRACT <package> [<version>] [...])

  Extract the contents of the package into variables.

  .. code-block:: cmake

    cmake_pkg_config(EXTRACT <package> [<version>]
                    [REQUIRED] [EXACT] [QUIET]
                    [STRICTNESS <mode>]
                    [ENV_MODE <mode>]
                    [PC_LIBDIR <path>...]
                    [PC_PATH <path>...]
                    [DISABLE_UNINSTALLED <bool>]
                    [PC_SYSROOT_DIR <path>]
                    [TOP_BUILD_DIR <path>]
                    [SYSTEM_INCLUDE_DIRS <path>...]
                    [SYSTEM_LIBRARY_DIRS <path>...]
                    [ALLOW_SYSTEM_INCLUDES <bool>]
                    [ALLOW_SYSTEM_LIBS <bool>])

The following variables will be populated from the contents of package file:

==================================== ====== ========================================================================================
              Variable                Type                       Definition
==================================== ====== ========================================================================================
``CMAKE_PKG_CONFIG_NAME``            String Value of the ``Name`` keyword
``CMAKE_PKG_CONFIG_DESCRIPTION``     String Value of the ``Description`` keyword
``CMAKE_PKG_CONFIG_VERSION``         String Value of the ``Version`` keyword
``CMAKE_PKG_CONFIG_PROVIDES``        List   Value of the ``Provides`` keyword
``CMAKE_PKG_CONFIG_REQUIRES``        List   Value of the ``Requires`` keyword
``CMAKE_PKG_CONFIG_CONFLICTS``       List   Value of the ``Conflicts`` keyword
``CMAKE_PKG_CONFIG_CFLAGS``          String Value of the ``CFlags`` / ``Cflags`` keyword
``CMAKE_PKG_CONFIG_INCLUDES``        List   All ``-I`` prefixed flags from ``CMAKE_PKG_CONFIG_CFLAGS``
``CMAKE_PKG_CONFIG_COMPILE_OPTIONS`` List   All flags not prefixed with ``-I`` from ``CMAKE_PKG_CONFIG_CFLAGS``
``CMAKE_PKG_CONFIG_LIBS``            String Value of the ``Libs`` keyword
``CMAKE_PKG_CONFIG_LIBDIRS``         List   All ``-L`` prefixed flags from ``CMAKE_PKG_CONFIG_LIBS``
``CMAKE_PKG_CONFIG_LIBNAMES``        List   All ``-l`` prefixed flags from ``CMAKE_PKG_CONFIG_LIBS``
``CMAKE_PKG_CONFIG_LINK_OPTIONS``    List   All flags not prefixed with ``-L`` or ``-l`` from ``CMAKE_PKG_CONFIG_LIBS``
``CMAKE_PKG_CONFIG_*_PRIVATE``       \*     ``CFLAGS`` / ``LIBS`` / ``REQUIRES`` and derived, but in their ``.private`` suffix forms
==================================== ====== ========================================================================================

``SYSTEM_INCLUDE_DIRS``
  Overrides the "system" directories for the purpose of flag mangling include
  directories in ``CMAKE_PKG_CONFIG_CFLAGS`` and derived variables.

  When this option is not provided, the default directories are provided by the
  first available of the following values:

  #. ``CMAKE_PKG_CONFIG_SYS_INCLUDE_DIRS``
  #. The ``PKG_CONFIG_SYSTEM_INCLUDE_PATH`` environment variable
  #. The output of ``pkgconf --variable pc_system_includedirs pkg-config``
  #. A platform-dependent default value

  Additionally, when the ``ENV_MODE`` is ``PKGCONF`` the
  ``CMAKE_PKG_CONFIG_PKGCONF_INCLUDES`` variable will be concatenated to the
  list if available. If it is not available, the following environment variables
  will be queried and concatenated:

  * ``CPATH``
  * ``C_INCLUDE_PATH``
  * ``CPLUS_INCLUDE_PATH``
  * ``OBJC_INCLUDE_PATH``
  * ``INCLUDE`` (Windows Only)

``SYSTEM_LIBRARY_DIRS``
  Overrides the "system" directories for the purpose of flag mangling library
  directories in ``CMAKE_PKG_CONFIG_LIBS`` and derived variables.

  When this option is not provided, the default directories are provided by the
  first available of the following values:

  #. ``CMAKE_PKG_CONFIG_SYS_LIB_DIRS``
  #. The ``PKG_CONFIG_SYSTEM_LIBRARY_PATH`` environment variable
  #. The output of ``pkgconf --variable pc_system_libdirs pkg-config``
  #. A platform-dependent default value

  Additionally, when the ``ENV_MODE`` is ``PKGCONF`` the
  ``CMAKE_PKG_CONFIG_PKGCONF_LIB_DIRS`` variable will be concatenated to the
  list if available. If it is not available, the ``LIBRARY_PATH`` environment
  variable will be queried and concatenated.

``ALLOW_SYSTEM_INCLUDES``
  Preserves "system" directories during flag mangling of include directories
  in ``CMAKE_PKG_CONFIG_CFLAGS`` and derived variables.

  When this option is not provided, the default value is determined by the first
  available of the following values:

  #. ``CMAKE_PKG_CONFIG_ALLOW_SYS_INCLUDES``
  #. If the ``PKG_CONFIG_ALLOW_SYSTEM_CFLAGS`` environment variable is defined
     the flags are preserved, otherwise they are filtered during flag mangling.


``ALLOW_SYSTEM_LIBS``
  Preserves "system" directories during flag mangling of library directories
  in ``CMAKE_PKG_CONFIG_LIBS`` and derived variables.

  When this option is not provided, the default value is determined by the first
  available of the following values:

  #. ``CMAKE_PKG_CONFIG_ALLOW_SYS_LIBS``
  #. If the ``PKG_CONFIG_ALLOW_SYSTEM_LIBS`` environment variable is defined
     the flags are preserved, otherwise they are filtered during flag mangling.