Fix CMake options and add minimal build
This MR fixes a number of issues I discovered while working on #2102 (closed) that are mostly unrelated to MinGW. I spawned it off from an upcoming MR to make that MR a little bit smaller.
Only one of the commits is actually a step towards #2102 (closed).