llvm-rc: Compiling RC files no longer finds adjacent data files
When compiling Windows RC files on the Windows-Clang platform, with llvm-rc, the folder of the resource is not added to the resource compiler include path.
This is a fairly serious bug for projects using Windows RC files that are compiled with the Windows-Clang platform and in particular
llvm-rc, caused by !4219 (merged).
When compiling a Windows resource file with
llvm-rc, CMake used to simply invoke
llvm-rc on that resource file in its original source folder.
Since that patch, CMake instead invokes its own command-line tool
cmake_llvm_rc that does two steps:
- preprocess that resource file into an intermediary preprocessed resource file, somewhere in the CMakeFiles build folder
llvm-rcon that new file.
The cause of the bug is that
llvm-rc now processes the resource file in the new folder, rather than in its original source folder.
Now consider a project where a resource file
resource.rc references a resource
resource.dat in its current directory, like so (this is not an edge-case, it is a typically way to reference and include a resource file into an executable):
4 RCDATA "resource.dat"
To look up the reference file in order to read it,
llvm-rc mimicks the original behaviour of the Windows Resource Compiler and looks up paths in the following order:
- if the file path is absolute and exists, try to use that; otherwise:
- search in the current working directory
- search in the directory of the input resource file
- search in all of the include directories specified on the command line
The path used to be matched by the third case (search in the directory of the input resource file), because that direcotry was indeed the directory that contained the resource file and in our example the resource as well.
But now, the directory of the input resource file has changed and is now inside the CMakeFiles folder which does not contain the resource. So none of the paths contain that resource and the file cannot be looked up, resulting in a build failure.
To me the simplest way to fix this would be to add to the include directories specified on the command line of
llvm-rc, the path of the folder containing the original resource file. Specifically perhaps modify that line in Platform/Windows-Clang.cmake to add a
/I <SOURCE_DIR> where
SOURCE_DIR is the folder containing