更新时间:2023-02-26 20:47:27
根据文档, find_dependency
只是 find_package $的包装c $ c>:
它旨在用于程序包配置文件(
< package> Config.cmake
)。find_dependency
转发 QUIET 和 REQUIRED 的正确参数,这些参数已传递给原始的find_package( )
调用。指定的所有其他参数将转发到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 originalfind_package()
call. Any additional arguments specified are forwarded tofind_package()
.
如果找不到依赖项,它将设置一条信息性诊断消息并调用 return()
结束对调用程序包配置文件的处理,并返回到 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.
如果要使用,例如 find_package(REQUIRED)
而不是 find_dependency
,并且找不到该包,那么用户将很难理解,该错误与外部包有关,而不仅与内部包有关。另外,如果 find_package
的外部调用不使用 REQUIRE 选项,则使用该选项执行内部调用是不一致的。
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.