Fix some CMake linker problems.

Commit bb1b4071a65159cdff43aa8e445c1370b5d8521c missed linker errors
when the tests were disabled, so fixed them now. Reported by Spoffy and
Ivanovic.