Reorganize CMake so that tests played nice with autogenerated code