# Meson common cross file for targeting Windows from Linux
# To be included after mingw-cross-{matlab,octave}.ini

[constants]
# For the architectural baseline, we follow MSYS2:
# https://www.msys2.org/news/#2022-10-18-new-minimum-hardware-requirements-cpus-from-20067
arch_flags = [ '-march=nocona', '-msahf', '-mtune=generic' ]

[binaries]
cpp = 'x86_64-w64-mingw32-g++-posix'
fortran = 'x86_64-w64-mingw32-gfortran-posix'
c = 'x86_64-w64-mingw32-gcc-posix'
strip = 'x86_64-w64-mingw32-strip'
ar = 'x86_64-w64-mingw32-gcc-ar-posix'
pkgconfig = 'x86_64-w64-mingw32-pkg-config'

[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

[built-in options]
prefer_static = true

# MSYS2 libraries are now built with -fstack-protector-strong, see:
# https://www.msys2.org/news/#2022-10-23-mingw-packages-now-built-with-d_fortify_source2-and-fstack-protector-strong
# As of 2023-01-03, when linking against HDF5 (and possibly other libraries),
# it is necessary to compile our own code with -fstack-protector to avoid undefined symbols
# at link time.
# Note that specifying -fstack-protector-strong or -fstack-protector-all will lead
# to a dependency on libssp-0.dll (at least when using the MinGW compilers from Debian),
# and there seems to be no easy way of linking it statically.
# Also note that adding this flag is not necessary when building from MSYS2 shell.
# Maybe revisit this once our runners are upgraded to Debian “Bookworm” 12.
cpp_args = [ '-fstack-protector' ] + arch_flags
cpp_link_args = [ '-fstack-protector' ]

fortran_args = arch_flags + [ '-B', slicot_path ]
c_args = arch_flags

[properties]
sys_root='/tmp/windeps/lib64-msys2'
pkg_config_libdir = '/tmp/windeps/lib64-msys2/mingw64/lib/pkgconfig'
boost_root = '/tmp/windeps/lib64-msys2/mingw64'
