# ExternalProject\_Add project that depends on other external project

**URL:** <https://discourse.cmake.org/t/externalproject-add-project-that-depends-on-other-external-project/2437>\
**Category:** Code\
**Created:** [December 29, 2020, 1:59am UTC](https://discourse.cmake.org/t/externalproject-add-project-that-depends-on-other-external-project/2437 "2020-12-29T01:59:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kerim](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kerim](https://discourse.cmake.org/u/kerim)\
**Post date:** [December 29, 2020, 1:59am UTC](https://discourse.cmake.org/t/externalproject-add-project-that-depends-on-other-external-project/2437/1 "2020-12-29T01:59:59Z")

</div>

Hi,

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:

```cmake
ExternalProject_Add(B
  ...
  DEPENDS
    A_target
    )

```

If in `SuperBuild.cmake` I write:

```cmake
include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/External_A.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/External_B.cmake")

```

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

```cmake
include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/External_B.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/External_A.cmake")

```

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)`?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [December 29, 2020, 5:36am UTC](https://discourse.cmake.org/t/externalproject-add-project-that-depends-on-other-external-project/2437/2 "2020-12-29T05:36:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kerim](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/6f9a4e/32.png) [@kerim](https://discourse.cmake.org/u/kerim)\
**Post date:** [December 29, 2020, 7:33am UTC](https://discourse.cmake.org/t/externalproject-add-project-that-depends-on-other-external-project/2437/3 "2020-12-29T07:33:05Z")

</div>

Thank you a lot for the help!
