CMake to replace Eclipse CDT GNU - how to deal with C_DEPS?

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

-include $(C_DEPS)


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

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?

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

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

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,

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:

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.

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:

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:

Oldish discussion about CMake deps scanning:

1 Like