cmake: place binaries together in the build tree

This allows Windows to copy binaries to one place rather than to each
executable directory.
mingw: copy required libraries to the build tree

These are found as shared libraries and need to be copied so that PATH
manipulation isn't necessary outside of an msys shell.
cmake: work around a bug with implicit link directories

Unfortunately, this is necessary because CMake doesn't detect whether
mingw libraries are static or shared and doesn't put a -static flag around
the -lfoo argument which then makes the shared library be linked to.