I've spent a lot of time recently following a long gone developer's vague and incorrect build instructions for a C++ project I'm working on. Therefore, I'm writing a new build system and I'm looking for the best way to do it. I've settled on using the ExternalProject_Add
command in CMake for collecting and building dependencies before the project targets but I've also found an excellant article suggesting use of git submodules, which looks like it does a very similar, if not the same thing. So my question: What is the relationship between git submodules and ExternalProject_Add?

- 7,014
- 10
- 53
- 106
-
`git submodules` is provided by `git` utility, `ExternalProject_Add` is provided by CMake. How they could be "the **same thing**"? Do you want to **compare** these functionalities as a way for handle **external dependencies** in a CMake project? I am unsure that prop. and cons. request is on-topic on Stack Overflow and can be properly answered. BTW, instead of `ExternalProject_Add` it is `FetchContent` functionality which is similar to one provided by `git submodules`. It is mainly up to the project's developer to choose one of `FetchContent` or `git submodules`. – Tsyvarev Mar 02 '20 at 19:49
-
"the same thing", I mean in terms of functionality. I didn't mean to imply they are exact. It seems to me they both enable third party libraries to be intstalled without much hastle. I want to know what the 'normal' (for want of a better word) C++ developer knows about these two similar features. Perhaps your right, this is boarding on being off-topic for stack overflow, but I'd still find it very useful to have an answer however. – CiaranWelsh Mar 03 '20 at 17:22
1 Answers
You can use ExternalProject_Add
without git submodules:
if (SPECIAL_CASE)
include (ExternalProject)
ExternalProject_Add (
project1
PREFIX project1
GIT_REPOSITORY "https://github.com/project.git"
GIT_TAG "v1"
)
endif ()
project
will be cloned to CURRENT_BINARY_DIR
, built and installed into local system before main project build. Your main project will use #include <project/header.h>
from global scope. This solution is suitable for popular projects only, that are available as dependency for part of target operating systems. You can guarantee that your target system will receive required version of dependency.
For example lets look at openssl
, your local system 100% have this library installed. Your target operating systems list includes native Win32
(without MinGW
or CygWin
). All available releases of openssl
for Win32
are too ancient, you won't be able to find required version of openssl
installer for Win32
. So you may use #include <openssl/ssl.h>
together with if (WIN32) ExternalProject_Add
without submodule. There is no point in adding openssl
submodule to your project.
Please review the following example.
If external project
is not popular, not available in popular package managers (as rpm, deb, ebuilds, etc) than it is better to use submodules.

- 3,294
- 6
- 38
- 62