我有一个CMake设置,其中一个变量的可访问性将取决于是否设置了另一个变量。小片段:
option(build-compiler "Build the Nap Compiler" ON)
set(include_interrupt_dirs CACHE INTERNAL "interrupts/intr_4" FORCE)
if(build-compiler)
option(enable-runtime-compilation
"Build in the runtime code compilation link in intr_2 & intr_3)" ON)
if(enable-runtime-compilation)
list(APPEND include_interrupt_dirs "interrupts/intr_2" "interrupts/intr_3" )
endif()
endif()我使用cmake来配置项目,我想要实现的是:
build-compiler,则还应该显示enable-runtime-compilation。这部分完成了。build-compiler,那么enable-runtime-compilation应该是隐藏的。这不管用。你知道怎么做吗?
发布于 2014-04-24 08:41:40
可以使用unset(var CACHE)从缓存中删除变量:
if(build-compiler)
option(enable-runtime-compilation
"Build in the runtime code compilation link in intr_2 & intr_3)" ON)
if(enable-runtime-compilation)
list(APPEND include_interrupt_dirs "interrupts/intr_2" "interrupts/intr_3" )
endif()
else()
unset(enable-runtime-compilation CACHE)
endif()发布于 2017-05-13 10:01:44
使用unset(var [CACHE])是很微妙的。如果您只是取消了变量的设置,它将留在缓存中(尽管它在脚本中是不可见的,但它对用户仍然是可见的)。如果您还从缓存中删除了它,那么就会失去存在的值。
在我的用例中,我想根据某些条件隐藏变量。我发现,从缓存中删除变量可能会引起混淆,因为当恢复时,它们将返回到默认状态,而不是返回到用户以前设置的状态。
我更喜欢使用mark_as_advanced(FORCE var)隐藏变量,使用mark_as_advanced(CLEAR var)取消隐藏。它完全可以满足您的需要--它向GUI隐藏变量,但它仍然存在于缓存中。您可以将它与“软”未设置(没有CACHE)一起使用,以确保配置中不再使用隐藏变量。
此外,还有专门针对此用例的CMakeDependentOption (只有在某些条件集计算为true时才可用的选项)。这显然是从CMake 3.0.2开始提供的。
https://stackoverflow.com/questions/23238642
复制相似问题