Wrangle (some) Caffe dependencies through CMake #2240
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Caffe has many dependencies, some of which seem quite esoteric. In order to alleviate the problem, I propose to modify the CMake build to fetch and build some dependencies as part of the Caffe build itself.
This can be done through the ExternalProject module in CMake. At build time, if a system-wide version of a given library is not found, CMake can be instructed to download and build it. Any dependencies built this way are always built as static libraries, to avoid having to pollute the user's system with extra shared libraries at install time.
Right now, this PR only handles glog and gflags. The same method can be extended to pretty much anything, although I'd recommend only doing this for libraries not commonly installed on a user's system. I've used this technique successfully in the past to tackle software that depends on, e.g., specific versions of Boost, or libraries that are not packaged yet and therefore hard to install for end users.
There are a few advantages to doing this: less dependencies to worry about when compiling Caffe, plus we can ensure that the build uses known-good versions of the libraries we depend on.
This method is not without it's drawbacks, though, and there are a few open questions: is it OK to depend on GitHub being accessible during the build? Are we concerned about bloating binary sizes due to static vs. dynamic linking? This will increase build times when our dependencies are not installed, would that be a concern for automated build systems?
Even though this is technically ready to merge, this PR is expected to be more of a starting point for discussion. Does this sound like a viable/interesting option to pursue?