60

次の2つに違いはありますか?

set(FOO true CACHE BOOL "description")

option(FOO "description" ON)

ドキュメンテーション: set -オプション

背景: しばらく CMake を使用していたとしても、option今日コマンドに気づいただけなので、常に使用してきsetました。

4

2 に答える 2

50

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.

于 2016-04-01T14:32:48.507 に答える