Refactor some stuff out to CMake test