CMakeFindDependencyMacro¶
- find_dependency¶
The
find_dependency()macro wraps afind_package()call for a package dependency:find_dependency(<dep> [...])
It is designed to be used in a Package Configuration File (
<PackageName>Config.cmake).find_dependencyforwards the correct parameters forQUIETandREQUIREDwhich were passed to the originalfind_package()call. Any additional arguments specified are forwarded tofind_package().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 thefind_package()command that loaded it.Note
The call to
return()makes this macro unsuitable to call from Find Modules.Package Dependency Search Optimizations¶
If
find_dependencyis called with arguments identical to a previous call in the same directory, perhaps due to diamond-shaped package dependencies, the underlying call tofind_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<PackageName>_USE_STATIC_LIBS, offered by some packages. Therefore package configuration files should avoid setting such variables before their calls tofind_dependency.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 whichfind_dependencycall 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_dependencycall arguments.