How it works

Once pkg-config is found, CMake will provide two functions to wrap the functionality offered by this program:

  • pkg_check_modules, to find all modules (libraries and/or programs) in the passed list
  • pkg_search_module, to find the first working module in the passed list

These functions accept the REQUIRED and QUIET arguments, as find_package does. In more detail, our call to pkg_search_module is the following:

pkg_search_module(  ZeroMQ  REQUIRED    libzeromq libzmq lib0mq  IMPORTED_TARGET  )

Here, the first argument is the prefix that will be used to name the target that is storing the result of the search for the ZeroMQ library: PkgConfig::ZeroMQ. Notice that we need to pass different options for the names of the library on the system: ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.