One way would be to build those dependencies statically as well and use PKG_CONFIG_PATH
point to your own copies so everything gets linked statically. That should make CMake choose the static versions.
But if the goal is to avoid depending on the user-installed libraries rather than making everything a single executable, I would recommend shipping the libraries and working with the load path to make sure they get loaded. With gcc
you'd pass -Wl,-R
to set the search path in the binary itself, so you can set where to search for the shared libraries you're shipping with your app. With go
it looks like you can pass -r
to the linker (via -ldflags
or manually) to do the same thing.
libgit2 is rather extensible, so there is a third option which is to implement the TLS stream and SSH transport in Go and plug those into a version of libgit2 without support for these. This is however a significant amount of work.