Sore more DB fixes. Also, expose definitions and libraries out with
cmake variables.