From 124708784fdc4321d5983cdbfb889e62fbd25f40 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 21 Mar 2024 22:42:35 +0100 Subject: [PATCH] Restore buildability with SDL 2.0.10 --- .github/workflows/build.yml | 6 ++---- src/CMakeLists.txt | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0cb4165..f31521bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,8 +61,7 @@ jobs: LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest ogles2 linux-sdl: - # something is wrong with the SDL cmake files on 20.04 - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 - name: Install deps @@ -106,8 +105,7 @@ jobs: LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest opengl3 linux-sdl-gles2: - # something is wrong with the SDL cmake files on 20.04 - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 - name: Install deps diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 743dd1d8..46eaf9cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -265,8 +265,27 @@ if(ENABLE_OPENGL OR ENABLE_OPENGL3) find_package(OpenGL REQUIRED) endif() if(USE_SDL2) - find_package(SDL2 2.0.10 CONFIG REQUIRED) + find_package(SDL2 REQUIRED) message(STATUS "Found SDL2: ${SDL2_LIBRARIES}") + + # unfortunately older SDL does not provide its version to cmake, so check header. + set(CMAKE_REQUIRED_INCLUDES ${SDL2_INCLUDE_DIRS}) + unset(CHECK_SDL_VERSION CACHE) + check_cxx_source_compiles("#include \n\ +#if !SDL_VERSION_ATLEAST(2, 0, 10)\n\ +#error\n\ +#endif\n\ +int main() {}" CHECK_SDL_VERSION) + if(NOT CHECK_SDL_VERSION) + message(FATAL_ERROR "SDL2 is too old, required is at least 2.0.10!") + endif() + + # ...no target either. + if(NOT TARGET SDL2::SDL2) + add_library(SDL2::SDL2 SHARED IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARIES}") + endif() endif() # More special config