refactored CMake build scripts to be cleaner