Import of Jessica Pumphrey's work.

This needs careful tidying up - there are currently CMake build files in the diff.