# CMakeDetermineRCCompiler can not set correct extension when cross compiling

**URL:** https://discourse.cmake.org/t/cmakedeterminerccompiler-can-not-set-correct-extension-when-cross-compiling/9365
**Category:** Usage
**Tags:** os:linux, comp:mingw
**Created:** [November 4, 2023, 10:26pm UTC](https://discourse.cmake.org/t/cmakedeterminerccompiler-can-not-set-correct-extension-when-cross-compiling/9365 "2023-11-04T22:26:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![UrMyLacia](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/u/51bf81/32.png) [@UrMyLacia](https://discourse.cmake.org/u/UrMyLacia)
#### Post date: [November 4, 2023, 10:26pm UTC](https://discourse.cmake.org/t/cmakedeterminerccompiler-can-not-set-correct-extension-when-cross-compiling/9365/1 "2023-11-04T22:26:47Z")

</div>

# 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

```auto
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

> <https://github.com/Kitware/CMake/blob/3a467f0f8eb043cf48422f28121d600a49016f88/Modules/CMakeDetermineRCCompiler.cmake#L50-L55>

```cmake
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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 17, 2023, 1:40pm UTC](https://discourse.cmake.org/t/cmakedeterminerccompiler-can-not-set-correct-extension-when-cross-compiling/9365/2 "2023-11-17T13:40:25Z")

</div>

This makes sense to me. Can you please [file an issue](https://gitlab.kitware.com/cmake/cmake/-/issues)?
