Implementing cmake build

Replacement for PR #645.
Fixes: #647.