Rewrite much of CMakeLists.txt

Be better about detecting the compiler's/system's capabilities rather than
have a bunch of hard-coded "if this is FreeBSD, then <memory.h> is
available" sort of stuff. (Similarly for detecting C++11 features.)
Similarly, in code, the #defines to be checked are based on language
features, not compilers or compiler versions.
This should improve portability overall.
Along the way, got rid of port.h, which is basically unneeded now.