# SDL\_image: Test installed SDL\_image with CMake

**URL:** <https://discourse.libsdl.org/t/sdl-image-test-installed-sdl-image-with-cmake/36746>\
**Category:** SDL Commits\
**Created:** [June 7, 2022, 2:54am UTC](https://discourse.libsdl.org/t/sdl-image-test-installed-sdl-image-with-cmake/36746 "2022-06-07T02:54:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [June 7, 2022, 2:54am UTC](https://discourse.libsdl.org/t/sdl-image-test-installed-sdl-image-with-cmake/36746/1 "2022-06-07T02:54:24Z")

</div>

> <https://github.com/libsdl-org/SDL_image/commit/a9fa9082a60ee6b4c5cf6898a672c2af627cf4c9>

```diff
From a9fa9082a60ee6b4c5cf6898a672c2af627cf4c9 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 4 Jun 2022 02:54:14 +0200
Subject: [PATCH] Test installed SDL_image with CMake

---
 .github/workflows/main.yml | 65 ++++++++++++++++++++++----------------
 1 file changed, 38 insertions(+), 27 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index c558abc8..e4a70a15 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -15,19 +15,19 @@ jobs:
       fail-fast: false
       matrix:
         platform:
- - { name: Windows (MSVC+CMake), os: windows-latest, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -GNinja', msvc: 1 }
- - { name: Windows (mingw32+autotools), os: windows-latest, shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686 }
- - { name: Windows (mingw64+CMake), os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64,
+ - { name: Windows (MSVC+CMake), os: windows-latest, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -GNinja', msvc: 1, shared: 1, static: 0 }
+ - { name: Windows (mingw32+autotools), os: windows-latest, shell: 'msys2 {0}', msystem: mingw32, msys-env: mingw-w64-i686, shared: 1, static: 1 }
+ - { name: Windows (mingw64+CMake), os: windows-latest, shell: 'msys2 {0}', msystem: mingw64, msys-env: mingw-w64-x86_64, shared: 1, static: 0,
             cmake: '-DSDL2IMAGE_BACKEND_STB=OFF -DSDL2IMAGE_BACKEND_WIC=OFF -DSDL2IMAGE_VENDORED=OFF -DSDL2IMAGE_AVIF=ON -G "Ninja Multi-Config"' }
- - { name: Linux (autotools), os: ubuntu-20.04, shell: sh }
- - { name: Linux (CMake), os: ubuntu-20.04, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -GNinja' }
- - { name: 'Linux (CMake, static)', os: ubuntu-20.04, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -DBUILD_SHARED_LIBS=OFF -GNinja' }
- - { name: Macos (autotools), os: macos-latest, shell: sh }
- - { name: Macos (CMake), os: macos-latest, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -GNinja' }
+ - { name: Linux (autotools), os: ubuntu-20.04, shell: sh, shared: 1, static: 1}
+ - { name: Linux (CMake), os: ubuntu-20.04, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -GNinja', shared: 1, static: 0 }
+ - { name: 'Linux (CMake, static)', os: ubuntu-20.04, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -DBUILD_SHARED_LIBS=OFF -GNinja', shared: 0, static: 1 }
+ - { name: Macos (autotools), os: macos-latest, shell: sh, shared: 1, static: 1 }
+ - { name: Macos (CMake), os: macos-latest, shell: sh, cmake: '-DSDL2IMAGE_VENDORED=ON -GNinja', shared: 1, static: 0 }
 
     steps:
     - name: Set up MSYS2
- if: matrix.platform.shell == 'msys2 {0}'
+ if: ${{ contains(matrix.platform.shell, 'msys2') }}
       uses: msys2/setup-msys2@v2
       with:
         msystem: ${{ matrix.platform.msystem }}
@@ -106,12 +106,12 @@ jobs:
       if: "runner.os == 'Linux' && matrix.platform.cmake"
       run: ./test-versioning.sh
 
- - name: Setup CMake
+ - name: Setup (CMake)
       if: ${{ matrix.platform.cmake && !matrix.platform.msystem && !matrix.platform.msvc }}
       uses: jwlawson/actions-setup-cmake@v1.12
       with:
         cmake-version: '3.16'
- - name: Configure CMake
+ - name: Configure (CMake)
       if: "matrix.platform.cmake"
       run: |
         set -- \
@@ -122,6 +122,7 @@ jobs:
           -DSDL2IMAGE_JXL=ON \
           -DSDL2IMAGE_TIF=ON \
           -DSDL2IMAGE_WEBP=ON \
+ -DCMAKE_INSTALL_PREFIX=prefix_cmake \
           ${NULL+}
 
         if ["${{ matrix.platform.msystem }}" = ""]; then
@@ -137,10 +138,10 @@ jobs:
         cmake -B build \
           "$@" \
           ${{ matrix.platform.cmake }}
- - name: Build
+ - name: Build (CMake)
       if: "matrix.platform.cmake"
       run: cmake --build build/ --config Release --parallel --verbose
- - name: Run build-time tests
+ - name: Run build-time tests (CMake)
       if: "runner.os == 'Linux' && matrix.platform.cmake"
       run: |
         set -eu
@@ -169,14 +170,15 @@ jobs:
         export SDL_IMAGE_TEST_REQUIRE_SAVE_PNG=1
 
         ctest -VV --test-dir build/test
- - name: Install
- if: "matrix.platform.shell == 'sh' && matrix.platform.cmake"
+ - name: Install (CMake)
+ if: "(matrix.platform.shell == 'sh' || contains(matrix.platform.shell, 'msys2')) && matrix.platform.cmake"
       run: |
         set -eu
         rm -fr DESTDIR-cmake
- DESTDIR=$(pwd)/DESTDIR-cmake cmake --install build/ --config Release
- find DESTDIR-cmake | LC_ALL=C sort -u
- - name: Upload artifacts
+ cmake --install build/ --config Release
+ echo "SDL2_image_DIR=$(pwd)/prefix_cmake" >> $GITHUB_ENV
+ ( cd prefix_cmake; find . ) | LC_ALL=C sort -u
+ - name: Upload artifacts (CMake)
       if: "failure() && runner.os == 'Linux' && matrix.platform.cmake"
       uses: actions/upload-artifact@v3
       with:
@@ -187,7 +189,7 @@ jobs:
           build/test/*.png
         if-no-files-found: ignore
 
- - name: Configure Autotools
+ - name: Configure (Autotools)
       if: "! matrix.platform.cmake"
       run: |
         set -eu
@@ -195,20 +197,20 @@ jobs:
         mkdir build-autotools
         ./autogen.sh
         # We do the CMake build with stb_image and the Autotools build without
- set -- --disable-stb-image
+ set -- --disable-stb-image --prefix=$(pwd)/prefix_autotools
         # mingw-w64-*-SDL2 doesn't have SDL_test, so only build this on Unix
         if ["${{ matrix.platform.shell }}" = 'sh']; then
           set -- "$@" --enable-tests
           set -- "$@" --enable-installed-tests
         fi
         ( cd build-autotools && ../configure "$@" )
- - name: Build with Autotools
+ - name: Build (Autotools)
       if: "! matrix.platform.cmake"
       run: |
         set -eu
         parallel="$(getconf _NPROCESSORS_ONLN)"
         make -j"${parallel}" -C build-autotools V=1
- - name: Run tests with Autotools
+ - name: Run build-time tests (Autotools)
       if: "! matrix.platform.cmake"
       run: |
         set -eu
@@ -239,7 +241,7 @@ jobs:
         export SDL_IMAGE_TEST_REQUIRE_SAVE_PNG=1
 
         make -j"${parallel}" -C build-autotools check V=1 VERBOSE=1
- - name: Install with Autotools
+ - name: Install (Autotools)
       if: "! matrix.platform.cmake"
       run: |
         set -eu
@@ -247,15 +249,16 @@ jobs:
         parallel="$(getconf _NPROCESSORS_ONLN)"
         rm -fr DESTDIR-autotools
         mkdir DESTDIR-autotools
- make -j"${parallel}" -C build-autotools install DESTDIR="${curdir}/DESTDIR-autotools" V=1
- find DESTDIR-autotools | LC_ALL=C sort -u
- - name: Distcheck with Autotools
+ make -j"${parallel}" -C build-autotools install V=1
+ echo "SDL2_image_DIR=$(pwd)/prefix_autotools" >> $GITHUB_ENV
+ ( cd prefix_autotools; find . ) | LC_ALL=C sort -u
+ - name: Distcheck (Autotools)
       if: "runner.os == 'Linux' && ! matrix.platform.cmake"
       run: |
         set -eu
         parallel="$(getconf _NPROCESSORS_ONLN)"
         make -j"${parallel}" -C build-autotools distcheck V=1
- - name: Upload artifacts
+ - name: Upload artifacts (Autotools)
       if: "failure() && ! matrix.platform.cmake"
       uses: actions/upload-artifact@v3
       with:
@@ -266,3 +269,11 @@ jobs:
           build-autotools/test/*.log
           build-autotools/test/*.png
         if-no-files-found: ignore
+ - name: Verify CMake configuration files
+ run: |
+ cmake -S cmake/test -B cmake_config_build \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_PREFIX_PATH="${{ env.SDL2_image_DIR }};${{ env.SDL2_DIR }}" \
+ -DTEST_SHARED=${{ matrix.platform.shared }} \
+ -DTEST_STATIC=${{ matrix.platform.static }}
+ cmake --build cmake_config_build --verbose

```
