Search⌘ K

How to Find Installed Packages II

Explore how to use CMake's find_package command to locate installed packages and utilize imported targets for cleaner dependency management. Understand common variables set by find_package and options to specify versions or handle errors. Learn to write concise and robust CMake code by prioritizing imported targets and leveraging documentation.

In most cases, we can expect some variables to be set when we call find_package(), whether we're using a built-in find-module or a config-file bundled with a package (assuming that the package was found):

  • <PKG_NAME>_FOUND

  • <PKG_NAME>_INCLUDE_DIRS or <PKG_NAME>_INCLUDES

  • <PKG_NAME>_LIBRARIES or <PKG_NAME>_LIBS

  • <PKG_NAME>_DEFINITIONS

  • IMPORTED targets specified by the find-module or config-file

The IMPORTED targets

The last point is really interesting—if a package supports so-called ...