UsePkgConfig — CMake 4.3.0 Documentation

# UsePkgConfig

Deprecated since version 3.0: This module should no longer be used. Instead, use the `FindPkgConfig` module or the `cmake_pkg_config()` command.

This module provided a command for finding external packages using `pkg-config` command-line utility. It has been replaced by the more convenient `FindPkgConfig` module, which is commonly used in Find Modules.

As of CMake 3.31, the built-in `cmake_pkg_config()` command provides even more features to extract package information.

Load this module in a CMake project with:

    include(UsePkgConfig)

## Commands

This module provides the following command:

pkgconfig

  Finds external package using `pkg-config` and sets result variables:

      pkgconfig(<package> <includedir> <libdir> <linkflags> <cflags>)

  This command invokes `pkg-config` command-line utility to retrieve the package information into specified variables. If `pkg-config` or the specified package `<package>` is NOT found, the result variables remain empty.

  The arguments are:

  `<package>`

    Name of the package as defined in its PC metadata file (`<package>.pc`).

  `<includedir>`

    Variable name to store the package's include directory.

  `<libdir>`

    Variable name to store the directory containing the package library.

  `<linkflags>`

    Variable name to store the linker flags for the package.

  `<cflags>`

    Variable name to store the compiler flags for the package.

## Examples

Using this module fills the desired information into the four given variables:

    include(UsePkgConfig)
    pkgconfig(
      libart-2.0
      LIBART_INCLUDEDIR
      LIBART_LIBDIR
      LIBART_LDFLAGS
      LIBART_CFLAGS
    )

Migrating to the `FindPkgConfig` would look something like this:

    find_package(PkgConfig QUIET)
    if(PkgConfig_FOUND)
      pkg_check_modules(LIBART QUIET libart-2.0)
    endif()

    message(STATUS "LIBART_INCLUDEDIR=${LIBART_INCLUDEDIR}")
    message(STATUS "LIBART_LIBDIR=${LIBART_LIBDIR}")
    message(STATUS "LIBART_LDFLAGS=${LIBART_LDFLAGS}")
    message(STATUS "LIBART_CFLAGS=${LIBART_CFLAGS}")