Ninja: CMake throws 'fatal error: opening dependency file' on Windows
Out of all targets, only one target fails with compilation error for CMake v3.20.2 with ninja generators (ninja 2.10.0) on Windows:
arm-none-eabi-gcc.exe -IINCLUDE_DIRS -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -MMD -MP -fno-exceptions -fno-non-call-exceptions -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -std=gnu99 -O3 -DNDEBUG -flto -fno-fat-lto-objects -mthumb -mapcs -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -MMD -MP -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -fno-exceptions -fno-non-call-exceptions -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -MD -MT CMakeFiles/TARGET.dir/PATH_TO_FILE/xfile.c.obj.d.obj -MF CMakeFiles\TARGET.dir\PATH_TO_FILE\xfile.c.obj.d -o CMakeFiles/TARGET.dir/PATH_TO_FILE/xfile.c.obj -c C:/Users/PATH_TO_FILE/xfile.c CMakeFiles/TARGET.dir/PATH_TO_FILE/xfile.c.obj.d:502:1: fatal error: opening dependency file CMakeFiles/TARGET.dir/PATH_TO_FILE/xfile.c.obj.d: No such file or directory compilation terminated.
It works fine with other generators on windows. This also works fine on Ubuntu 20.04 with same CMake and ninja versions. xfile.c.obj.d is not generated in the CMakefiles directory for the target. This only happens for this one file. The path length for the file is 168 characters, so it also does not exceeds max path length on windows.