ExternalProject_Add project that depends on other external project


I can’t figure out the following situation:

Let’ suppose that I have two external projects A and B that I build with ExternalProject_Add so that B depends on A.

In External_B.cmake I write something like:


If in SuperBuild.cmake I write:


then the compilation passes fine.
But if I change the order of calling these two cmake files:


then when configuring project B I get the error telling me:
3116: error: get_property could not find TARGET A_target. Perhaps it has not yet been created.

Is there a way to setup every project dependacies and let the CMake choose the right order of configuring and building projects? Or I have to manually specify order of include(External_*.cmake)?

That’s a little odd and isn’t really how a super build would normally be set up. Normally the ExternalProject_Add() calls would be in the CMakeLists.txt of the top level of the super build. You would make A install to some area you specify and then pass that directory as a CMAKE_PREFIX_PATH to the configure step of B. Use find_package() in B to locate A. If A doesn’t provide a package, but only bare libraries, then B would use find_library() instead, but you’d also need to take care of adding header search paths too.

You are responsible for understanding the dependencies and required order of building the projects in a super build arrangement.

1 Like

Thank you a lot for the help!