Skip to content

Commit 8b54c97

Browse files
committed
[WIP] Switch MinGW building to CMake
Automatically grabs and compiles libpng, and avoids having hacky lines in our Makefile (the compiler specification *should* be orthogonal to the build target!) Also move the MinGW package install to the `install_deps.sh` script, to move logic off of the YAML.
1 parent 66e521e commit 8b54c97

5 files changed

Lines changed: 73 additions & 8 deletions

File tree

.github/scripts/install_deps.sh

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
#!/bin/sh
22
# This script requires `sh` instead of `bash` because the latter is not always installed on FreeBSD.
3-
set -eu
3+
set -eux
44

5-
case "${1%-*}" in
5+
USAGE="Usage: $0 <os> [additional toolset]"
6+
7+
OS="${1:?$USAGE}"
8+
shift
9+
TOOLSET="${1-}"
10+
shift 2>/dev/null || : # That argument is optional.
11+
if [ $# -ne 0 ]; then
12+
echo >&2 "$USAGE"
13+
exit 1
14+
fi
15+
16+
case "${OS%-*}" in
617
ubuntu)
18+
pkgs=bison
19+
case "$TOOLSET" in
20+
mingw32) TOOLSET=
21+
pkgs="$pkgs g++-mingw-w64-i686-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev"
22+
;;
23+
mingw64) TOOLSET=
24+
pkgs="$pkgs g++-mingw-w64-x86-64-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev"
25+
;;
26+
'')
27+
pkgs="$pkgs libpng-dev"
28+
;;
29+
esac
730
sudo apt-get -qq update
8-
sudo apt-get install -yq bison libpng-dev pkg-config
31+
#shellcheck disable=SC2086 # (This word splitting is intentional.)
32+
sudo apt-get install -yq $pkgs
933
;;
1034
macos)
1135
# macOS bundles GNU Make 3.81, which doesn't support synced output.
@@ -30,6 +54,11 @@ case "${1%-*}" in
3054
;;
3155
esac
3256

57+
if [ -n "$TOOLSET" ]; then
58+
printf >&2 'Unknown toolset `%s` for OS `%s`\n' "$TOOLSET" "$OS"
59+
exit 1
60+
fi
61+
3362
echo "PATH=($PATH)" | sed 's/:/\n /g'
3463
bison --version
3564
make --version

.github/workflows/testing.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ jobs:
240240
- name: Install MinGW
241241
run: | # dpkg-dev is apparently required for pkg-config for cross-building
242242
sudo apt-get install g++-mingw-w64-${{ matrix.arch }}-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev
243-
- name: Install libpng dev headers for MinGW
244-
run: |
245-
./.github/scripts/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
243+
#- name: Install libpng dev headers for MinGW
244+
# run: |
245+
# ./.github/scripts/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
246246
- name: Cross-build Windows binaries
247247
run: |
248-
make mingw${{ matrix.bits }} -kj Q=
248+
cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw${{ matrix.bits }}.cmake
249249
- name: Package binaries
250250
run: | # DLL dependencies can be figured out using e.g. Dependency Walker or objdump -p
251251
mkdir bins

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ CMakeCache.txt
1414
CMakeFiles/
1515
cmake_install.cmake
1616
CMakeUserPresets.json
17-
build/
17+
build*/
1818
*.dSYM/
1919
callgrind.out.*

cmake/toolchain-mingw32.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# From https://www.mingw-w64.org/build-systems/cmake/
2+
3+
set(CMAKE_SYSTEM_NAME Windows)
4+
set(CMAKE_SYSTEM_PROCESSOR i686)
5+
6+
# specify the cross compiler
7+
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
8+
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
9+
set(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
10+
11+
# where is the target environment
12+
set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
13+
14+
# search for programs in the build host directories
15+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16+
# for libraries and headers in the target directories
17+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
18+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

cmake/toolchain-mingw64.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# From https://www.mingw-w64.org/build-systems/cmake/
2+
3+
set(CMAKE_SYSTEM_NAME Windows)
4+
set(CMAKE_SYSTEM_PROCESSOR x86_64)
5+
6+
# specify the cross compiler
7+
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
8+
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
9+
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
10+
11+
# where is the target environment
12+
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
13+
14+
# search for programs in the build host directories
15+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
16+
# for libraries and headers in the target directories
17+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
18+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

0 commit comments

Comments
 (0)