CMP0116 outputs broken paths when confronted with escaped windows paths
Hi,
I am using CMake together with the Ninja build system in a Windows environment. I tried to get depfiles running together with Slang and ran into a path transformation issue that is caused by CMP0116/cmake_transform_depfile
, where Windows paths containing escaped colons are transformed wrongly. Slang and other tools are escaping the colons of paths to resolve the ambiguities that otherwise may occur in dependency files that follow the path/to/rule: path/to/dependency0 dependency1 ...
syntax. Escaped colons also are supported when Ninja parses the depfile.
Simplified reproducer for the problem, reproduces using Windows 10 Enterprise 22H2 using CMake 3.29.2:
Example input dependency file e:\foo.d
:
e\:\\foo.cpp: e\:\\foo.cpp
Transforming this through cmake_transform_depfile
on a windows machine with absolute paths by calling e.g. cmake.exe -E cmake_transform_depfile Ninja gccdepfile E:/ E:/src E:/build E:/src E:/foo.d E:/foo.d_new
produces:
E:/src/e/:/foo.cpp: \
E:/foo.cpp
Here the rule is wrongly prefixed with E:/src/
as CMakes logic assumes that the path is relative. Also, the escape backslash gets converted to a forward backslash.
I put a fix together that both fixes parsing and generating of depfiles containing escaped colons, find it here. I did not include regeneration of the lexers, so you need to run the Utilities\Scripts\regenerate-lexers.bash
script after applying the patch.
Thanks for having a look into this!