How to use MXE to cross-build kst for Windows

=============================================

Note this is WIP and unofficial, provided FWIW by Tormod Volden
and tested on Ubuntu 20.04 (focal)

1. ADD MXE REPOSITORY
=====================

(See https://mxe.cc/ for details)

echo "deb https://pkg.mxe.cc/repos/apt focal main" | sudo tee /etc/apt/sources.list.d/mxeapt.list

sudo apt-key add mxeapt.gpg # gotten from https://pkg.mxe.cc/repos/apt/client-conf/

sudo apt update


2. INSTALL PREBUILT LIBRARIES FROM MXE
======================================

sudo apt install mxe-x86-64-w64-mingw32.shared-netcdf
sudo apt install mxe-x86-64-w64-mingw32.shared-qt5
sudo apt install mxe-x86-64-w64-mingw32.shared-gsl


3a. INSTALL MY PREBUILT LIBRARIES
=================================

Download and install my prebuilt packages (using dpkg -i):


3b. (alternatively) BUILD LIBRARIES NOT (YET?) IN MXE
========================================

(not needed if you download my prebuilt mxe-* packages instead!)

export PATH=/usr/lib/mxe/usr/bin:$PATH

# Get and unpack the getdata-0.11.0 zip for Windows
mkdir build && cd build &&
x86_64-w64-mingw32.shared-cmake ../getdata-0.11.0/cmake
make
make DESTDIR=$PWD/mxe-x86-64-w64-mingw32.shared-libgetdata install

# netcdf-cxx 4.2 (legacy)
mkdir build && cd build &&
../netcdf-cxx-4.2/configure --host=x86_64-w64-mingw32.shared --prefix=/usr/lib/mxe/usr/x86_64-w64-mingw32.shared
make
make DESTDIR=$PWD/mxe-x86-64-w64-mingw32.shared-libnetcdf-cxx-legacy install

# matio (shared, note that a static 1.5.2 is already in MXE)
ac_cv_va_copy=C99 ../matio-1.5.19/configure --host=x86_64-w64-mingw32.shared --prefix=/usr/lib/mxe/usr/x86_64-w64-mingw32.shared --disable-static
make 
make DESTDIR=$PWD/mxe-x86-64-w64-mingw32.shared-matio install

cfitsio (shared, note that a static 3410 is already in MXE)
x86_64-w64-mingw32.shared-cmake ../cfitsio-3410
make

# similar for all above: make deb package out of it
mkdir -p mxe-x86-64-w64-mingw32.shared-cfitsio/DEBIAN
vi mxe-x86-64-w64-mingw32.shared-cfitsio/DEBIAN/control
make DESTDIR=mxe-x86-64-w64-mingw32.shared-cfitsio install
fakeroot dpkg-deb --build mxe-x86-64-w64-mingw32.shared-cfitsio ..


4. BUILD KST
============

export PATH=/usr/lib/mxe/usr/bin:$PATH

# Generate makefiles and check all plugins are enabled (libraries detected)

x86_64-w64-mingw32.shared-cmake ../../../kst-git -Dkst_qt5=/usr/lib/mxe -Dkst_cross=x86_64-w64-mingw32.shared -Dkst_version_string=2.0.x-2021.03.14-09.31 -Dkst_release=1 -Dkst_merge_files=1


# WIP: something is wrong in cmake or xme wrapper:
# dependent libraries not being added to the list of libraries in linklibs.rsp

# add missing -hdf5 dependency:
sed -i 's/$/ -lhdf5/' src/datasources/CMakeFiles/kst2_datasource_hdf5.dir/linklibs.rsp

make VERBOSE=1

# WIP: make install doesn't add all libraries?
# workaround: add dlls to misc/cmake_install.cmake
# see the last lines of my modfied one
misc_cmake_install.cmake

make install

LINKS
=====
https://mxe.cc/
https://github.com/zer0main/battleship/blob/master/build/windows/requirements.sh
https://blog.rubenwardy.com/2018/05/07/mingw-copy-dlls/