What can cause a CMake option not work?

安稳与你 提交于 2019-12-02 13:30:15

问题


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) 

and

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

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


回答1:


Turning my comment into an answer

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.

References

  • 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?



回答2:


if (NEED_GUI MATCHES ON)

is the appropriate usage rather than

if (NEED_GUI)


来源:https://stackoverflow.com/questions/35744647/what-can-cause-a-cmake-option-not-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!