Some CMake refactoring.

Moved test files into their own directory (also including a separate CMakeLists.txt) and changed the command to build and run the tests to `make test`. Also includes more consistent formatting in the CMake files, and automatically generates a list of generated headers to add as build dependency.