Using already installed dependencies
When our project depends on a popular library, it's likely that the operating system already has the right package installed. We just have to connect it to our project's build process. How do we do that? We need to find out where the package is on the system, so CMake can use its files. Doing this by hand is possible, but every environment is a little different. A path that works on one system might not work on another. So, we should automatically find these paths when building. There are different ways to do this, but the best method is usually CMake's built-in find_package()
command which knows how to find many commonly used packages. If our package isn't supported, we have two options:
- We can write a small plug-in called a find-module to help
find_package()
- Or we can use an older method called FindPkgConfig
Let’s start with the recommended option first.
Finding packages with CMake’s find_package()
Let’...