ARTICLE AD BOX
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 <windows.h> LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UKI run CMake like so:
mkdir BUILD cd BUILD cmake -G "Ninja" ..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.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.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"UPDATE:
After exploring a bit I found the file rules.ninja which contains this:
rule RC_COMPILER__test_unscanned_Debug depfile = $DEP_FILE deps = gcc command = RC $in $DEP_FILE $out "Note: including file: " "C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe" ${LAUNCHER}${CODE_CHECK}C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe $DEFINES $INCLUDES $FLAGS /fo $out $in description = Building RC object $outIf I change that to:
rule RC_COMPILER__test_unscanned_Debug depfile = $DEP_FILE deps = gcc command = ${LAUNCHER}${CODE_CHECK}C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe $DEFINES $INCLUDES $FLAGS /fo $out $in description = Building RC object $outthen everything works fine.
So it looks like CMake is generating the rules.ninja file incorrectly.
FURTHER UPDATE:
I have noticed that the rules.ninja I posted above is specifying gcc for its dependencies format. I added set(CMAKE_RC_DEPFILE_FORMAT msvc) to my CMakeLists.txt file and it made no difference.
If I remove main.cpp and change the project language to RC then the rules.ninja is correct and the project builds.
