From c8cd182e98a2b95359fc56750b558e44a249868b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 28 Jul 2023 14:01:29 +0200
Subject: [PATCH] Build system / Meson: hack for static linking under Windows

[skip ci]
---
 src/meson.build | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/meson.build b/src/meson.build
index ff1ee552..f3829776 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -58,7 +58,18 @@ preprocessor_src = [ 'ComputingTasks.cc',
 	             'macro/Expressions.cc',
 	             'macro/Directives.cc' ]
 
+if get_option('prefer_static')
+  preprocessor_link_args = [ '-static-libgcc', '-static-libstdc++' ]
+  if host_machine.system() == 'windows'
+    # See comment in rules for MEX files
+    preprocessor_link_args += [ '-Wl,-Bstatic', '-lssp', '-Wl,-Bdynamic',
+                                '-Wl,-Bstatic,--whole-archive', '-lwinpthread', '-Wl,-Bdynamic,--no-whole-archive' ]
+  endif
+else
+  preprocessor_link_args = []
+endif
+
 executable('dynare-preprocessor', preprocessor_src, flex_src, flexlexer_h, bison_src,
            include_directories : preprocessor_incdir, dependencies : boost_dep,
-           link_args : get_option('prefer_static') ? '-static' : '',
+           link_args : preprocessor_link_args,
            install : true)
-- 
GitLab