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?
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.