CMake: Fix windres issues again.
At least on some systems, GNU windres needs --use-temp-file in addition to the \x20 hack to avoid spaces in the command line argument. Hovever, that \x20 syntax is broken with llvm-windres version 15.0.0 (results in "XZx20Utils") but luckily it works with a regular space. Thus it is best to limit the workarounds to GNU toolchain on Windows.
This commit is contained in:
parent
0c210ca7f4
commit
6b117d3b1f
|
@ -75,22 +75,33 @@ project(xz VERSION "${XZ_VERSION}" LANGUAGES C)
|
||||||
# On Apple OSes, don't build executables as bundles:
|
# On Apple OSes, don't build executables as bundles:
|
||||||
set(CMAKE_MACOSX_BUNDLE OFF)
|
set(CMAKE_MACOSX_BUNDLE OFF)
|
||||||
|
|
||||||
# String for PACKAGE_NAME macro in the C code and Windows resource files:
|
# windres from GNU binutils can be tricky with command line arguments
|
||||||
|
# that contain spaces or other funny characters. Unfortunately we need
|
||||||
|
# a space in PACKAGE_NAME. Using \x20 to encode the US-ASCII space seems
|
||||||
|
# to work in both cmd.exe and /bin/sh.
|
||||||
#
|
#
|
||||||
# windres from GNU binutils can be a bit tricky with command line arguments
|
# However, even \x20 isn't enough in all situations, resulting in
|
||||||
# that contain spaces or other funny characters because it will pass them
|
# "syntax error" from windres. Using --use-temp-file prevents windres
|
||||||
# to a shell (cmd.exe or /bin/sh). CMake doesn't seem to handle the quoting
|
# from using popen() and this seems to fix the problem.
|
||||||
# well enough either. Using \x20 to encode the US-ASCII space seems to work:
|
|
||||||
# it should be compatible with both shell types, it works also with llvm-rc,
|
|
||||||
# and CMake handles quoting the backslash too.
|
|
||||||
#
|
#
|
||||||
# For simplicity, use this workaround in all cases on Windows as it should
|
# llvm-windres claims to be compatible with GNU windres but with that
|
||||||
# do no harm with other toolchains. Outside Windows use a regular space as
|
# the \x20 results in "XZx20Utils" in the compiled binary. (At the
|
||||||
# then we are compatible with EBCDIC too (if it will ever matter with CMake;
|
# same time it works correctly with clang (the C compiler).) The option
|
||||||
# EBCDIC compatibility is important with the Autotools-based build though).
|
# --use-temp-file makes no difference.
|
||||||
if(WIN32)
|
#
|
||||||
|
# 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.
|
||||||
|
list(APPEND CMAKE_RC_FLAGS "--use-temp-file")
|
||||||
set(PACKAGE_NAME "XZ\\x20Utils")
|
set(PACKAGE_NAME "XZ\\x20Utils")
|
||||||
else()
|
else()
|
||||||
|
# Elsewhere a space is safe. This also keeps things compatible with
|
||||||
|
# EBCDIC in case CMake-based build is ever done on such a system.
|
||||||
set(PACKAGE_NAME "XZ Utils")
|
set(PACKAGE_NAME "XZ Utils")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue