Refactored the build slightly.

I factored the CMake code that deals with import libraries out into its
own file.