mirror of https://git.tukaani.org/xz.git
CMake/Windows: Add a workaround for windres from GNU binutils.
This is combined from the following commits in the master branch:443dfebced
6b117d3b1f
5e34774c31
Thanks to Iouri Kharon for the bug report, the original patch, and testing.
This commit is contained in:
parent
43521e77ac
commit
65c59ad429
|
@ -75,10 +75,40 @@ 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)
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# However, even \x20 isn't enough in all situations, resulting in
|
||||||
|
# "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.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
string(APPEND CMAKE_RC_FLAGS " --use-temp-file")
|
||||||
|
set(PACKAGE_NAME "XZ\\x20Utils")
|
||||||
|
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")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Definitions common to all targets:
|
# Definitions common to all targets:
|
||||||
add_compile_definitions(
|
add_compile_definitions(
|
||||||
# Package info:
|
# Package info:
|
||||||
PACKAGE_NAME="XZ Utils"
|
PACKAGE_NAME="${PACKAGE_NAME}"
|
||||||
PACKAGE_BUGREPORT="xz@tukaani.org"
|
PACKAGE_BUGREPORT="xz@tukaani.org"
|
||||||
PACKAGE_URL="https://tukaani.org/xz/"
|
PACKAGE_URL="https://tukaani.org/xz/"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue