cmake_pkg_config — CMake 4.0.3 Documentation (original) (raw)

Added in version 3.31.

Contents

Process pkg-config format package files.

Synopsis

cmake_pkg_config(EXTRACT [] [...])

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.

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. TheREQUIRED 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:

The default strictness is PERMISSIVE.

ENV_MODE

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

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:

  1. CMAKE_PKG_CONFIG_PC_LIB_DIRS
  2. The PKG_CONFIG_LIBDIR environment variable
  3. The output of pkg-config --variable pc_path pkg-config
  4. 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:

  1. CMAKE_PKG_CONFIG_PC_PATH
  2. The PKG_CONFIG_PATH environment variable
  3. 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:

  1. CMAKE_PKG_CONFIG_DISABLE_UNINSTALLED
  2. 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 -Icompile flags and -L library search locations; also used to derive thepc_sysrootdir package variable.

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

  1. CMAKE_PKG_CONFIG_SYSROOT_DIR
  2. The PKG_CONFIG_SYSROOT_DIR environment variable
  3. 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_builddirpackage variable.

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

  1. CMAKE_PKG_CONFIG_TOP_BUILD_DIR
  2. The PKG_CONFIG_TOP_BUILD_DIR environment variable
  3. If no top build directory path is available, the pc_top_builddirpackage variable is not set

Signatures

Extract the contents of the package into variables.

cmake_pkg_config(EXTRACT [] [REQUIRED] [EXACT] [QUIET] [STRICTNESS ] [ENV_MODE ] [PC_LIBDIR ...] [PC_PATH ...] [DISABLE_UNINSTALLED ] [PC_SYSROOT_DIR ] [TOP_BUILD_DIR ] [SYSTEM_INCLUDE_DIRS ...] [SYSTEM_LIBRARY_DIRS ...] [ALLOW_SYSTEM_INCLUDES ] [ALLOW_SYSTEM_LIBS ])

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:

  1. CMAKE_PKG_CONFIG_SYS_INCLUDE_DIRS
  2. The PKG_CONFIG_SYSTEM_INCLUDE_PATH environment variable
  3. The output of pkgconf --variable pc_system_includedirs pkg-config
  4. A platform-dependent default value

Additionally, when the ENV_MODE is PKGCONF theCMAKE_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:

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:

  1. CMAKE_PKG_CONFIG_SYS_LIB_DIRS
  2. The PKG_CONFIG_SYSTEM_LIBRARY_PATH environment variable
  3. The output of pkgconf --variable pc_system_libdirs pkg-config
  4. A platform-dependent default value

Additionally, when the ENV_MODE is PKGCONF theCMAKE_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:

  1. CMAKE_PKG_CONFIG_ALLOW_SYS_INCLUDES
  2. 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:

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