英文:
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()
仅用于布尔值。默认值只能是TRUE
或FALSE
(或它们的许多别名)。
对于非布尔选项,您需要执行以下操作:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论