cmake: Support building a shared library

Defaults to off. Either use `-DBUILD_SHARED_LIBS=foo` or ccmake.