# Hard time understanding depencies/action mechanism

**URL:** https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290
**Category:** Code
**Created:** [December 1, 2019, 8:07am UTC](https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290 "2019-12-01T08:07:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Phi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/phi/32/206_2.png) [@Phi](https://discourse.cmake.org/u/Phi)
#### Post date: [December 1, 2019, 8:07am UTC](https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290/1 "2019-12-01T08:07:47Z")

</div>

Hi All,

New to cmake, trying to migrate a big project from make to cmake.

At the moment I try to understand how dependencies works.

I posted this on stackoverflow with very few views and no valid answers, may be posting here will bring more luck 🙂

In the stko post I used a basic example where I use ld -r on purpose as a tool that build 1 file based on a set of input files. Very often cmake post ask why not using add\_lib() add\_exe() etc, this is because I try to understand dep/act mechanism to run my tools on set of input (lex, yacc for instance but not limited to)

In my example in stackoverflow post, I can build successfully the initial build but can not touch 1 .c file and rebuild what’s need to be rebuild. Hope one can help me.

[https://stackoverflow.com/questions/59118188/cmake-dependency-not-trigged](https://stackoverflow.com/questions/59118188/cmake-dependency-not-trigged)

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [December 1, 2019, 11:30am UTC](https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290/2 "2019-12-01T11:30:48Z")

</div>

Applying this diff to your example project should solve your issue:

```diff
@@ -10,6 +10,7 @@
 COMMAND rm -f l.a
 COMMAND ar r l.a l.o
 COMMAND rm -f l.o
+DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libs/l1/l1.o ${CMAKE_CURRENT_BINARY_DIR}/libs/l2/l2.o
 DEPENDS L1 L2
 )

```

This is basically what [Tsyvarev](https://stackoverflow.com/users/3440745/tsyvarev) proposed on Stack Overflow, but taking into account that the `DEPENDS` argument of `add_custom_command` works with files that live in either the source tree and the binary tree, so you need to give an absolute path.

---

<div class="post-metadata">

### Author: ![Phi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/phi/32/206_2.png) [@Phi](https://discourse.cmake.org/u/Phi)
#### Post date: [December 1, 2019, 5:07pm UTC](https://discourse.cmake.org/t/hard-time-understanding-depencies-action-mechanism/290/3 "2019-12-01T17:07:44Z")

</div>

Thax Alain, I applied this changes and various typos on SO, and we have now a running example.

I’m back on business 😀  
Cheers  
Phi
