[CMake] using ExternalProject_Add when cmake is launched

Bill Hoffman bill.hoffman at kitware.com
Thu May 3 11:29:26 EDT 2018


On 5/2/2018 4:47 AM, Petr Kmoch wrote:
> Hi Stephane.
>
> ExternalProject is designed to run at *build* time, not at *CMake* 
> time. It is not really intended for mixing with normal, 
> non-ExternalProject targets (such as those created by add_library).
>
> When using ExternalProject, the canonical form of operation is a 
> SuperBuild-style project: your master CMakeLists.txt will contain only 
> ExternalProject_Add() calls, *including one for your normal project.* 
> Your normal project becomes just another project managed by the 
> SuperBuild. The SuperBuild's purpose is to download, configure, build, 
> etc., all the subprojects. So you generate the SuperBuild and then 
> build it once to get all the dependencies in place. The you switch to 
> using just the YourProject "child" of the SuperBuild and do normal 
> development there.
>
> I think googling "CMake ExternalProject_Add superbuild" will give you 
> enough details to get you going.

Another option can be found in the most recent CMake 3.11:

https://cmake.org/cmake/help/git-stage/module/FetchContent.html

That should do what you want. It can not build or configure like 
external project, but it can download at cmake time.

-Bill






More information about the CMake mailing list