Add libgit2 dependency to build system

This is pretty much #7339 with all changes to base removed. And I'm changing the way I'm handling flags and compiler names with cmake in the last commit.
Do we want to build the tests by default?  Otherwise we should add `-DCLAR_BUILD=OFF` here.