cherry-pick certain "#if"s from 69dd692 (thanks to kamipo), add CmMakeLists.txt (with some fixed configuration)