Skip to content

Commit 6f8c425

Browse files
committed
Attempt to fetch Windows deps via CMake instead
This will respect existing installs, but download and compile from source if necessary.
1 parent fef748c commit 6f8c425

4 files changed

Lines changed: 60 additions & 44 deletions

File tree

.github/scripts/get_win_deps.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function getlibrary ([string] $URI, [string] $filename, [string] $hash, [string]
1515
Expand-Archive -DestinationPath $destdir $filename
1616
}
1717

18-
getlibrary 'https://www.zlib.net/zlib132.zip' 'zlib.zip' 'e8bf55f3017aa181690990cb58a994e77885da140609fc8f94abe9b65d2cae28' .
19-
getlibrary 'https://github.com/pnggroup/libpng/archive/refs/tags/v1.6.53.zip' 'libpng.zip' '9fb99118ec4523d9a9dab652ce7c2472ec76f6ccd69d1aba3ab873bb8cf84b98' .
20-
getlibrary 'https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip' 'winflexbison.zip' '8d324b62be33604b2c45ad1dd34ab93d722534448f55a16ca7292de32b6ac135' install_dir
18+
#getlibrary 'https://www.zlib.net/zlib132.zip' 'zlib.zip' 'e8bf55f3017aa181690990cb58a994e77885da140609fc8f94abe9b65d2cae28' .
19+
#getlibrary 'https://github.com/pnggroup/libpng/archive/refs/tags/v1.6.53.zip' 'libpng.zip' '9fb99118ec4523d9a9dab652ce7c2472ec76f6ccd69d1aba3ab873bb8cf84b98' .
20+
getlibrary 'https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip' 'winflexbison.zip' '8d324b62be33604b2c45ad1dd34ab93d722534448f55a16ca7292de32b6ac135' bison
2121

22-
Move-Item zlib-1.3.2 zlib
23-
Move-Item libpng-1.6.53 libpng
22+
#Move-Item zlib-1.3.2 zlib
23+
#Move-Item libpng-1.6.53 libpng

.github/workflows/testing.yml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ on:
33
- push
44
- pull_request
55

6+
env:
7+
CLICOLOR_FORCE: 1 # Makes CMake output colours.
8+
CMAKE_COLOR_DIAGNOSTICS: ON # Makes CMake-generated build systems emit colour.
9+
610
jobs:
711
unix:
812
strategy:
@@ -31,7 +35,7 @@ jobs:
3135
- name: Build & install using CMake
3236
if: matrix.buildsys == 'cmake'
3337
run: |
34-
cmake -S . -B build --preset develop -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DTESTS_OS_NAME=${{ matrix.os }}
38+
cmake -S . -B build --preset develop -DFETCHCONTENT_BASE_DIR=/tmp/cmake_deps -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DTESTS_OS_NAME=${{ matrix.os }}
3539
cmake --build build -j --verbose
3640
sudo cmake --install build --verbose
3741
- name: Package binaries
@@ -147,37 +151,37 @@ jobs:
147151
uses: actions/checkout@v4
148152
- name: Install deps
149153
run: .github/scripts/get_win_deps.ps1
150-
- name: Check libraries cache
151-
id: cache
152-
uses: actions/cache@v4
153-
with:
154-
path: |
155-
zbuild
156-
pngbuild
157-
key: ${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles('zlib/**', 'libpng/**') }}
158-
- name: Build zlib
159-
if: steps.cache.outputs.cache-hit != 'true'
160-
shell: bash
161-
run: | # BUILD_SHARED_LIBS causes the output DLL to be called `z.dll` as of zlib 1.3.2 (formerly `zlib1.dll`)
162-
cmake -S zlib -B zbuild -A ${{ matrix.platform }} -Wno-dev -DCMAKE_INSTALL_PREFIX=install_dir -DBUILD_SHARED_LIBS=ON
163-
cmake --build zbuild --config Debug -j
164-
- name: Install zlib
165-
run: |
166-
cmake --install zbuild --config Debug
167-
- name: Build libpng
168-
if: steps.cache.outputs.cache-hit != 'true'
169-
shell: bash
170-
run: |
171-
cmake -S libpng -B pngbuild -A ${{ matrix.platform }} -Wno-dev -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Debug -DPNG_SHARED=ON -DPNG_STATIC=OFF -DPNG_TESTS=OFF
172-
cmake --build pngbuild --config Debug -j
173-
- name: Install libpng
174-
run: |
175-
cmake --install pngbuild --config Debug
154+
# - name: Check libraries cache
155+
# id: cache
156+
# uses: actions/cache@v4
157+
# with:
158+
# path: |
159+
# zbuild
160+
# pngbuild
161+
# key: ${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles('zlib/**', 'libpng/**') }}
162+
# - name: Build zlib
163+
# if: steps.cache.outputs.cache-hit != 'true'
164+
# shell: bash
165+
# run: | # BUILD_SHARED_LIBS causes the output DLL to be called `z.dll` as of zlib 1.3.2 (formerly `zlib1.dll`)
166+
# cmake -S zlib -B zbuild -A ${{ matrix.platform }} -Wno-dev -DCMAKE_INSTALL_PREFIX=install_dir -DBUILD_SHARED_LIBS=ON
167+
# cmake --build zbuild --config Debug -j
168+
# - name: Install zlib
169+
# run: |
170+
# cmake --install zbuild --config Debug
171+
# - name: Build libpng
172+
# if: steps.cache.outputs.cache-hit != 'true'
173+
# shell: bash
174+
# run: |
175+
# cmake -S libpng -B pngbuild -A ${{ matrix.platform }} -Wno-dev -DCMAKE_INSTALL_PREFIX=install_dir -DCMAKE_BUILD_TYPE=Debug -DPNG_SHARED=ON -DPNG_STATIC=OFF -DPNG_TESTS=OFF
176+
# cmake --build pngbuild --config Debug -j
177+
# - name: Install libpng
178+
# run: |
179+
# cmake --install pngbuild --config Debug
176180
- name: Build Windows binaries
177181
shell: bash
178182
run: | # ASan seems to be broken on Windows.
179-
cmake -S . -B build -A ${{ matrix.platform }} --preset develop -DCMAKE_INSTALL_PREFIX=install_dir -DSANITIZERS=OFF
180-
cmake --build build --config Debug -j --verbose
183+
cmake -S . -B build -A ${{ matrix.platform }} --preset develop -DFETCHCONTENT_BASE_DIR="$TEMP/cmake-deps" -DBISON_EXECUTABLE=bison/win_bison.exe -DSANITIZERS=OFF
184+
cmake --build build --config Debug -j 1
181185
cmake --install build --verbose
182186
- name: Package binaries
183187
shell: bash

CMakeLists.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,27 @@ endif()
136136

137137
## Dependencies.
138138

139-
find_package(PkgConfig)
140-
if(MSVC OR NOT PKG_CONFIG_FOUND)
141-
# fallback to find_package
142-
# cmake's FindPNG is very fragile; it breaks when multiple versions are installed
143-
# this is most evident on macOS but can occur on Linux too
144-
find_package(PNG REQUIRED)
145-
else()
146-
pkg_check_modules(LIBPNG REQUIRED IMPORTED_TARGET libpng)
147-
add_library(PNG::PNG ALIAS PkgConfig::LIBPNG)
139+
include(FetchContent)
140+
FetchContent_Declare(PNG
141+
URL https://download.sourceforge.net/libpng/libpng-1.6.55.tar.xz
142+
URL_HASH SHA256=d925722864837ad5ae2a82070d4b2e0603dc72af44bd457c3962298258b8e82d
143+
FIND_PACKAGE_ARGS 1.5.4)
144+
FetchContent_Declare(ZLIB
145+
URL https://www.zlib.net/zlib-1.3.2.tar.xz
146+
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
147+
FIND_PACKAGE_ARGS)
148+
set(PNG_TESTS OFF CACHE INTERNAL "") # We do not care for these two (and they can even cause compile errors!)
149+
set(PNG_TOOLS OFF CACHE INTERNAL "")
150+
set(PNG_SHARED ON CACHE INTERNAL "") # Upstream seems to favour the dynamic lib over the static one?
151+
set(PNG_STATIC OFF CACHE INTERNAL "")
152+
FetchContent_MakeAvailable(ZLIB)
153+
if(NOT DEFINED ZLIB_INCLUDE_DIRS)
154+
get_target_property(ZLIB_INCLUDE_DIRS ZLIB::ZLIB INCLUDE_DIRECTORIES) # libpng relies on this variable to be set.
155+
endif()
156+
execute_process(COMMAND sed -Ei "s/RESULT_VARIABLE/COMMAND_ECHO STDERR &/" "$ENV{TEMP}/cmake-deps/png-build/scripts/cmake/genout.cmake")
157+
FetchContent_MakeAvailable(PNG)
158+
if(NOT TARGET PNG::PNG)
159+
add_library(PNG::PNG ALIAS png_shared)
148160
endif()
149161

150162
## The actual stuff.

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ target_compile_definitions(common PRIVATE "BUILD_VERSION_STRING=\"${GIT_REV}\"")
1313

1414
find_package(BISON 3.0.0 REQUIRED)
1515
set(BISON_FLAGS "-Wall -Dlr.type=ielr")
16-
# Set some flags on versions that support them
16+
# Set some flags on versions that support them.
1717
if(BISON_VERSION VERSION_GREATER_EQUAL "3.5")
1818
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.lac=full -Dapi.token.raw=true -Wdangling-alias")
1919
endif()

0 commit comments

Comments
 (0)