Using ExternalProject and FetchContent modules
Online reference books on CMake will suggest ExternalProject
and FetchContent
modules to deal with the management of dependencies in more complex projects. That's actually good advice, but it's often given without appropriate context. Suddenly, we're facing a lot of questions. What are these modules for? When to choose one over the other? How exactly do they work, and how do they interact with each other? Some answers are harder to find than others, and surprisingly, CMake's documentation doesn't provide a smooth introduction to the subject. Not to worry – we'll take care of it here.
ExternalProject
CMake 3.0.0 introduced a module called ExternalProject
. As you can guess, its purpose was to add support for external projects available in online repositories. Over the years, the module was gradually extended for different needs, resulting in quite a complicated command – ExternalProject_Add...