Detecting external libraries: I. Using pkg-config

The code for this recipe is available at https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-03/recipe-09 and has a C example. The recipe is valid with CMake version 3.6 (and higher) and has been tested on GNU/Linux, macOS, and Windows (using MSYS Makefiles). In https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-03/recipe-09, we also provide an example compatible with CMake 3.5.

We have so far discussed two ways of detecting external dependencies:

  • Using find-modules shipped with CMake. This is generally reliable and well tested. However, not all packages have a find-module in the official release of CMake.
  • Using <package>Config.cmake, <package>ConfigVersion.cmake, and ...

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.