CMake: Fix Windows build with Clang/LLVM 17.

llvm-windres 17.0.0 has more accurate emulation of GNU windres, so
the hack for GNU windres must now be used with llvm-windres too.

LLVM 16.0.6 has the old behavior and there likely won't be more
16.x releases. So we can simply check for >= 17.0.0.

See also:
2bcc0fdc58
This commit is contained in:
Lasse Collin 2023-09-27 19:54:35 +03:00
parent 5a9af95f85
commit 0570308ddd
1 changed files with 14 additions and 12 deletions

View File

@ -93,19 +93,21 @@ set(CMAKE_MACOSX_BUNDLE OFF)
# "syntax error" from windres. Using --use-temp-file prevents windres # "syntax error" from windres. Using --use-temp-file prevents windres
# from using popen() and this seems to fix the problem. # from using popen() and this seems to fix the problem.
# #
# llvm-windres claims to be compatible with GNU windres but with that # llvm-windres from Clang/LLVM 16.0.6 and older: The \x20 results
# the \x20 results in "XZx20Utils" in the compiled binary. (At the # in "XZx20Utils" in the compiled binary. The option --use-temp-file
# same time it works correctly with clang (the C compiler).) The option # makes no difference.
# --use-temp-file makes no difference.
# #
# CMake 3.25 doesn't have CMAKE_RC_COMPILER_ID so we rely on # llvm-windres 17.0.0 and later: It emulates GNU windres more accurately, so
# CMAKE_C_COMPILER_ID. If Clang is used together with GNU windres # the workarounds used with GNU windres must be used with llvm-windres too.
# then it will fail, but this way the risk of a bad string in #
# the binary should be fairly low. # CMake 3.27 doesn't have CMAKE_RC_COMPILER_ID so we rely on
if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "GNU") # CMAKE_C_COMPILER_ID.
# Use workarounds with GNU windres. The \x20 in PACKAGE_NAME works if(WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR (
# with gcc too so we don't need to worry how to pass different flags CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
# to windres and gcc. CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "17")))
# Use workarounds with GNU windres and llvm-windres >= 17.0.0. The \x20
# in PACKAGE_NAME works with gcc and clang too so we don't need to worry
# how to pass different flags to windres and the C compiler.
string(APPEND CMAKE_RC_FLAGS " --use-temp-file") string(APPEND CMAKE_RC_FLAGS " --use-temp-file")
set(PACKAGE_NAME "XZ\\x20Utils") set(PACKAGE_NAME "XZ\\x20Utils")
else() else()