diff --git a/CMakeLists.txt b/CMakeLists.txt index 33fc3675..a55892fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,24 @@ else() set(PACKAGE_NAME "XZ Utils") endif() +# When used with MSVC, CMake can merge .manifest files with +# linker-generated manifests and embed the result in an executable. +# However, when paired with MinGW-w64, CMake (3.30) ignores .manifest +# files. Embedding a manifest with a resource file works with both +# toochains. It's also the way to do it with Autotools. +# +# With MSVC, we need to disable the default manifest; attempting to add +# two manifest entries would break the build. The flag /MANIFEST:NO +# goes to the linker and it also affects behavior of CMake itself: it +# looks what flags are being passed to the linker and when CMake sees +# the /MANIFEST:NO option, other manifest-related linker flags are +# no longer added (see the file Source/cmcmd.cxx in CMake). +# +# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23066 +if(MSVC) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO") +endif() + # Definitions common to all targets: add_compile_definitions( # Package info: diff --git a/src/Makefile.am b/src/Makefile.am index d199e858..a461a440 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,4 +39,5 @@ EXTRA_DIST = \ common/tuklib_physmem.c \ common/tuklib_physmem.h \ common/tuklib_progname.c \ - common/tuklib_progname.h + common/tuklib_progname.h \ + common/w32_application.manifest diff --git a/src/common/common_w32res.rc b/src/common/common_w32res.rc index d05d22e7..1f82577d 100644 --- a/src/common/common_w32res.rc +++ b/src/common/common_w32res.rc @@ -50,3 +50,8 @@ BEGIN VALUE "Translation", 0x409, 1200 END END + +/* Omit the manifest on Cygwin and MSYS2 (both define __CYGWIN__). */ +#if MY_TYPE == VFT_APP && !defined(__CYGWIN__) +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "w32_application.manifest" +#endif diff --git a/src/common/w32_application.manifest b/src/common/w32_application.manifest new file mode 100644 index 00000000..2f875087 --- /dev/null +++ b/src/common/w32_application.manifest @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + true + UTF-8 + + +