Modularize CMakeLists.txt.

This is still a work in progress, but the bulk of the work is done now.
This change moves standalone executables into tools/ subdirectories of the
libraries they are for, and makes our build system consist of many
CMakeLists.txt files. This should make things easier to follow, at least
locally.
Fix compilation with gcc.