ported build system to cmake
make compile with -pedantic and use foreach in some places