[CMake] When should I use add_subdirectory and when ExternalProject?

Kent Williams nkwmailinglists at gmail.com
Mon Feb 4 10:21:09 EST 2013


They are two different things entirely.

add_subdirectory is used when you have a project structured hierarchically
in directories and subdirectories, but you want the entire project
configured at one time.

ExternalProject is used to download, configure and build a project that is
a prerequisite to your project, but not part of your project.

The most common use-case is the SuperBuild pattern.  In this case all
prerequisites to your project are built, and then YOUR project is built as
an ExternalProject.  Why? Because almost always, the prerequisites need to
be built and perhaps installed BEFORE configuring your projects.

It is sometimes possible to use ExternalProject from within your source
tree, but it requires that configuring your project requires nothing from
the ExternalProject at configure time.


On Mon, Feb 4, 2013 at 2:23 AM, Ansis Māliņš <ansis.malins at gmail.com> wrote:

> If I have a dependency (e.g. SDL2) that seems to work with
> add_subdirectory just fine, should I still use ExternalProject_Add instead?
> Given both ways work, what should I prefer? What are the tradeoffs?
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130204/24561785/attachment-0001.htm>


More information about the CMake mailing list