From 8ac267c8db771bf87111e29f0511b26e145819fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 21 Oct 2021 19:16:01 +0200 Subject: Figure out how to abuse MSYS2 repositories In the end, all seems to work fairly well on Windows 10. --- CMakeLists.txt | 6 +++- README.adoc | 15 ++++++++-- ToolchainCrossMinGW.cmake | 16 ++++++++++ ToolchainCrossMinGWW64.cmake | 16 ++++++++++ ToolchainCrossWin64.cmake | 16 ++++++++++ ToolchainDebianMinGW.cmake | 16 ---------- ToolchainDebianMinGWW64.cmake | 16 ---------- Win64Depends.sh | 69 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 134 insertions(+), 36 deletions(-) create mode 100644 ToolchainCrossMinGW.cmake create mode 100644 ToolchainCrossMinGWW64.cmake create mode 100644 ToolchainCrossWin64.cmake delete mode 100644 ToolchainDebianMinGW.cmake delete mode 100644 ToolchainDebianMinGWW64.cmake create mode 100644 Win64Depends.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bead1c..ab3e04b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,12 +348,16 @@ if (WIN32) DESTINATION etc) install (DIRECTORY ${WIN32_DEPENDS_PATH}/lib/gdk-pixbuf-2.0 - DESTINATION lib) + DESTINATION lib + FILES_MATCHING PATTERN "*" PATTERN "*.a" EXCLUDE) install (DIRECTORY ${WIN32_DEPENDS_PATH}/share/glib-2.0/schemas DESTINATION share/glib-2.0 FILES_MATCHING PATTERN "org.gtk.Settings.*") + install (DIRECTORY + ${WIN32_DEPENDS_PATH}/share/icons/Adwaita + DESTINATION share/icons OPTIONAL) install (FILES ${WIN32_DEPENDS_PATH}/share/icons/hicolor/index.theme DESTINATION share/icons/hicolor) diff --git a/README.adoc b/README.adoc index b1d65c7..ebfd0b6 100644 --- a/README.adoc +++ b/README.adoc @@ -51,7 +51,7 @@ After _cpack_ finishes making the package, install this file. Build from source on Windows ---------------------------- -_Note that with the current method we're stuck with GTK+ 3.10.4 at best._ +_Note that with the current method we're stuck with GTK+ 3.8.2._ First install CMake >= 3.1 and MinGW. Add both to your system path. If you want to build an installation package, also install NSIS. @@ -86,7 +86,6 @@ By default, that is if you specify no generator, both packages are built. Cross-compilation for Windows ----------------------------- - The procedure is almost exactly the same as before, including the requirements. Just install MinGW-w64 and let automation take care of the rest. @@ -94,7 +93,17 @@ Just install MinGW-w64 and let automation take care of the rest. $ mkdir build $ cd build $ cmake .. \ - -DCMAKE_TOOLCHAIN_FILE=../ToolchainDebianMinGWW64.cmake \ + -DCMAKE_TOOLCHAIN_FILE=../ToolchainCrossMinGWW64.cmake \ + -DCMAKE_BUILD_TYPE=Release + $ cpack + +Alternatively, for an unnecessarily bloated MSYS2-based 64-bit build: + + $ sh Win64Depends.cmake + $ mkdir build + $ cd build + $ cmake .. \ + -DCMAKE_TOOLCHAIN_FILE=../ToolchainCrossWin64.cmake \ -DCMAKE_BUILD_TYPE=Release $ cpack diff --git a/ToolchainCrossMinGW.cmake b/ToolchainCrossMinGW.cmake new file mode 100644 index 0000000..7c9242b --- /dev/null +++ b/ToolchainCrossMinGW.cmake @@ -0,0 +1,16 @@ +set (CMAKE_SYSTEM_NAME "Windows") +set (CMAKE_SYSTEM_PROCESSOR "x86") + +set (CMAKE_C_COMPILER "i586-mingw32msvc-gcc") +set (CMAKE_CXX_COMPILER "i586-mingw32msvc-g++") +set (CMAKE_RC_COMPILER "i586-mingw32msvc-windres") + +# Not needed to crosscompile an installation package +#set (CMAKE_CROSSCOMPILING_EMULATOR "wine") + +set (CMAKE_FIND_ROOT_PATH "/usr/i586-mingw32msvc") + +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff --git a/ToolchainCrossMinGWW64.cmake b/ToolchainCrossMinGWW64.cmake new file mode 100644 index 0000000..f72e903 --- /dev/null +++ b/ToolchainCrossMinGWW64.cmake @@ -0,0 +1,16 @@ +set (CMAKE_SYSTEM_NAME "Windows") +set (CMAKE_SYSTEM_PROCESSOR "x86") + +set (CMAKE_C_COMPILER "i686-w64-mingw32-gcc") +set (CMAKE_CXX_COMPILER "i686-w64-mingw32-g++") +set (CMAKE_RC_COMPILER "i686-w64-mingw32-windres") + +# Not needed to crosscompile an installation package +#set (CMAKE_CROSSCOMPILING_EMULATOR "wine") + +set (CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") + +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff --git a/ToolchainCrossWin64.cmake b/ToolchainCrossWin64.cmake new file mode 100644 index 0000000..a562ed0 --- /dev/null +++ b/ToolchainCrossWin64.cmake @@ -0,0 +1,16 @@ +set (CMAKE_SYSTEM_NAME "Windows") +set (CMAKE_SYSTEM_PROCESSOR "x86_64") + +set (CMAKE_C_COMPILER "x86_64-w64-mingw32-gcc") +set (CMAKE_CXX_COMPILER "x86_64-w64-mingw32-g++") +set (CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres") + +# Not needed to crosscompile an installation package +#set (CMAKE_CROSSCOMPILING_EMULATOR "wine") + +set (CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") + +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff --git a/ToolchainDebianMinGW.cmake b/ToolchainDebianMinGW.cmake deleted file mode 100644 index 7c9242b..0000000 --- a/ToolchainDebianMinGW.cmake +++ /dev/null @@ -1,16 +0,0 @@ -set (CMAKE_SYSTEM_NAME "Windows") -set (CMAKE_SYSTEM_PROCESSOR "x86") - -set (CMAKE_C_COMPILER "i586-mingw32msvc-gcc") -set (CMAKE_CXX_COMPILER "i586-mingw32msvc-g++") -set (CMAKE_RC_COMPILER "i586-mingw32msvc-windres") - -# Not needed to crosscompile an installation package -#set (CMAKE_CROSSCOMPILING_EMULATOR "wine") - -set (CMAKE_FIND_ROOT_PATH "/usr/i586-mingw32msvc") - -set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - diff --git a/ToolchainDebianMinGWW64.cmake b/ToolchainDebianMinGWW64.cmake deleted file mode 100644 index f72e903..0000000 --- a/ToolchainDebianMinGWW64.cmake +++ /dev/null @@ -1,16 +0,0 @@ -set (CMAKE_SYSTEM_NAME "Windows") -set (CMAKE_SYSTEM_PROCESSOR "x86") - -set (CMAKE_C_COMPILER "i686-w64-mingw32-gcc") -set (CMAKE_CXX_COMPILER "i686-w64-mingw32-g++") -set (CMAKE_RC_COMPILER "i686-w64-mingw32-windres") - -# Not needed to crosscompile an installation package -#set (CMAKE_CROSSCOMPILING_EMULATOR "wine") - -set (CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") - -set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - diff --git a/Win64Depends.sh b/Win64Depends.sh new file mode 100644 index 0000000..aa0deab --- /dev/null +++ b/Win64Depends.sh @@ -0,0 +1,69 @@ +#!/bin/sh -e +# Win64Depends.sh: download dependencies from MSYS2 for cross-compilation +# Dependencies: AWK, sed, cURL, bsdtar, wine64 +repository=https://repo.msys2.org/mingw/mingw64/ + +status() { + echo "$(tput bold)-- $*$(tput sgr0)" +} + +# TODO: Try to verify checksums, it will be relatively low-effort. +dbsync() { + status Fetching repository DB + [ -f db.tsv ] || curl -# "$repository/mingw64.db" | bsdtar -xOf- | awk ' + function flush() { print f["%NAME%"] f["%FILENAME%"] f["%DEPENDS%"] } + NR > 1 && $0 == "%FILENAME%" { flush(); for (i in f) delete f[i] } + { if (/^[^%]/) f[field] = f[field] $0 "\t"; else field = $0 } + END { flush() } + ' > db.tsv +} + +fetch() { + status Resolving "$@" + mkdir -p packages + awk -F'\t' 'function get(name, i, a) { + if (visited[name]++ || !(name in filenames)) return + print filenames[name] + split(deps[name], a) + for (i in a) get(a[i]) + } BEGIN { while ((getline < "db.tsv") > 0) { + filenames[$1] = $2; deps[$1] = "" + for (i = 3; i <= NF; i++) { gsub(/[<=>].*/, "", $i) + deps[$1] = deps[$1] $i FS } + } for (i = 0; i < ARGC; i++) get(ARGV[i]) }' "$@" | while IFS= read -r name + do + status Fetching "$name" + [ -f "packages/$name" ] || curl -#o "packages/$name" "$repository/$name" + done +} + +extract() { + status Extracting packages + for subdir in * + do [ -d "$subdir" -a "$subdir" != packages ] && rm -rf -- "$subdir" + done + for i in packages/* + do bsdtar -xf "$i" --strip-components 1 mingw64 + done +} + +configure() { + status Configuring packages + glib-compile-schemas share/glib-2.0/schemas + wine64 bin/gdk-pixbuf-query-loaders.exe \ + > lib/gdk-pixbuf-2.0/2.10.0/loaders.cache + + # pkgconf has a command line option for this, but CMake can't pass it + sed -i "s|^prefix=/mingw64|prefix=$(pwd)|" lib/pkgconfig/*.pc +} + +mkdir -p win32-depends +cd win32-depends +dbsync +fetch mingw-w64-x86_64-gtk3 mingw-w64-x86_64-lua \ + mingw-w64-x86_64-libwinpthread-git # because we don't do "provides"? +extract +configure + +# XXX: Why is this override needed to run some GLib-based things under wine64? +export XDG_DATA_DIRS=$(pwd)/share -- cgit v1.2.3