Fixed the cmake example to support out-of-source builds

In addition, it adds some handy variables.
This fixes a bug