cmake中的find_dependency和find_package之间的区别? [英] Difference between find_dependency and find_package in cmake?

查看:778
本文介绍了cmake中的find_dependency和find_package之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在package-Config.cmake中,如果我执行find_package而不是find_dependency,对我的应用程序会有什么影响?

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?

推荐答案

根据文档 find_dependency 只是 find_package


它旨在用于程序包配置文件(< 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 original find_package() call. Any additional arguments specified are forwarded to find_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.

这篇关于cmake中的find_dependency和find_package之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆