Why is Ninja not compiling my RC file correctly?
09:48 06 Feb 2026

I am using the MSys posix shell for convenience, and am using CMake with Ninja and MSVC. I have a minimum viable project like this:

CMakeLists.txt:

cmake_minimum_required (VERSION 3.16)


project(test CXX)


add_executable(test
    main.cpp
    test.rc
)

main.cpp:

int main(int argc, char **rgv)
{
    return 0;
}

test.rc:

#include 

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK

I run CMake like so:

mkdir BUILD
cd BUILD
cmake -G "Ninja" -DCMAKE_SYSROOT="${MSVC_ROOT}" -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_FIND_ROOT_PATH="${MSVC_ROOT}" -D CMAKE_BUILD_TYPE=Debug ..

When I then use the ninja command to build I get the following output:

[1/3] Building RC object CMakeFiles\test.dir\test.rc.res
FAILED: [code=1] CMakeFiles/test.dir/test.rc.res
RC C:\msys64\home\AlastairAdmin\Work\rc_test\test.rc CMakeFiles\test.dir\test.rc.res.d CMakeFiles\test.dir\test.rc.res "Note: including file: " "cl.exe" C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe   -DWIN32 -D_DEBUG /fo CMakeFiles\test.dir\test.rc.res C:\msys64\home\AlastairAdmin\Work\rc_test\test.rc
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.

fatal error RC1107: invalid usage; use RC /? for Help
[2/3] Building CXX object CMakeFiles\test.dir\main.cpp.obj
ninja: build stopped: subcommand failed.

If I delete everything up to the \ before rc.exe, escape all the \ then this is what happens:

$ rc -DWIN32 -D_DEBUG /fo CMakeFiles\\test.dir\\test.rc.res C:\\msys64\\home\\AlastairAdmin\\Work\\rc_test\\test.rc
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.

So the basic command is right. The problem seems to be the preamble that Ninja is adding at the beginning:

RC C:\msys64\home\AlastairAdmin\Work\rc_test\test.rc CMakeFiles\test.dir\test.rc.res.d CMakeFiles\test.dir\test.rc.res "Note: including file: " "cl.exe"
cmake ninja