pvallet
pvallet

Reputation: 137

How should I link to library dependencies from my git repository?

I have made a project on github that uses several libraries such as glew, glm, sdl2 or sdl2_image. I use them by having them in an a folder named 'external', and building them from source using CMake.

My problem is trying to setup that 'external' folder right after cloning the repo, so that it is easy for the user to compile the project.

The two reasonable options (but not optimal) that I see for me are downloading a zip file of the dependencies that I would have made myself, or fetching the dependencies one by one and unpacking them at the right locations through a script.

But making the script would add dependencies such as wget and its Windows equivalent, and I don't know where I could store the zip file, since github doesn't seem to provide a storage place for additional files (a new branch?).

Upvotes: 2

Views: 1573

Answers (1)

d-karl
d-karl

Reputation: 98

This sounds like a job for FetchContent: a fairly recent couple of scripts that should be able to do exactly what you want. That is, download either compiled binary zip files from fixed URLs or even pull in and build the latest commit in a given branch.

FetchContent is especially helpful, since it does all this at configuration time, skipping a couple problems the alternative, ExternalProject, has always had for me, which is only fetching and compiling a project at build time.

From the examples on FetchContent:

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        release-1.8.0
)

FetchContent_MakeAvailable(googletest)
# you now magically have the googletest cmake targets available 
# at configuration time and can link against them.

An alternative to this is to use the conan package management system, althought that is way more involved.

Upvotes: 1

Related Questions