- CMake Cookbook
- Radovan Bast Roberto Di Remigio
- 193字
- 2025-04-04 16:17:18
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: libzeromq, libzmq, and lib0mq. This is due to the fact that different operating systems and package managers can choose different names for the same package.
The pkg_check_modules and pkg_search_module functions gained the IMPORTED_TARGET option and the functionality to also define an imported target in CMake 3.6. Prior to this version of CMake, only the variables ZeroMQ_INCLUDE_DIRS , for the include directories, and ZeroMQ_LIBRARIES , for the link libraries, would have been defined for later use.