[CMake] How to depend on external cmake projects?

James Johnston JamesJ at motionview3d.com
Mon Aug 24 10:32:10 EDT 2015


> -----Original Message-----
> From: rcdailey at gmail.com [mailto:rcdailey at gmail.com] On Behalf Of Robert
> Dailey
> Sent: Sunday, August 23, 2015 02:43
> To: James Johnston
> Cc: CMake
> Subject: Re: [CMake] How to depend on external cmake projects?
> 
> On Mon, Aug 17, 2015 at 10:17 AM, James Johnston
> <JamesJ at motionview3d.com> wrote:
> > Well, you'd do this in conjunction with ExternalProject_Add.  A
> > well-written CMake external project will provide a
> > <project>Config.cmake file which you will then find using find_package.
> 
> After toying around with this idea for a bit, I've found out that
> ExternalProject_Add() actually builds the project from a custom target within
> Visual Studio (I'm using VS as my generator). However,
> find_package() works at CMake configure time, so this is a chicken & egg
> problem. find_package() won't work because the external project has not
> been built yet.
> 
> How do you solve this problem?

By following the following suggestion from earlier:

> 
> > A high-level CMake project that does nothing but call
> > ExternalProject_Add; this is called a superbuild.  Your own CMake
> > projects will be ExternalProjects to this high-level project and the
> > superbuild would pass the location to your project via
> > -D<project>_DIR=<location> so that find_package can locate the Config
> file.
> 
> I'm not sure I understand this. This smells related to my question above,
> maybe an answer even. Can you clarify/go into more detail?
> Thanks a bunch.

Here is an example:

https://github.com/InsightSoftwareConsortium/ITKWikiExamples/tree/master/Superbuild

This CMakeLists.txt is the root CMakeLists.txt for the superbuild.  Notice that:

1.  It calls ExternalProject_Add to build VTK/ITK, **as well as** its own project.

2.  find_package is not called from the superbuild, thus avoiding the chicken and egg problem. 

Best regards,

James Johnston




More information about the CMake mailing list