“选项"和“选项"有什么区别?和“设置 CACHE BOOL"对于 CMake 变量? [英] What is the difference between "option" and "set CACHE BOOL" for a CMake variable?

查看:27
本文介绍了“选项"和“选项"有什么区别?和“设置 CACHE BOOL"对于 CMake 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两者有区别吗?

set(FOO true CACHE BOOL "description")

option(FOO "description" ON)

文档:set - 选项

背景:即使我已经使用 CMake 一段时间了,我今天才注意到 option 命令,因此我一直在使用 set:我想知道是否用第二个替换第一个是安全/值得的.

Background: Even if I have been using CMake for a while, I only noticed the option command today and I have therefore always been using set: I was wondering if it is safe/worth to replace the first with the second.

推荐答案

在您的示例中,没有区别.但可能存在差异:

In your example, there is no difference. But there can be differences:

  • Option has a default value of OFF.
  • You can make an option dependent on other options with CMakeDependentOption
  • Set accepts types other than BOOL, especially ;-lists.

此外,当您使用某个选项时,您是在向您的用户表明它可以安全地设置.从外部设置内部变量可能会巧妙地破坏具有无效值的脚本.

Additionally, when you use an option you are indicating to your user that it can be set safely. Setting internal variables from the outside might subtly break the script with invalid values.

这篇关于“选项"和“选项"有什么区别?和“设置 CACHE BOOL"对于 CMake 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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