# Integrating ExternalProject\_Add() with generate-phase target dependencies

**URL:** https://discourse.cmake.org/t/integrating-externalproject-add-with-generate-phase-target-dependencies/15584
**Category:** Usage
**Tags:** os:linux
**Created:** [March 30, 2026, 7:03pm UTC](https://discourse.cmake.org/t/integrating-externalproject-add-with-generate-phase-target-dependencies/15584 "2026-03-30T19:03:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![wdezell](https://discourse.cmake.org/user_avatar/discourse.cmake.org/wdezell/32/6081_2.png) [@wdezell](https://discourse.cmake.org/u/wdezell)
#### Post date: [March 30, 2026, 7:03pm UTC](https://discourse.cmake.org/t/integrating-externalproject-add-with-generate-phase-target-dependencies/15584/1 "2026-03-30T19:03:17Z")

</div>

**Background**

I have a large project organized as 20+ repos, one being the logical “parent” from which the CMake project is homed and `add_subdirectory()` calls chain in the rest, save one. That repo homes a customer-provided simulation that performs an in-tree build controlled by one top-level Korn shell script. Until now we’ve manually run its build beforehand so that the necessary generated artifacts will be present for pickup when our top-level CMake launches CPack to build a Deb for us (we install and configure their sim as sort of a peripheral for our app).

**Problem**

We now have a new wrinkle where we need to sequence the build roughly as follows:

1. Execute build of some of our targets, which modify a few source files of the vendor sim

2. Kick off the non-CMake in-tree build of the vendor sim at the right point in the sequence Edit: block 3 until 2 done

3. Consume a few generated artifacts in building our final targets before packaging begins

We employ `add_dependencies()` in several places to control the ordering of our own target builds. I’m also using `ExternalProject_Add()` to build a CMake-based third-party tool from tree-local sources. I think I have the right control mechanisms but can’t quite make them play together. I’m struggling with (I think) the two following points:

A. `ExternalProject_Add()` will run at _build_ time. I’m not sure how the CMake sequence-planning logic during the **generate** phase can work it into the correct spot

B. For some reason, perhaps this external project not being CMake-based as is our other (wild guess), CMake seems to want me to include a `project()`statement in the controlling `CMakeLists.txt` file where the External Project is defined. If I do, I put the target name into a separate scope and certainly can’t satisfy ‘ **A** ’ (above).

When things get this convoluted I’m usually trying to do something stupid, but this seems like something that should be commonplace, and so doable. Can anyone advise how?
