Using third-party libraries in your CMake project
If you're writing software in earnest, sooner or later, you will hit the point where your project will rely on libraries from outside your project. Instead of looking for individual library files or header files, the recommended way by the CMake community and us authors is to do this with the find_package
command. The preferred approach for finding dependencies in CMake is using packages.
Packages provide a set of information about dependencies for CMake and the generated build systems. They can be integrated into a project in two forms. This is either by their configuration details (also called config-file packages), which are provided by the upstream project, or as so-called find module packages, which are usually defined somewhere that is unrelated to the package, either by CMake itself or by the project using the package. Both types can be found by using find_package
, and the result is a set of imported targets and/or a...