如果有其他选择 [英] cmake if else with option

查看:97
本文介绍了如果有其他选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cmake中同时使用optionif-else时遇到问题.

I am with problem to use option together if-else in the cmake.

project(test)

option(TESTE "isso é um teste" OFF)

if(TESTE)
  message("true")
else()
  message("false")
endif()

add_executable(test main.cpp)

即使我在该选项上选择了OFF,它也始终显示true,这是什么意思?

It always display true even if I put OFF at the option, what am I doing wrong?

推荐答案

这是因为选项的值存储在缓存(CMakeCache.txt)中.

That's because the value of the option is stored in the cache (CMakeCache.txt).

如果您在CMakeLists中更改了 default 值,但 actual 值已经存储在缓存中,则只会从缓存中加载该值.

If you change the default value in the CMakeLists but the actual value is already stored in the cache, it will just load the value from the cache.

因此,要测试CMakeList中的逻辑,请在每次重新运行CMake之前每次都删除高速缓存.

So to test the logic in your CMakeLists, delete the cache each time before re-running CMake.

这篇关于如果有其他选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆