I have custom source files that are not C/C++. These files are compiled to C source files and then those C files are compiled by cmake as usual.
However, my custom files can have dependencies that can change during development.
For example let us say the I have the files source1.lang
, source2.lang
, source3.lang
...
source1.lang
... some code
source2.lang
import source1;
... some code
I compile these files as
./langc source1.lang
./langc source2.lang
...
and I get source1.c
, source2.c
...
Now, as you can see source2.lang
depends on source1.lang
. I can find these dependencies for these custom files at any time by pre-processing them. And then generate an explicit dependency of source2.lang
on source1.lang
so that it gets recompiled if source1.lang
is modified.
Right now, I have a custom command like this
# This is populated automatically.
set(SOURCE2_DEPENDS source2.lang source1.lang)
add_custom_command(
DEPENDS ${SOURCE2_DEPENDS }
COMMAND ./langc source2.lang
OUTPUT source2.c
COMMENT "Compiling source2.c"
)
The problem is the dependencies can change during development. That is, SOURCE1_DEPENDS
can change after configuration. For example I can modify source2.lang
to import source3.lang
source2.lang
import source1;
import source3;
... some code
I can now see that source2.lang
is modified. So I pre-process it to find the new dependencies. But how do I let cmake know that the dependency has changed?
The only way I can see so far is for Makefile generators to modify the generated build.make file to add and remove these dependencies manually.
However, how I can I tell cmake in a generic way that these are the new dependencies?
Basically as cmake does normally when you add a new #include
to a C source file. So that things work for other generators as well.