Qt cmake currently does an optional find of all the modules, if they're
not available it temporarily disables ENABLE_QT5, and gives a nice
message rather than just breaking.
It seems that there was an attempt to only do this if ENABLE_QT5 is not
explicitly defined, but that test is flawed. There is no way to tell the difference between loading from a previous cache and the command line as -D is literally just setting a cache variable before it starts processing.
On the first run it fails gracefully, on a second cmake run, it then just breaks badly.
I've also ported the case of only enabling kde support when we link KDE
when we build the relevant Qt to a cmake function that handles it all
for us. It allows the user to set an option explicitly and it will be
remembered, but the variable will only be true if and only if Qt is also
found.