Skip to content

Windows: Ninja incorrectly passes whitespace-containing-path to windres.exe and cc1.exe

I encountered this error when building a executable with windows .rc file on windows. I'm using cmake 3.25.0, with ninja 1.11.1 as generator, and MinGW 12.2.0 as compiler. But I found that windres failed to build rc objects.

The reason is that, there are some pathes contains whitespaces, and they are not wrapped with quotations when passed to cc1.exe, so cc1.exe received incorrect pathes because they are spilited by whitespaces.

I have tried MinGW Makefiles as generator, and this bug doesn't occur, the rc object can be built successfully.

Example for reappearance

Here 's a simpilest example contatining 3 files. Whitespaces are introduced by OpenCL, because on my PC it is installed at C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.0, that contains lots of whitespaces. build.ninja is also uploaded. build.ninja

#CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(test_white_space VERSION 0.1.0)

find_package(OpenCL REQUIRED)

add_executable(test_white_space main.cpp rc.rc)
target_link_libraries(test_white_space OpenCL::OpenCL)
//main.cpp
#include <CL/cl.hpp>
#include <iostream>

int main(int, char **) {
  cl::Device dev;
  std::cout << "Hello, world!\n";
}
/* rc.rc */
#include <windows.h>

VS_VERSION_INFO VERSIONINFO
	FILEVERSION 0,0,0,0
	PRODUCTVERSION 0,0,0,0
	FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
	FILEFLAGS VS_FF_DEBUG
#else
	FILEFLAGS 0x0L
#endif
	FILEOS VOS_NT_WINDOWS32
	FILETYPE VFT_DLL
	FILESUBTYPE VFT2_UNKNOWN
	BEGIN
		BLOCK "StringFileInfo"
		BEGIN
			BLOCK "000404b0"
			BEGIN
				VALUE "CompanyName", "XXX\0"
				VALUE "FileDescription", "XXX\0"
				VALUE "FileVersion", "0.0.0.0\0"
				VALUE "LegalCopyright", "XXX\0"
				VALUE "OriginalFilename", "XXX\0"
				VALUE "ProductName", "XXX\0"
				VALUE "ProductVersion", "0.0.0.0\0"
				VALUE "InternalName", "XXX\0"
				VALUE "Comments", "XXX\0"
				VALUE "LegalTrademarks", "XXX\0"
			END
		END
		BLOCK "VarFileInfo"
		BEGIN
			VALUE "Translation", 0x0004, 1200
		END
	END
/* End of Version info */

I configure and build it with following command:

D:\ProgramFiles\CMake\bin\cmake.EXE -G Ninja --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:/ProgramFilesU/gcc-compilers/mingw-gcc12/bin/g++.exe -SD:/Git/test_ninja_space -Bd:/Git/build-test_ninja_space-win
D:\ProgramFiles\CMake\bin\cmake.EXE --build d:/Git/build-test_ninja_space-win --config Debug --target all --parallel --

This project is configured successfully, but following errors occur when building:

[build] [2/3  33% :: 0.086] Building RC object CMakeFiles/test_white_space.dir/rc.rc.obj
[build] FAILED: CMakeFiles/test_white_space.dir/rc.rc.obj 
[build] D:\ProgramFilesU\gcc-compilers\mingw-gcc12\bin\windres.exe -O coff  -I "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.0/include"  D:/Git/test_ninja_space/rc.rc CMakeFiles/test_white_space.dir/rc.rc.obj
[build] cc1.exe: fatal error: Files/NVIDIA\: No such file or directory
[build] compilation terminated.
[build] cc1.exe: fatal error: GPU\: No such file or directory
[build] compilation terminated.
[build] cc1.exe: fatal error: Computing\: No such file or directory
[build] compilation terminated.
[build] cc1.exe: fatal error: Toolkit/CUDA/v12.0/include: No such file or directory
[build] compilation terminated.
[build] D:\ProgramFilesU\gcc-compilers\mingw-gcc12\bin\windres.exe: preprocessing failed.
[build] [2/3  66% :: 1.036] Building CXX object CMakeFiles/test_white_space.dir/main.cpp.obj
[build] ninja: build stopped: subcommand failed.
[proc] The command: D:\ProgramFiles\CMake\bin\cmake.EXE --build d:/Git/build-test_ninja_space-win --config Debug --target all --parallel -- exited with code: 1
[build] Build finished with exit code 1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information