Browse Source

MinGW: Fix regression when windres is not found

The fix in commit e9755bc7c1 (MinGW: Restore using windres when
toolchain-prefixed name is not available, 2022-08-15, v3.24.1~4^2)
incorrectly listed two entries in `CMAKE_RC_COMPILER_INIT`, which is
only meant to have one value.  Revise the logic to support multiple
platform-specific names for the Windows Resource Compiler while still
only using one name as the fallback when it is not found.

Fixes: #24190
Issue: #23841
Brad King 3 years ago
parent
commit
b47092fddb
2 changed files with 11 additions and 7 deletions
  1. 9 6
      Modules/CMakeDetermineRCCompiler.cmake
  2. 2 1
      Modules/Platform/Windows-GNU.cmake

+ 9 - 6
Modules/CMakeDetermineRCCompiler.cmake

@@ -30,16 +30,19 @@ if(NOT CMAKE_RC_COMPILER)
 
   # finally list compilers to try
   if(CMAKE_RC_COMPILER_INIT)
-    set(CMAKE_RC_COMPILER_LIST ${CMAKE_RC_COMPILER_INIT})
-  else()
-    set(CMAKE_RC_COMPILER_LIST rc)
+    set(_CMAKE_RC_COMPILER_LIST     ${CMAKE_RC_COMPILER_INIT})
+    set(_CMAKE_RC_COMPILER_FALLBACK ${CMAKE_RC_COMPILER_INIT})
+  elseif(NOT _CMAKE_RC_COMPILER_LIST)
+    set(_CMAKE_RC_COMPILER_LIST rc)
   endif()
 
   # Find the compiler.
-  find_program(CMAKE_RC_COMPILER NAMES ${CMAKE_RC_COMPILER_LIST} DOC "RC compiler")
-  if(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER)
-    set(CMAKE_RC_COMPILER "${CMAKE_RC_COMPILER_INIT}" CACHE FILEPATH "RC compiler" FORCE)
+  find_program(CMAKE_RC_COMPILER NAMES ${_CMAKE_RC_COMPILER_LIST} DOC "RC compiler")
+  if(_CMAKE_RC_COMPILER_FALLBACK AND NOT CMAKE_RC_COMPILER)
+    set(CMAKE_RC_COMPILER "${_CMAKE_RC_COMPILER_FALLBACK}" CACHE FILEPATH "RC compiler" FORCE)
   endif()
+  unset(_CMAKE_RC_COMPILER_FALLBACK)
+  unset(_CMAKE_RC_COMPILER_LIST)
 endif()
 
 mark_as_advanced(CMAKE_RC_COMPILER)

+ 2 - 1
Modules/Platform/Windows-GNU.cmake

@@ -157,7 +157,8 @@ macro(__windows_compiler_gnu lang)
   endif()
 
   if(NOT CMAKE_RC_COMPILER_INIT AND NOT CMAKE_GENERATOR_RC)
-    set(CMAKE_RC_COMPILER_INIT ${_CMAKE_TOOLCHAIN_PREFIX}windres windres)
+    set(_CMAKE_RC_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}windres windres)
+    set(_CMAKE_RC_COMPILER_FALLBACK windres)
   endif()
 
   enable_language(RC)