find_package is a two-headed beast these days:
CMake provides direct support for two forms of packages, Config-file Packages and Find-Module Packages.
A source
Now what does that mean?
Find-module packages are the ones you are most likely familiar with. They execute a CMake code script (like this one ) that does a bunch of calls to functions like find_library and find_path to figure out where to find the library.
The great advantage of this approach is that it is extremely general. As long as there is something in the file system, we can find it. The big disadvantage is that it often provides a little more information than the physical location of this. That is, the result of an operation with a search module, as a rule, is simply a bunch of file system paths. This means that modeling like transitive dependencies or multiple assembly configurations is quite complicated.
This becomes especially painful if the thing you are trying to find is itself built with CMake. In this case, you already have a bunch of things modeled in your build scripts that you now need to carefully rebuild to find the script so that it becomes available for future projects.
This is where the configuration file files are displayed. Unlike find-modules, the result of running a script is not just a bunch of paths, but instead creates fully functional CMake targets. In a dependent project, it looks like dependencies were created as part of the same project.
This allows you to transfer much more information in a very convenient way. The obvious downside is that config-file scripts are much more complicated than find-scripts. Therefore, you do not want to write them yourself, but CMake generates them for you. Or rather, the dependency provides a configuration file as part of its deployment, which you can then simply load by calling find_package . And that is exactly what Qt5 does.
It also means that if your own project is a library, consider creating a configuration file as part of the build process . This is not the easiest CMake feature, but the results are quite powerful.
Here is a brief comparison of how the two approaches usually look in CMake code:
Find-module style
find_package(foo) target_link_libraries(bar ${FOO_LIBRARIES}) target_include_directories(bar ${FOO_INCLUDE_DIR})
Config file style
find_package(foo) target_link_libraries(bar foo)
tl; dr : always prefer configuration file packages, if available. If not, use find- script instead.