# difference between a build cache and a build dependency

**URL:** https://discourse.cmake.org/t/difference-between-a-build-cache-and-a-build-dependency/3540
**Category:** Usage
**Created:** [June 9, 2021, 1:06pm UTC](https://discourse.cmake.org/t/difference-between-a-build-cache-and-a-build-dependency/3540 "2021-06-09T13:06:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hex/32/363_2.png) [@hex](https://discourse.cmake.org/u/hex)
#### Post date: [June 9, 2021, 1:06pm UTC](https://discourse.cmake.org/t/difference-between-a-build-cache-and-a-build-dependency/3540/1 "2021-06-09T13:06:26Z")

</div>

a build dependency defines dependencies between objects

```cmake
add_custom_target(target_name DEPENDS /path/to/objectfile)

```

by using a file dependency CMake improves compilation performance by avoiding unnecessary recompilation. Or, perhaps the generated build system does that.

apart from offering lots of features and control, a build cache does this as well.

So, how is a compiler cache any different from what Make already does? Is it seen as a replacement or an extension of behaviour?

---

<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: [June 9, 2021, 1:24pm UTC](https://discourse.cmake.org/t/difference-between-a-build-cache-and-a-build-dependency/3540/2 "2021-06-09T13:24:05Z")

</div>

They work together. A build cache tool (such as `ccache` or `sccache`) can “remember” compilation output from prior runs. With just `make`, running `git checkout $other_branch` followed by `git checkout $prior_branch` will cause all files changed due to the switch to recompile (because timestamps changed). A compiler cache can remember that `$prior_branch` has been compiled before and skip the actual compilation by pulling the output from the cache instead.
