“选项”与“选项”之间的区别是什么?和“设置CACHE BOOL”为CMake变量? [英] What is the difference between "option" and "set CACHE BOOL" for a CMake variable?

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

问题描述

  set(FOO true CACHE BOOLdescription)

选项(FOOdescriptionON)

文档: set - option

背景:即使我一直在使用CMake,我也只注意到 option 命令,因此我总是使用 set :我想知道是否安全/值得替换第一个第二。

解决方案

在你的例子中,没有区别。但可能会有所不同:





另外,当您使用一个选项时,您向用户指出可以安全设置。从外部设置内部变量可能会巧妙地将脚本中断为无效值。


Is there any difference between the following two?

set(FOO true CACHE BOOL "description")

option(FOO "description" ON)

Documentation: set - option

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 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天全站免登陆