add cmake options to perfer system libs to sdl and sdl_image

This commit is contained in:
Green Sky 2025-04-06 16:49:50 +02:00
parent 9b40c417a2
commit de75a067a3
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A
3 changed files with 57 additions and 24 deletions

View File

@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR) cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
include(FetchContent)
if (NOT TARGET Freetype::Freetype) if (NOT TARGET Freetype::Freetype)
find_package(Freetype 2.12 CONFIG GLOBAL QUIET) find_package(Freetype 2.12 CONFIG GLOBAL QUIET)
endif()
if (NOT TARGET Freetype::Freetype) if (NOT TARGET Freetype::Freetype)
find_package(Freetype 2.12 GLOBAL QUIET) find_package(Freetype 2.12 GLOBAL QUIET)
@ -25,5 +24,3 @@ if (NOT TARGET Freetype::Freetype)
else() else()
message(STATUS "freetype not found") message(STATUS "freetype not found")
endif() endif()
endif()

View File

@ -2,10 +2,26 @@ cmake_minimum_required(VERSION 3.16...3.24 FATAL_ERROR)
include(FetchContent) include(FetchContent)
option(TOMATO_DEP_SDL_USE_SYSTEM "Prefer system provided SDL" OFF)
if (TOMATO_DEP_SDL_USE_SYSTEM)
if (NOT TARGET SDL3::SDL3) if (NOT TARGET SDL3::SDL3)
#find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared)
find_package(SDL3 REQUIRED CONFIG GLOBAL QUIET)
endif()
if (TARGET SDL3::SDL3)
message(STATUS "found system SDL3")
else()
message(STATUS "system SDL3 not found")
endif()
endif()
if (NOT TARGET SDL3::SDL3)
message(STATUS "using bundled SDL3")
# bundle sdl static
set(SDL_SHARED OFF CACHE INTERNAL "") set(SDL_SHARED OFF CACHE INTERNAL "")
set(SDL_STATIC ON CACHE INTERNAL "") set(SDL_STATIC ON CACHE INTERNAL "")
#TODO: pic ?
set(SDL_DISABLE_ANDROID_JAR OFF CACHE INTERNAL "") set(SDL_DISABLE_ANDROID_JAR OFF CACHE INTERNAL "")
FetchContent_Declare(SDL3 FetchContent_Declare(SDL3

View File

@ -2,6 +2,26 @@ cmake_minimum_required(VERSION 3.16...3.24 FATAL_ERROR)
include(FetchContent) include(FetchContent)
option(TOMATO_DEP_SDL_IMAGE_USE_SYSTEM "Prefer system provided SDL_image" OFF)
if (TOMATO_DEP_SDL_IMAGE_USE_SYSTEM)
if (NOT TARGET SDL3_image::SDL3_image)
find_package(SDL3_image REQUIRED CONFIG GLOBAL QUIET)
endif()
if (TARGET SDL3_image::SDL3_image)
message(STATUS "found system SDL3_image")
else()
message(STATUS "system SDL3_image not found")
endif()
endif()
if (SDLIMAGE_BACKEND_STB)
# mandatory security
# technically its only used if no proper libjpeg and libpng where found/configured
message(FATAL_ERROR "SDL3_image has the STBI backend enabled")
endif()
if (NOT TARGET SDL3_image::SDL3_image) if (NOT TARGET SDL3_image::SDL3_image)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
# TODO: make pr to make this an option # TODO: make pr to make this an option