CMake RC Support (Ninja)?

I’m unable to compile a simple project Ninja. I’ve made a SSCCE to demonstrate the issue.

My command line is super basic:

 cmake -S . -B build -G "Ninja" -DCMAKE_MAKE_PROGRAM=D:\foobar\ninja.exe

Here are the files contents:

  • This is the CMakeLists.txt
cmake_minimum_required(VERSION 3.20)

project(demo)

add_executable(demo)

target_sources(demo PRIVATE
    main.cpp
    demo.rc
)
  • This is the RC file in question causing the havoc.
#include <winres.h>

// Little macro tricks this turn number defines into non-quoted strings
#define STRINGIZED_HELPER( a ) #a
#define STRINGIZED( a ) STRINGIZED_HELPER( a )

#define DEMO_VERSION_MAJOR 1
#define DEMO_VERSION_MINOR 2
#define DEMO_BRANCH_VERSION_LEVEL1 3
#define DEMO_BRANCH_VERSION_LEVEL2 4
#define DEMO_BRANCH "demo_shorty"

#define DEMO_VER_STR               STRINGIZED(DEMO_VERSION_MAJOR) "," STRINGIZED(DEMO_VERSION_MINOR) "," STRINGIZED(DEMO_BRANCH_VERSION_LEVEL1) "," STRINGIZED(DEMO_BRANCH_VERSION_LEVEL2) "\0"
#define FILEVER                     DEMO_VERSION_MAJOR,DEMO_VERSION_MINOR,DEMO_BRANCH_VERSION_LEVEL1,DEMO_BRANCH_VERSION_LEVEL2
#define PRODUCTVER                  DEMO_VERSION_MAJOR,DEMO_VERSION_MINOR,DEMO_BRANCH_VERSION_LEVEL1,DEMO_BRANCH_VERSION_LEVEL2
#define VS_PACKAGE_FILEVER          DEMO_VERSION_MAJOR,DEMO_VERSION_MINOR,DEMO_BRANCH_VERSION_LEVEL1,DEMO_BRANCH_VERSION_LEVEL2
#define VS_PACKAGE_PRODUCTVER       DEMO_VERSION_MAJOR,DEMO_VERSION_MINOR,DEMO_BRANCH_VERSION_LEVEL1,DEMO_BRANCH_VERSION_LEVEL2
#define STRFILEVER                  DEMO_VER_STR
#define STRPRODUCTVER               DEMO_VER_STR
#define VS_PACKAGE_STRFILEVER       DEMO_VER_STR
#define VS_PACKAGE_STRPRODUCTVER    DEMO_VER_STR
#define STRCOMPANYNAME              L"Foobar Inc.\0"
#define STRCOPYRIGHT                L"(C) 2015-2021 Foobar Inc. For internal use only.\0"
#define STRFILEDESCRIPTION          L"DEMO " DEMO_BRANCH " ver " DEMO_VER_STR "\0"
#define STRPRODUCTNAME              L"DEMO\0"
#define VS_PACKAGE_STRPRODUCTNAME   L"DEMO\0"

VS_VERSION_INFO VERSIONINFO
 FILEVERSION FILEVER
 FILEFLAGSMASK 0x3fL
 FILEFLAGS 0x0L
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904B0"
        BEGIN
            VALUE "CompanyName", STRCOMPANYNAME
            VALUE "FileDescription", STRFILEDESCRIPTION
            VALUE "FileVersion", DEMO_VER_STR
            VALUE "LegalCopyright", STRCOPYRIGHT
            VALUE "LegalTrademarks", "\0"
            VALUE "ProductName", STRPRODUCTNAME
            VALUE "ProductVersion", DEMO_BRANCH
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END
  • This is main.cpp
#include <stdio.h>

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

And I run this in a VS 2019 command prompt yet it fails:

It seems to be unable to find the appropriate environment for the RC/MT:
image

Worked fine for me:

You might have some scripts or some funny business messing up the environment path though. I’d double check that.

Here is a sample of what my cmake cache looked like:
CMakeCache.txt (14.2 KB)

I even got it working with clang

C:\git\rc_compiler_issue>cmake -S . -B build -G "Ninja" -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
-- The C compiler identification is Clang 11.0.0 with GNU-like command-line
-- The CXX compiler identification is Clang 11.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/git/rc_compiler_issue/build

C:\git\rc_compiler_issue>cmake --build build
[1/3] Building RC object CMakeFiles/demo.dir/demo.rc.res
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.

[3/3] Linking CXX executable demo.exe

C:\git\rc_compiler_issue>

Here is what the cache looks like for the clang path:
CMakeCache.txt (15.5 KB)

Usually this means that you forgot/missed the SDK installation in the Visual Studio installer. The compiler components are just the C/C++ compilers. The rc and mt tools come with the SDK (the binutils analogous bit).

It was a combination of not having enough stuff. As you mentioned @ben.boeckel

And due to work reasons having my path cluttered in an awkward way. As was mentioned by @anon45792294