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)
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
if (NEED_GUI MATCHES ON)
is the appropriate usage rather than
if (NEED_GUI)