# CMake to replace Eclipse CDT GNU - how to deal with C\_DEPS?

**URL:** <https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917>\
**Category:** Code\
**Created:** [September 26, 2020, 8:23am UTC](https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917 "2020-09-26T08:23:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![swoo.quek](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@swoo.quek](https://discourse.cmake.org/u/swoo.quek)\
**Post date:** [September 26, 2020, 8:23am UTC](https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917/1 "2020-09-26T08:23:43Z")

</div>

I am using Eclipse CDT with GNU Make  
In the project makefile, there are these lines:

> -include $(C\_DEPS)

where:

> C\_DEPS += time\_cx/src/time\_cx.d

where time\_cx.d is:

> time\_cx/src/time\_cx.obj time\_cx/src/time\_cx.d: …/time\_cx/src/time\_cx.c  
> …  
> time\_cx/src/time\_cx.obj time\_cx/src/time\_cx.d: C:\WS\timer\time\_cx\time\_cx.h  
> C:\WS\timer\time\_cx\time\_cx.h:  
> …

So essentially C\_DEPS has the dependencies information of each \*.obj file  
eg: **time\_cx.obj** has pre-requisite **time\_cx.h**

I want to generate makefile for this project using CMake (not using CDT builder). How do I incorporate **C\_DEPS** in **CMakeLists.txt**?

Purpose:  
I want the project to be re-built everytime when **time\_cx.h** is changed and **make all** is executed; **time\_cx.obj** will be re-generated

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [September 27, 2020, 2:20pm UTC](https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917/2 "2020-09-27T14:20:38Z")

</div>

With `CMake`, dependencies are managed automatically: no need to manage them manually.

---

<div class="post-metadata">

**Author:** ![swoo.quek](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/94ad74/32.png) [@swoo.quek](https://discourse.cmake.org/u/swoo.quek)\
**Post date:** [September 27, 2020, 3:40pm UTC](https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917/3 "2020-09-27T15:40:44Z")

</div>

Dear Marc,

How does CMake manage it automatically?  
In my above example, if time\_cx.h have been modified, how can we make sure that the next time I run “make all” (without running CMake again), only time\_cx.c is compiled (to obj file), and then linking to produce the final binary file?  
Do you have an simple example?  
Thank you,  
s.q

---

<div class="post-metadata">

**Author:** ![madscientist](https://discourse.cmake.org/user_avatar/discourse.cmake.org/madscientist/32/109_2.png) [@madscientist](https://discourse.cmake.org/u/madscientist)\
**Post date:** [September 27, 2020, 6:19pm UTC](https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917/4 "2020-09-27T18:19:46Z")

</div>

I don’t know exactly how the cmake makefile generator sets this up but typically it would make use of the compiler’s extra options to generate make dependency files.

You can find some info here: [http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/](http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/)

I don’t know if cmake makefiles use exactly that method (probably not because they don’t use GNU make-specific features, IIRC) but they likely use something similar.

---

<div class="post-metadata">

**Author:** ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)\
**Post date:** [September 27, 2020, 6:41pm UTC](https://discourse.cmake.org/t/cmake-to-replace-eclipse-cdt-gnu-how-to-deal-with-c-deps/1917/5 "2020-09-27T18:41:51Z")

</div>

> [@swoo.quek](#):
>
> How does CMake manage it automatically?

CMake has a builtin dependency scanner for officially supported languages (at least C, C++, Fortran and Java), have a look at cmDependsXXX.\* in the source code:  
[https://gitlab.kitware.com/cmake/cmake/-/tree/master/Source](https://gitlab.kitware.com/cmake/cmake/-/tree/master/Source)

I’m sure there is a lot of nasty details I am not aware of about this but basically it’ll scan for included files in order to track down the dependencies.

Have a look here too:

FAQ: [https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#cmake-dependency-scanner](https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#cmake-dependency-scanner)  
Oldish discussion about CMake deps scanning: [https://cmake.org/pipermail/cmake/2010-June/037805.html](https://cmake.org/pipermail/cmake/2010-June/037805.html)
