# Partial build, even for a single top-level target?

**URL:** https://discourse.cmake.org/t/partial-build-even-for-a-single-top-level-target/4535
**Category:** Usage
**Created:** [November 23, 2021, 6:01pm UTC](https://discourse.cmake.org/t/partial-build-even-for-a-single-top-level-target/4535 "2021-11-23T18:01:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Stefaan](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@Stefaan](https://discourse.cmake.org/u/Stefaan)
#### Post date: [November 23, 2021, 6:01pm UTC](https://discourse.cmake.org/t/partial-build-even-for-a-single-top-level-target/4535/1 "2021-11-23T18:01:08Z")

</div>

Hi!  
I really like how modern CMake allows adding sources to a top-level target, from within a subdirectory. Before this, (I think) I needed to have per-subdirectory library targets defined, to have subdir CMakeLists.txt for a top-level executable.

However, now I’m missing the advantage, especially for very large projects, of being able to compile the sources for a subdirectory only (useful e.g. when working on a widely used header): running make in the (binary) subdirectory doesn’t trigger any compiles at all.

How can I trigger rebuilding sources within a subdir only, even when I have a single top-level target?  
Thanks

ps: working on Linux, have tried this with makefile and ninja targets

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 24, 2021, 2:31am UTC](https://discourse.cmake.org/t/partial-build-even-for-a-single-top-level-target/4535/2 "2021-11-24T02:31:59Z")

</div>

Only the `Makefiles` targets supported this before (though maybe the `Ninja` generator has it now?). But these are tied to where the `add_subdirectory` happens and targets are “anchored” to the directory where they are defined. If you want something in between, I suggest `OBJECT` libraries.
