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

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


The real world example is Slicer --
http://www.slicer.org/pages/DeveloperOrientation

This is rather a large and complex project and the way they do somethings
is hard to decode.

Make sure you read through and understand this:

http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html

The simplest setup is this:

Add a directory SuperBuild to your project.

Within SuperBuild, write a CMakeLists.txt that contains ExternalProject_add
for each of the prerequisite libraries.

Then use an ExternalProject to configure and build your actual project.
Since SuperBuild is a subdirectory of your actual project, there's no need
to download source, so you suppress the download and update steps, and
specify where to find the source.

ExternalProject_Add(MyProject
   DEPENDS ${Prerequisite_List} # this is the list of all the prerequisite
ExternalProjects you've added.
   DOWNLOAD_COMMAND ""     # no need to download
   UPDATE_COMMAND       ""    # or update.
   SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..    # source is relative to where
this CMakeLists.txt is
   BINARY_DIR MyProject-build  # otherwise build is nested down in
MyProject-prefix
   CMAKE_ARGS ${MyProject_CMAKE_ARGS} # set to allow your project to find
prerequisites
                                                                       #
e.g. -DITK_DIR:PATH=${PATH_TO_ITK_BUILD}
)



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

> >SuperBuild pattern
> Tell me all about it!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130204/a605b105/attachment.htm>


More information about the CMake mailing list