diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2023-09-27 19:54:35 +0300 |
---|---|---|
committer | Jia Tan <jiat0218@gmail.com> | 2023-10-31 18:44:59 +0800 |
commit | 38171492ded6426ddf53d0c200fa8c93fcd02a60 (patch) | |
tree | f1bbc40e86f2c5c3b4b5b70f3e6c5c6aa9f4dae6 | |
parent | liblzma: Avoid compiler warning without creating extra symbol. (diff) | |
download | xz-38171492ded6426ddf53d0c200fa8c93fcd02a60.tar.xz |
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.
The workaround must not be used with Clang that is acting in
MSVC mode. This checks for the known environments that need
the workaround instead of using "NOT MSVC".
See also:
https://github.com/llvm/llvm-project/commit/2bcc0fdc58a220cb9921b47ec8a32c85f2511a47
-rw-r--r-- | CMakeLists.txt | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b36ee30f..7c3b6b33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,19 +94,21 @@ set(CMAKE_MACOSX_BUNDLE OFF) # "syntax error" from windres. Using --use-temp-file prevents windres # from using popen() and this seems to fix the problem. # -# llvm-windres claims to be compatible with GNU windres but with that -# the \x20 results in "XZx20Utils" in the compiled binary. (At the -# same time it works correctly with clang (the C compiler).) The option -# --use-temp-file makes no difference. +# llvm-windres from Clang/LLVM 16.0.6 and older: The \x20 results +# in "XZx20Utils" in the compiled binary. The option --use-temp-file +# makes no difference. # -# CMake 3.25 doesn't have CMAKE_RC_COMPILER_ID so we rely on -# CMAKE_C_COMPILER_ID. If Clang is used together with GNU windres -# then it will fail, but this way the risk of a bad string in -# the binary should be fairly low. -if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "GNU") - # Use workarounds with GNU windres. The \x20 in PACKAGE_NAME works - # with gcc too so we don't need to worry how to pass different flags - # to windres and gcc. +# llvm-windres 17.0.0 and later: It emulates GNU windres more accurately, so +# the workarounds used with GNU windres must be used with llvm-windres too. +# +# CMake 3.27 doesn't have CMAKE_RC_COMPILER_ID so we rely on +# CMAKE_C_COMPILER_ID. +if((MINGW OR CYGWIN OR MSYS) AND ( + NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" OR + 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") set(PACKAGE_NAME "XZ\\x20Utils") else() |