[CMake] How to depend on external cmake projects?

Robert Dailey rcdailey.lists at gmail.com
Sun Aug 16 09:32:08 EDT 2015


There are certain repositories on Github I'd like to pull in as a
dependency. These repositories already use CMake to build their source
code. Based on personal experience and reading material online, there
are a couple of different options:

1. Pull down the repository as a submodule to my own git repository.
Then call add_subdirectory() on it to make it part of the build,
allowing me to refer to those targets as dependencies in my own
targets.

2. Use ExternalProject_Add(). This seems like legacy, I'm not sure if
I should use this. It also seems very verbose and boilerplate.

3. Use packages. The [CMake package documentation][1] does not go into
great detail on support for both installed versions and build tree for
a single package. Does this require two scripts? Can it share a single
one? Where are the examples?

How do I accomplish this?

[1]: http://www.cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html#creating-a-package-configuration-file-for-the-build-tree


More information about the CMake mailing list