In short: Is there a way to generate and use dynamic explicit dependencies during build time for targets and/or custom commands?
In long:
Let’s use C++20 modules for example: compiling a source file will generate two outputs: a object file and an interface file that is required to compile other sources file that import it.
Then the compilation of a source file should dynamically explicitly depend on all interfaces of the sources it imports.
foreach(src ${sources})
add_custom_command(
OUTPUT ${src}.interface ${src}.object
COMMAND ${compiler} ${src}
DEPENDS ???
)
endforeach()
A script can be written to discover these dependencies during build time, but how can I tell CMake to use these explicit dependencies?
add_custom_command
has a DEPFILE
option but it is very limited for only implicit dependencies similar to equivalent GNU’s -MF
flags. So it is not up to this task.
If I understand correctly, CMake have to solve the same problem for supporting C++20 modules. How does/will CMake solve it and can I use the that for custom commands?