是什么导致CMake选项不起作用? [英] What can cause a CMake option not work?

查看:689
本文介绍了是什么导致CMake选项不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在准备一个可以在没有GUI的情况下使用的应用程序,因此我在CMakeLists.txt中使用了命令

I am preparing an application which should work with and without GUI, so I use in my CMakeLists.txt the command

option (NEED_GUI "Include Qt support"  OFF) 

if (NEED_GUI)
  message("****GUI should be OFF****")
  add_subdirectory(QtGUI)   # The Qt-based graphics routines
endif (NEED_GUI)

尽管我将选项设置为OFF,但仍收到消息,并且库已构建.在哪里寻找错误?

Despite that I set the option OFF, I receive the message and the library is built. Where to look for an error?

推荐答案

将我的评论变成答案

您的代码看起来不错.因此,我假设这里的问题是 option() 会通过初始配置步骤将给定的值传送到您的CMakeCache.txt中.之后,只能通过修改NEED_GUI的缓存条目来更改它.生成构建环境后,在CMakeLists.txt中更改选项将不再更新缓存.

Your code looks good. So I'm assuming the problem here is that option() does transfer the value given into your CMakeCache.txt with the initial configuration step. After that you can only change it by modifying the cached entry for NEED_GUI. Changing the option in your CMakeLists.txt after you have generated your build environment will not update the cache anymore.

参考

  • What's the CMake syntax to set and use variables?
  • Advantages of using CMake option command rather than set?
  • How to tell whether CMake used initial value for an option?

这篇关于是什么导致CMake选项不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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