CMake选项的默认值被忽略。

huangapple go评论58阅读模式
英文:

CMake option default value is ignored

问题

给定以下的CMake代码:

cmake_minimum_required(VERSION 3.25)
project(foo)
option(XXX "List of things" "a;b;c")
message(STATUS "XXX is ${XXX}")

在一个完全干净的构建目录中执行cmake ..会打印:

-- XXX is OFF

为什么默认值不起作用?请注意,这个问题特指在构建目录干净的情况下默认值不起作用,因此这个问题不是重复

英文:

Given the following CMake

cmake_minimum_required(VERSION 3.25)
project(foo)
option(XXX "List of things" "a;b;c")
message(STATUS "XXX is ${XXX}")

cmake .. with a completely clean build directory prints

-- XXX is OFF

Why doesn't the default value work? Note that this question is specifically about it not working when the build directory is clean so this question is not a duplicate.

答案1

得分: 2

option()仅用于布尔值。默认值只能是TRUEFALSE(或它们的许多别名)。

对于非布尔选项,您需要执行以下操作:

set(var_name "默认值" CACHE STRING "帮助文本")
英文:

Ah option() is only intended to be used for booleans. The default value can only be TRUE or FALSE (or their many aliases).

For non-boolean options you need to do:

set(var_name "Default value" CACHE STRING "Help text")

huangapple
  • 本文由 发表于 2023年6月15日 19:37:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定