From 6ac3cc71a4034817ebe155fcedf8b14b651c6546 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Wolfgang=20St=C3=B6ggl?= <c72578@yahoo.de>
Date: Mon, 9 Aug 2021 22:20:41 +0200
Subject: [PATCH] Fix mingw-w64 build

Add common_flags and common_ldflags to libgxps/meson.build, which are
required in case of mingw-w64 builds.
- For mingw-w64 builds, COBJMACROS needs to be defined before any
  #include <jpeglib.h>, because jpeglib.h includes shlwapi.h, which
  provides a different IStream_Write and lacks IStream_Release.
  The correct include for IStream_Write and IStream_Release is objidl.h
  Fixes:
    gxps-images.c:1042:4: error: too many arguments to function
    'IStream_Write'
    gxps-images.c:1058:2: error: implicit declaration of function
    'IStream_Release'
- mingw-w64 builds require linking with libwindowscodecs
---
 libgxps/meson.build | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libgxps/meson.build b/libgxps/meson.build
index 29b044e..212714e 100644
--- a/libgxps/meson.build
+++ b/libgxps/meson.build
@@ -73,6 +73,14 @@ if host_system == 'linux'
   common_ldflags = [ '-Wl,-Bsymbolic' ]
 endif
 
+if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-cl'
+  # Required for mingw-w64 builds for IStream_Write and IStream_Release in gxps-images.c
+  # COBJMACROS needs to be defined before any #include <jpeglib.h>, because jpeglib.h includes shlwapi.h
+  common_flags += '-DCOBJMACROS'
+  # mingw-w64 builds require linking with libwindowscodecs
+  common_ldflags = [ '-lwindowscodecs' ]
+endif
+
 gxps = shared_library('gxps',
                       include_directories: core_inc,
                       sources: sources + headers + private_headers + [ gxps_version_h ],
-- 
GitLab

