1

As in title, I am wondering about what is better, attach graphic libraries(e.g glew, glm, glfw, etc.) in my git repository, or make a special cmake modules that download it while building?

I heard that it is not proper to add libraries to repo explicitly, especially if they are large, but making cmake modules for each library can be very infernal...

What in your opinion is better way? Maybe you have some other idea? What is your experience with it?

P.S. I use in my project cmake.

Edit: You can assume that libraries has around 10-20MB, and another project files < 5MB.

BartekPL
  • 2,290
  • 1
  • 17
  • 34
  • If the library will seldom be updated and is not very big, you could add it to the repo. It depends on your and your co-worker's storage capacity and network condition. – ElpieKay Apr 28 '17 at 06:44
  • 1
    The answer [here](http://stackoverflow.com/a/31622855/1938798) gives an alternative where the external project's repo is downloaded during CMake's configure stage. That answer links to further details with google test used as the example and it also includes a fully general implementation you may find useful. – Craig Scott Apr 28 '17 at 11:04
  • @CraigScott Thanks, I know cmake `ExternalProject` and I use it for know as best option for me, but sometimes I don't need full git repo to download. I sometimes need half of all library functionality, but I cannot download only chosen files. I learn how to download only some directories from git via cmake, but it is still not enough configurable. Another cons of use `ExternalProject` is that if I use some IDE and want to link it to downloaded library I have to write cmake first that download and build it. What's more, writing proper ExternalProject modules can be very infernal as I wrote ;) – BartekPL Apr 28 '17 at 11:32

1 Answers1

1

We're talking two distinct problems here: Build configuration and distribution configuration.

In general your project and build configuration should be as minimal as possible and rely on system wide installation of libraries where applicable. This is important to prepare – for example – for Linux distributions where a package manager keeps track of dependencies and builds should happen against the libraries installed through the package manager.

Distribution configuration OTOH is concerned with the various ways in which your project gets distributed to end users. Such a distribution configuration should allow for the configuration of builds with system wide installed libraries (like you want it for Linux packaging), but as well as producing self-contained builds that also covers importing and building exact versions of required libraries (you don't want to automatically use the most recent version, because that might break your build).

In that sense distribution configuration is responsible for specializing build configurations. A good approach for self contained builds (which is those which include 3rd party libraries) is to fetch and build the dependencies into the build tree (you're doing out of source tree builds, are you?).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Yes, I do out of source builds. My project has a long way to distribution, but distribution configuration seems be good way. I read sth about Cargo from Rust language, and it will be great to have it in C/C++ language. – BartekPL Apr 28 '17 at 08:36
  • Could you give me some example for distribution configuration for C++ project that has some dependiencies? How it should be done? – BartekPL Apr 28 '17 at 08:53
  • @BartekPL: Nothing off the shelf I can think of the tip of my tongue. OSS projects usually are not too much concerned with it, because for the most part they'll either live in a package managed system or on Windows, so the distribution channel is kind of hardcoded into the build script. As far as my own projects go (which use CMake) it boils down to a custom set of Python scripts (though I might port to Perl-6 eventually) and modified `Find*.cmake` files in my projects cmake. It's a crude hack, TBH, just so that I could check that "we have distribution configuration" box in the process. – datenwolf Apr 28 '17 at 08:53
  • @BartekPL: Um, I'll have no time this weekend to do a write up (family visiting; so I'll have to provide entertainment), but I think it'd be a good thing to do a formal writeup of how it works anyway. Ping me next week maybe. – datenwolf Apr 28 '17 at 08:55