Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between find_dependency and find_package in cmake?

Tags:

cmake

In package-Config.cmake, if I do find_package instead of find_dependency, what would be the effect on my application? In what scenarios it will break?

like image 997
user3237667 Avatar asked May 09 '18 23:05

user3237667


1 Answers

According to documentation, find_dependency is just a wrapper around find_package:

It is designed to be used in a Package Configuration File (<package>Config.cmake). find_dependency forwards the correct parameters for QUIET and REQUIRED which were passed to the original find_package() call. Any additional arguments specified are forwarded to find_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 the find_package() command that loaded it.

If you would use, e.g., find_package(REQUIRED) instead of find_dependency, and the package won't be found, then it will be difficult for user to understand, that the error is related with outer package, not only with the inner one. Also, if outer call of find_package doesn't use REQUIRE option, it is inconsistent to perform inner call with that option.

like image 92
Tsyvarev Avatar answered Nov 03 '22 08:11

Tsyvarev