cmake: fix the detection of $QTDIR from the environment

Thanks to Christian Degenkolb <christian@degenkolb.net> for his report and to
http://www.cmake.org/pipermail/cmake/2006-February/008252.html for instructions
on how to do this properly.

REVIEW: 112505