find_dependency()macro wraps a
find_package()call for a package dependency:
It is designed to be used in a Package Configuration File (
find_dependencyforwards the correct parameters for
REQUIREDwhich were passed to the original
find_package()call. Any additional arguments specified are forwarded to
If the dependency could not be found it sets an informative diagnostic message and calls
return()to end processing of the calling package configuration file and return to the
find_package()command that loaded it.
Package Dependency Search Optimizations¶
find_dependency is called with arguments identical to a previous
call in the same directory, perhaps due to diamond-shaped package
dependencies, the underlying call to
find_package() is optimized
out. This optimization is important to support large package dependency
graphs while avoiding a combinatorial explosion of repeated searches.
However, the heuristic cannot account for ambient variables that
affect package behavior, such as
offered by some packages. Therefore package configuration files should
avoid setting such variables before their calls to
Changed in version 3.15: Previously, the underlying call to
find_package() was always
optimized out if the package had already been found. CMake 3.15
removed the optimization to support cases in which
call arguments request different components.
Changed in version 3.26: The pre-3.15 optimization was restored, but with the above-described
heuristic to account for varying
find_dependency call arguments.