From 8f05246299699f1f5600b8558b131ae454ea3ca3 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 22 May 2024 03:29:21 +0200
Subject: [PATCH] cmake: download SDL3 using FetchContent
---
.github/workflows/main.yml | 4 ++--
CMakeLists.txt | 22 ++++++++++++++++++++--
main.c | 2 +-
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index b4d9474..070a704 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -21,8 +21,8 @@ jobs:
with:
version: sdl3-head
- name: Get project sources
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Configure CMake
- run: cmake -B build ${{ matrix.platform.flags }}
+ run: cmake -B build ${{ matrix.platform.flags }} -DDOWNLOAD_DEPENDENCIES=OFF
- name: Build
run: cmake --build build/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b6bab11..7332651 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,26 @@
cmake_minimum_required(VERSION 3.12.0)
project(SDL_helloworld)
-find_package(SDL3 CONFIG REQUIRED)
+# By configuring CMake with -DDOWNLOAD_DEPENDENCIES=ON/OFF,
+# users can choose between downloading dependencies or using system libraries
+option(DOWNLOAD_DEPENDENCIES "Download dependencies" TRUE)
+
+if(DOWNLOAD_DEPENDENCIES)
+ # FetchContent downloads and configures dependencies
+ include(FetchContent)
+ FetchContent_Declare(
+ SDL3
+ GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git"
+ GIT_TAG "main"
+ EXCLUDE_FROM_ALL
+ )
+ FetchContent_MakeAvailable(SDL3)
+else()
+ # find_package looks for already-installed system packages.
+ # Configure with `-DCMAKE_PREFIX_PATH="/path/to/package1;/path/to/package2"`
+ # to add search paths.
+ find_package(SDL3 CONFIG REQUIRED)
+endif()
add_executable(sdl-helloworld
main.c
@@ -12,4 +31,3 @@ target_link_libraries(sdl-helloworld PRIVATE SDL3::SDL3)
# This is safe to set on all platforms. Otherwise your SDL app will
# have a terminal window pop up with it on Windows.
set_property(TARGET sdl-helloworld PROPERTY WIN32_EXECUTABLE TRUE)
-
diff --git a/main.c b/main.c
index 4323a83..378732f 100644
--- a/main.c
+++ b/main.c
@@ -17,7 +17,7 @@ static int setup_program(int argc, char **argv)
return -1;
}
- renderer = SDL_CreateRenderer(window, NULL, 0);
+ renderer = SDL_CreateRenderer(window, NULL);
if (!renderer) {
SDL_Log("SDL_CreateRenderer() failed: %s", SDL_GetError());
return -1;