What is the difference between “option” and “set C

2019-02-05 13:31发布

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.

1条回答
姐就是有狂的资本
2楼-- · 2019-02-05 14:06

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.

查看更多
登录 后发表回答