I expect, that I will populate .d file during my script first launch and later custom command will be rerun only when one of files listed after colon will change. Instead command is running during every compilation, even with empty dependencies list. Printing my own sources during cmake run also leads me to constant command rerunning. What am I doing (or understanding) wrong?
Due to Ninja behavior, it seems that a dep file without any dependencies (so exactly what you have in your example) imply that the command is rerun at each launch.
Now, I jus tested that, when a depfile have some dependencies, the command is run just the first time. In your case, are you sure that the depfile you generate has the correct format?
The format is explained here, under DEPFILE option.
Space is OK as separator. But are you sure that all files specified as dependencies exist? Moreover, the depfile is transformed by CMake before to be consumed by ninja. Can you check the effective file used by ninja? This file is under <build-dir>/CMakeFiles/d directory.
Maybe toolchain we are using isn’t the latest, but ninja -d explain messages was clear, they said, that there was absolute path where relative one was expected and when I fixed it - everything was ok.