CMakeDetermineRCCompiler can not set correct extension when cross compiling

Environment

OS: Debian 12.2.0

cmake: 3.25.1

compiler tools: x86_64-w64-mingw32

issue

I’m cross-compiling a desktop program for windows on a linux platform

I want to add app icon using add_executable like

add_executable(${DEMO_NAME} ${src_files} ${inc_files} ${RCC_SOURCES} main.cpp icon.rc)

icon.rc is the app icon

I set CMAKE_RC_COMPILER as x86_64-w64-mingw32-windres for it to compile

set(CMAKE_RC_COMPILER /bin/x86_64-w64-mingw32-windres)
set(CMAKE_RC_COMPILE_OBJECT
	"<CMAKE_RC_COMPILER> -i <SOURCE> -o <OBJECT>")
enable_language(RC)

By the way, I need to set CMAKE_RC_COMPILE_OBJECT manually to set the out put file

When I build it, I got error

icon.rc.res: file not recognized: file format not recognized

The suffix was incorrectly set to .res, it should be .obj or .o

I try to set CMAKE_RC_OUTPUT_EXTENSION to modify the extension

set(CMAKE_RC_OUTPUT_EXTENSION .o)

But the extension is still .res, this doesn’t work

CMAKE_RC_OUTPUT_EXTENSION doesn’t work

cause

get_filename_component(_CMAKE_RC_COMPILER_NAME_WE ${CMAKE_RC_COMPILER} NAME_WE)
if(_CMAKE_RC_COMPILER_NAME_WE STREQUAL "windres")
  set(CMAKE_RC_OUTPUT_EXTENSION .obj)
else()
  set(CMAKE_RC_OUTPUT_EXTENSION .res)
endif()

This problem is caused by this file.

If the compiler name equals ‘windres’, the extension will be .obj

but it doesn’t work for other cross compile windres like x86_64-w64-mingw32-windres

I have two suggestions

  1. if(_CMAKE_RC_COMPILER_NAME_WE STREQUAL "windres")
    it should not be equal here, it may be MATCHES "*windres" or something like endwith

  2. If possible, I think CMAKE_RC_OUTPUT_EXTENSION should not be set here

    This will affect the user’s setting of CMAKE_RC_OUTPUT_EXTENSION

This makes sense to me. Can you please file an issue?