Revert "Reverted the broken CMake stuff"

This reverts commit 93e21124323e21ab49638201b1c5be233e94cc2b.