From 538768e149d071563f6c3fb7436479c4b11aeb11 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Mon, 22 Jan 2024 01:08:19 +0100 Subject: [PATCH] cmake: add SDL3IMAGE_STRICT option OFF means not having a 3rd party dependency installed, means no configure failure. ON means a configure failure. --- .github/workflows/main.yml | 1 + CMakeLists.txt | 368 ++++++++++++++++++++++---------- cmake/SDL3_imageConfig.cmake.in | 33 +-- 3 files changed, 268 insertions(+), 134 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 79c42d75..428907f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -115,6 +115,7 @@ jobs: -DSDL3IMAGE_JXL=${{ !matrix.platform.nojxl }} \ -DSDL3IMAGE_TIF=ON \ -DSDL3IMAGE_WEBP=ON \ + -DSDL3IMAGE_STRICT=ON \ -DSDL3IMAGE_WERROR=ON \ -DCMAKE_INSTALL_PREFIX=prefix_cmake \ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=$PWD/build \ diff --git a/CMakeLists.txt b/CMakeLists.txt index f3081f9c..dd0f96ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,14 @@ cmake_dependent_option(SDL3IMAGE_DEPS_SHARED "Load dependencies dynamically" ON option(SDL3IMAGE_VENDORED "Use vendored third-party libraries" ${vendored_default}) option(SDL3IMAGE_WERROR "Treat warnings as errors" OFF) +option(SDL3IMAGE_STRICT "Fail when a dependency could not be found" OFF) +set(required "") +set(fatal_error "STATUS") +if(SDL3IMAGE_STRICT) + set(required "REQUIRED") + set(fatal_error "FATAL_ERROR") +endif() + option(SDL3IMAGE_SAMPLES "Build the SDL3_image sample program(s)" ${SDL3IMAGE_SAMPLES_DEFAULT}) cmake_dependent_option(SDL3IMAGE_SAMPLES_INSTALL "Install the SDL3_image sample program(s)" OFF "SDL3IMAGE_SAMPLES;SDL3IMAGE_INSTALL" OFF) @@ -327,13 +335,20 @@ set(INSTALL_EXTRA_TARGETS) set(INSTALL_EXTRA_CMAKE_MODULES) set(PC_LIBS) set(PC_REQUIRES) +set(SDL3IMAGE_BACKENDS) +list(APPEND SDL3IMAGE_BACKENDS STB) +set(SDL3IMAGE_STB_ENABLED FALSE) if(SDL3IMAGE_BACKEND_STB) + set(SDL3IMAGE_STB_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE USE_STBIMAGE) endif() +list(APPEND SDL3IMAGE_BACKENDS IMAGEIO) +set(SDL3IMAGE_IMAGEIO_ENABLED FALSE) if(APPLE) if(SDL3IMAGE_BACKEND_IMAGEIO) + set(SDL3IMAGE_IMAGEIO_ENABLED TRUE) target_link_libraries(${sdl3_image_target_name} PRIVATE -Wl,-framework,ApplicationServices) target_link_libraries(${sdl3_image_target_name} PRIVATE objc) target_sources(${sdl3_image_target_name} PRIVATE @@ -351,7 +366,10 @@ if(APPLE) endif() endif() +list(APPEND SDL3IMAGE_BACKENDS WIC) +set(SDL3IMAGE_WIC_ENABLED FALSE) if(SDL3IMAGE_BACKEND_WIC) + set(SDL3IMAGE_WIC_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE SDL_IMAGE_USE_WIC_BACKEND) endif() @@ -381,8 +399,7 @@ if(SDL3IMAGE_ZLIB) set_target_properties(${ZLIB_LIBRARY} PROPERTIES EXPORT_NAME external_zlib) add_library(SDL3_image::external_zlib ALIAS ${ZLIB_LIBRARY}) else() - message(STATUS "${PROJECT_NAME}: Using system zlib") - find_package(ZLIB REQUIRED) + message(FATAL_ERROR "Internal error (zlib is only required when requesting vendored dependencies)") endif() endif() @@ -396,13 +413,15 @@ if(SDL3IMAGE_DAV1D) list(APPEND INSTALL_EXTRA_TARGETS dav1d) endif() else() - message(FATAL_ERROR "Not implemented") + message(FATAL_ERROR "Internal error (dav1d is only required when requesting vendored dependencies)") endif() endif() +list(APPEND SDL3IMAGE_BACKENDS AVIF) +set(SDL3IMAGE_AVIF_ENABLED FALSE) if(SDL3IMAGE_AVIF) - target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_AVIF) if(SDL3IMAGE_AVIF_VENDORED) + set(SDL3IMAGE_AVIF_ENABLED TRUE) message(STATUS "${PROJECT_NAME}: Using vendored libavif") sdl_check_project_in_subfolder(external/libavif libavif SDL3IMAGE_VENDORED) set(BUILD_SHARED_LIBS ${SDL3IMAGE_AVIF_SHARED}) @@ -426,54 +445,63 @@ if(SDL3IMAGE_AVIF) endif() endif() else() - message(STATUS "${PROJECT_NAME}: Using system libavif") find_package(libavif 1.0 QUIET) if(NOT libavif_FOUND) - message(STATUS "libavif-1.0 or compatible not found") find_package(libavif ${LIBAVIF_MINIMUM_VERSION} QUIET) endif() if(libavif_FOUND) - message(STATUS "libavif-${libavif_VERSION} found") + message(STATUS "${PROJECT_NAME}: Using system libavif") + set(SDL3IMAGE_AVIF_ENABLED TRUE) + if(NOT SDL3IMAGE_AVIF_SHARED) + list(APPEND PC_REQUIRES libavif) + endif() else() message(STATUS "libavif-${LIBAVIF_MINIMUM_VERSION} or compatible not found") - message(FATAL_ERROR "libavif NOT found") - endif() - if(NOT SDL3IMAGE_AVIF_SHARED) - list(APPEND PC_REQUIRES libavif) + message(${fatal_error} "libavif NOT found") endif() endif() - if(SDL3IMAGE_AVIF_SHARED) - target_include_directories(${sdl3_image_target_name} PRIVATE - $ - $ - $ - ) - target_get_dynamic_library(dynamic_avif avif) - message(STATUS "Dynamic libavif: ${dynamic_avif}") - target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_AVIF_DYNAMIC=\"${dynamic_avif}\"") - if(SDL3IMAGE_AVIF_VENDORED) - add_dependencies(${sdl3_image_target_name} avif) + if(SDL3IMAGE_AVIF_ENABLED) + target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_AVIF) + if(SDL3IMAGE_AVIF_SHARED) + target_include_directories(${sdl3_image_target_name} PRIVATE + $ + $ + $ + ) + target_get_dynamic_library(dynamic_avif avif) + message(STATUS "Dynamic libavif: ${dynamic_avif}") + target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_AVIF_DYNAMIC=\"${dynamic_avif}\"") + if(SDL3IMAGE_AVIF_VENDORED) + add_dependencies(${sdl3_image_target_name} avif) + endif() + else() + target_link_libraries(${sdl3_image_target_name} PRIVATE avif) endif() - else() - target_link_libraries(${sdl3_image_target_name} PRIVATE avif) endif() endif() +list(APPEND SDL3IMAGE_BACKENDS BMP) +set(SDL3IMAGE_BMP_ENABLED FALSE) if(SDL3IMAGE_BMP) + set(SDL3IMAGE_BMP_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_BMP) endif() +list(APPEND SDL3IMAGE_BACKENDS GIF) +set(SDL3IMAGE_GIF_ENABLED FALSE) if(SDL3IMAGE_GIF) + set(SDL3IMAGE_GIF_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_GIF) endif() +list(APPEND SDL3IMAGE_BACKENDS JPG) +set(SDL3IMAGE_JPG_ENABLED FALSE) if(SDL3IMAGE_JPG) - target_compile_definitions(${sdl3_image_target_name} PRIVATE - LOAD_JPG - SDL_IMAGE_SAVE_JPG=$ - ) - if(NOT SDL3IMAGE_BACKEND_STB AND NOT SDL3IMAGE_BACKEND_WIC AND NOT SDL3IMAGE_BACKEND_IMAGEIO) + if(SDL3IMAGE_BACKEND_STB OR SDL3IMAGE_BACKEND_WIC OR SDL3IMAGE_BACKEND_IMAGEIO) + set(SDL3IMAGE_JPG_ENABLED TRUE) + else() if(SDL3IMAGE_JPG_VENDORED) + set(SDL3IMAGE_JPG_ENABLED TRUE) message(STATUS "${PROJECT_NAME}: Using vendored libjpeg") sdl_check_project_in_subfolder(external/jpeg libjpeg SDL3IMAGE_VENDORED) set(BUILD_SHARED_LIBS ${SDL3IMAGE_JPG_SHARED}) @@ -487,33 +515,48 @@ if(SDL3IMAGE_JPG) list(APPEND PC_LIBS -l$) endif() else() - message(STATUS "${PROJECT_NAME}: Using system libjpeg") - find_package(JPEG REQUIRED) - if(NOT SDL3IMAGE_JPG_SHARED) - list(APPEND PC_REQUIRES libjpeg) + find_package(JPEG ${required}) + if(JPEG_FOUND) + message(STATUS "${PROJECT_NAME}: Using system libjpeg") + set(SDL3IMAGE_JPG_ENABLED TRUE) + if(NOT SDL3IMAGE_JPG_SHARED) + list(APPEND PC_REQUIRES libjpeg) + endif() + else() + message(${fatal_error} "libjpeg NOT found") endif() endif() - if(SDL3IMAGE_JPG_SHARED) - target_include_directories(${sdl3_image_target_name} PRIVATE - $ - $ - $ - ) - target_get_dynamic_library(dynamic_jpeg JPEG::JPEG) - message(STATUS "Dynamic libjpeg: ${dynamic_jpeg}") - target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_JPG_DYNAMIC=\"${dynamic_jpeg}\"") - if(SDL3IMAGE_JPG_VENDORED) - add_dependencies(${sdl3_image_target_name} JPEG::JPEG) + if(SDL3IMAGE_JPG_ENABLED) + if(SDL3IMAGE_JPG_SHARED) + target_include_directories(${sdl3_image_target_name} PRIVATE + $ + $ + $ + ) + target_get_dynamic_library(dynamic_jpeg JPEG::JPEG) + message(STATUS "Dynamic libjpeg: ${dynamic_jpeg}") + target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_JPG_DYNAMIC=\"${dynamic_jpeg}\"") + if(SDL3IMAGE_JPG_VENDORED) + add_dependencies(${sdl3_image_target_name} JPEG::JPEG) + endif() + else() + target_link_libraries(${sdl3_image_target_name} PRIVATE JPEG::JPEG) endif() - else() - target_link_libraries(${sdl3_image_target_name} PRIVATE JPEG::JPEG) - endif() + endif() + endif() + if(SDL3IMAGE_JPG_ENABLED) + target_compile_definitions(${sdl3_image_target_name} PRIVATE + LOAD_JPG + SDL_IMAGE_SAVE_JPG=$ + ) endif() endif() +list(APPEND SDL3IMAGE_BACKENDS JXL) +set(SDL3IMAGE_JXL_ENABLED FALSE) if(SDL3IMAGE_JXL) - target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_JXL) if(SDL3IMAGE_JXL_VENDORED) + set(SDL3IMAGE_JXL_ENABLED TRUE) enable_language(CXX) message(STATUS "${PROJECT_NAME}: Using vendored libjxl") # BUILD_TESTING variable is used by libjxl @@ -553,45 +596,60 @@ if(SDL3IMAGE_JXL) add_library(libjxl::libjxl ALIAS ${jxl_lib}) endif() else() - message(STATUS "${PROJECT_NAME}: Using system libjxl") - find_package(libjxl REQUIRED) - if(NOT SDL3IMAGE_JXL_SHARED) - list(APPEND PC_REQUIRES libjxl) - list(APPEND INSTALL_EXTRA_CMAKE_MODULES cmake/Findlibjxl.cmake) + find_package(libjxl ${required}) + if(libjxl_FOUND) + message(STATUS "${PROJECT_NAME}: Using system libjxl") + set(SDL3IMAGE_JXL_ENABLED TRUE) + if(NOT SDL3IMAGE_JXL_SHARED) + list(APPEND PC_REQUIRES libjxl) + list(APPEND INSTALL_EXTRA_CMAKE_MODULES cmake/Findlibjxl.cmake) + endif() + else() + message(${fatal_error} "libjxl NOT found") endif() endif() - if(SDL3IMAGE_JXL_SHARED) - target_include_directories(${sdl3_image_target_name} PRIVATE - $ - $ - $ - ) - target_get_dynamic_library(dynamic_jxl libjxl::libjxl) - message(STATUS "Dynamic libjxl: ${dynamic_jxl}") - target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_JXL_DYNAMIC=\"${dynamic_jxl}\"") - if(SDL3IMAGE_JXL_VENDORED) - add_dependencies(${sdl3_image_target_name} libjxl::libjxl) + if(SDL3IMAGE_JXL_ENABLED) + target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_JXL) + if(SDL3IMAGE_JXL_SHARED) + target_include_directories(${sdl3_image_target_name} PRIVATE + $ + $ + $ + ) + target_get_dynamic_library(dynamic_jxl libjxl::libjxl) + message(STATUS "Dynamic libjxl: ${dynamic_jxl}") + target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_JXL_DYNAMIC=\"${dynamic_jxl}\"") + if(SDL3IMAGE_JXL_VENDORED) + add_dependencies(${sdl3_image_target_name} libjxl::libjxl) + endif() + else() + target_link_libraries(${sdl3_image_target_name} PRIVATE libjxl::libjxl) endif() - else() - target_link_libraries(${sdl3_image_target_name} PRIVATE libjxl::libjxl) endif() endif() +list(APPEND SDL3IMAGE_BACKENDS LBM) +set(SDL3IMAGE_LBM_ENABLED FALSE) if(SDL3IMAGE_LBM) + set(SDL3IMAGE_LBM_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_LBM) endif() +list(APPEND SDL3IMAGE_BACKENDS PCX) +set(SDL3IMAGE_PCX_ENABLED FALSE) if(SDL3IMAGE_PCX) + set(SDL3IMAGE_PCX_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_PCX) endif() +list(APPEND SDL3IMAGE_BACKENDS PNG) +set(SDL3IMAGE_PNG_ENABLED FALSE) if(SDL3IMAGE_PNG) - target_compile_definitions(${sdl3_image_target_name} PRIVATE - LOAD_PNG - SDL_IMAGE_SAVE_PNG=$ - ) - if(NOT SDL3IMAGE_BACKEND_STB AND NOT SDL3IMAGE_BACKEND_WIC AND NOT SDL3IMAGE_BACKEND_IMAGEIO) + if(SDL3IMAGE_BACKEND_STB OR SDL3IMAGE_BACKEND_WIC OR SDL3IMAGE_BACKEND_IMAGEIO) + set(SDL3IMAGE_PNG_ENABLED TRUE) + else() if(SDL3IMAGE_PNG_VENDORED) + set(SDL3IMAGE_PNG_ENABLED TRUE) message(STATUS "${PROJECT_NAME}: Using vendored libpng") set(PNG_TESTS OFF CACHE BOOL "Build PNG Tests" FORCE) sdl_check_project_in_subfolder(external/libpng libpng SDL3IMAGE_VENDORED) @@ -618,10 +676,15 @@ if(SDL3IMAGE_PNG) endif() endif() else() - message(STATUS "${PROJECT_NAME}: Using system libpng") - find_package(PNG REQUIRED) - if(NOT SDL3IMAGE_PNG_SHARED) - list(APPEND PC_REQUIRES libpng) + find_package(PNG ${required}) + if(PNG_FOUND) + message(STATUS "${PROJECT_NAME}: Using system libpng") + set(SDL3IMAGE_PNG_ENABLED TRUE) + if(NOT SDL3IMAGE_PNG_SHARED) + list(APPEND PC_REQUIRES libpng) + endif() + else() + message(${FATAL_ERROR} "libpnb NOT found") endif() endif() if(SDL3IMAGE_PNG_SHARED) @@ -640,27 +703,47 @@ if(SDL3IMAGE_PNG) target_link_libraries(${sdl3_image_target_name} PRIVATE PNG::PNG) endif() endif() + if(SDL3IMAGE_PNG_ENABLED) + target_compile_definitions(${sdl3_image_target_name} PRIVATE + LOAD_PNG + SDL_IMAGE_SAVE_PNG=$ + ) + endif() endif() +list(APPEND SDL3IMAGE_BACKENDS PNM) +set(SDL3IMAGE_PNM_ENABLED FALSE) if(SDL3IMAGE_PNM) + set(SDL3IMAGE_PNM_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_PNM) endif() +list(APPEND SDL3IMAGE_BACKENDS QOI) +set(SDL3IMAGE_QOI_ENABLED FALSE) if(SDL3IMAGE_QOI) + set(SDL3IMAGE_QOI_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_QOI) endif() +list(APPEND SDL3IMAGE_BACKENDS SVG) +set(SDL3IMAGE_SVG_ENABLED FALSE) if(SDL3IMAGE_SVG) + set(SDL3IMAGE_SVG_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_SVG) endif() +list(APPEND SDL3IMAGE_BACKENDS TGA) +set(SDL3IMAGE_TGA_ENABLED FALSE) if(SDL3IMAGE_TGA) + set(SDL3IMAGE_TGA_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_TGA) endif() +list(APPEND SDL3IMAGE_BACKENDS TIF) +set(SDL3IMAGE_TIF_ENABLED FALSE) if(SDL3IMAGE_TIF) - target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_TIF) if(SDL3IMAGE_TIF_VENDORED) + set(SDL3IMAGE_TIF_ENABLED TRUE) message(STATUS "${PROJECT_NAME}: Using vendored libtiff") # tiff-tests variable is used by vendored libtiff set(tiff-tests OFF CACHE BOOL "libtiff: tests" FORCE) @@ -697,33 +780,43 @@ if(SDL3IMAGE_TIF) list(APPEND PC_LIBS -l$) endif() else() - message(STATUS "${PROJECT_NAME}: Using system libtiff") - find_package(TIFF REQUIRED) - if(NOT SDL3IMAGE_TIF_SHARED) - list(APPEND PC_REQUIRES libtiff-4) + find_package(TIFF ${required}) + if(TIFF_FOUND) + message(STATUS "${PROJECT_NAME}: Using system libtiff") + set(SDL3IMAGE_TIF_ENABLED TRUE) + if(NOT SDL3IMAGE_TIF_SHARED) + list(APPEND PC_REQUIRES libtiff-4) + endif() + else() + message(${fatal_error} "libtiff NOT found") endif() endif() - if(SDL3IMAGE_TIF_SHARED) - target_include_directories(${sdl3_image_target_name} PRIVATE - $ - $ - $ - ) - target_get_dynamic_library(dynamic_tif TIFF::TIFF) - message(STATUS "Dynamic libtiff: ${dynamic_tif}") - target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_TIF_DYNAMIC=\"${dynamic_tif}\"") - if(SDL3IMAGE_TIF_VENDORED) - add_dependencies(${sdl3_image_target_name} TIFF::TIFF) + if(SDL3IMAGE_TIF_ENABLED) + target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_TIF) + if(SDL3IMAGE_TIF_SHARED) + target_include_directories(${sdl3_image_target_name} PRIVATE + $ + $ + $ + ) + target_get_dynamic_library(dynamic_tif TIFF::TIFF) + message(STATUS "Dynamic libtiff: ${dynamic_tif}") + target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_TIF_DYNAMIC=\"${dynamic_tif}\"") + if(SDL3IMAGE_TIF_VENDORED) + add_dependencies(${sdl3_image_target_name} TIFF::TIFF) + endif() + else() + target_link_libraries(${sdl3_image_target_name} PRIVATE TIFF::TIFF) endif() - else() - target_link_libraries(${sdl3_image_target_name} PRIVATE TIFF::TIFF) endif() endif() +list(APPEND SDL3IMAGE_BACKENDS WEBP) +set(SDL3IMAGE_WEBP_ENABLED FALSE) if(SDL3IMAGE_WEBP) - target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_WEBP) # missing cpufeatures if(SDL3IMAGE_WEBP_VENDORED) + set(SDL3IMAGE_WEBP_ENABLED TRUE) message(STATUS "${PROJECT_NAME}: Using vendored libwebp") sdl_check_project_in_subfolder(external/libwebp libwebp SDL3IMAGE_VENDORED) set(BUILD_SHARED_LIBS ${SDL3IMAGE_WEBP_SHARED}) @@ -742,45 +835,62 @@ if(SDL3IMAGE_WEBP) set_target_properties(sharpyuv PROPERTIES EXPORT_NAME "external_sharpyuv") add_library(SDL3_image::external_libwebp ALIAS webp) else() - message(STATUS "${PROJECT_NAME}: Using system libwebp") - find_package(webp REQUIRED) - if(NOT SDL3IMAGE_WEBP_SHARED) - list(APPEND PC_REQUIRES libwebp) - list(APPEND INSTALL_EXTRA_CMAKE_MODULES cmake/Findwebp.cmake) + find_package(webp ${required}) + if(webp_FOUND) + message(STATUS "${PROJECT_NAME}: Using system libwebp") + set(SDL3IMAGE_WEBP_ENABLED TRUE) + if(NOT SDL3IMAGE_WEBP_SHARED) + list(APPEND PC_REQUIRES libwebp) + list(APPEND INSTALL_EXTRA_CMAKE_MODULES cmake/Findwebp.cmake) + endif() + else() + message(${fatal_error} "libwebp NOT found") endif() endif() - if(SDL3IMAGE_WEBP_SHARED) - target_include_directories(${sdl3_image_target_name} PRIVATE - $ - $ - $ - $ - $ - $ - ) - target_get_dynamic_library(dynamic_webpdemux WebP::webpdemux) - message(STATUS "Dynamic libwebpdemux: ${dynamic_webpdemux}") - target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_WEBPDEMUX_DYNAMIC=\"${dynamic_webpdemux}\"") - target_get_dynamic_library(dynamic_webp WebP::webp) - message(STATUS "Dynamic libwebp: ${dynamic_webp}") - target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_WEBP_DYNAMIC=\"${dynamic_webp}\"") - if(SDL3IMAGE_WEBP_VENDORED) - add_dependencies(${sdl3_image_target_name} WebP::webp WebP::webpdemux) + if(SDL3IMAGE_WEBP_ENABLED) + target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_WEBP) + if(SDL3IMAGE_WEBP_SHARED) + target_include_directories(${sdl3_image_target_name} PRIVATE + $ + $ + $ + $ + $ + $ + ) + target_get_dynamic_library(dynamic_webpdemux WebP::webpdemux) + message(STATUS "Dynamic libwebpdemux: ${dynamic_webpdemux}") + target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_WEBPDEMUX_DYNAMIC=\"${dynamic_webpdemux}\"") + target_get_dynamic_library(dynamic_webp WebP::webp) + message(STATUS "Dynamic libwebp: ${dynamic_webp}") + target_compile_definitions(${sdl3_image_target_name} PRIVATE "LOAD_WEBP_DYNAMIC=\"${dynamic_webp}\"") + if(SDL3IMAGE_WEBP_VENDORED) + add_dependencies(${sdl3_image_target_name} WebP::webp WebP::webpdemux) + endif() + else() + target_link_libraries(${sdl3_image_target_name} PRIVATE WebP::webp WebP::webpdemux) endif() - else() - target_link_libraries(${sdl3_image_target_name} PRIVATE WebP::webp WebP::webpdemux) endif() endif() +list(APPEND SDL3IMAGE_BACKENDS XCF) +set(SDL3IMAGE_XCF_ENABLED FALSE) if(SDL3IMAGE_XCF) + set(SDL3IMAGE_XCF_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_XCF) endif() +list(APPEND SDL3IMAGE_BACKENDS XPM) +set(SDL3IMAGE_XPM_ENABLED FALSE) if(SDL3IMAGE_XPM) + set(SDL3IMAGE_XPM_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_XPM) endif() +list(APPEND SDL3IMAGE_BACKENDS XV) +set(SDL3IMAGE_XV_ENABLED FALSE) if(SDL3IMAGE_XV) + set(SDL3IMAGE_XV_ENABLED TRUE) target_compile_definitions(${sdl3_image_target_name} PRIVATE LOAD_XV) endif() @@ -933,3 +1043,25 @@ if(SDL3IMAGE_TESTS) enable_testing() add_subdirectory(test) endif() + + +set(available_deps) +set(unavailable_deps) +foreach(dep IN LISTS SDL3IMAGE_BACKENDS) + set(var SDL3IMAGE_${dep}_ENABLED) + if(NOT DEFINED ${var}) + message(AUTHOR_WARNING "${var} not defined") + endif() + if(${var}) + list(APPEND available_deps ${dep}) + else() + list(APPEND unavailable_deps ${dep}) + endif() +endforeach() +string(JOIN " " avail_str ${available_deps}) +string(TOLOWER "${avail_str}" avail_str) +string(JOIN " " unavail_str ${unavailable_deps}) +string(TOLOWER "${unavail_str}" unavail_str) +message(STATUS "SDL3_image backends:") +message(STATUS "- enabled: ${avail_str}") +message(STATUS "- disabled: ${unavail_str}") diff --git a/cmake/SDL3_imageConfig.cmake.in b/cmake/SDL3_imageConfig.cmake.in index 16e50bf5..d8507cb0 100644 --- a/cmake/SDL3_imageConfig.cmake.in +++ b/cmake/SDL3_imageConfig.cmake.in @@ -8,27 +8,28 @@ set_package_properties(SDL3_image PROPERTIES set(SDL3_image_FOUND ON) -set(SDL3IMAGE_AVIF @SDL3IMAGE_AVIF@) +set(SDL3IMAGE_AVIF @SDL3IMAGE_AVIF_ENABLED@) set(SDL3IMAGE_AVIF_SHARED @SDL3IMAGE_AVIF_SHARED@) -set(SDL3IMAGE_BMP @SDL3IMAGE_BMP@) -set(SDL3IMAGE_GIF @SDL3IMAGE_GIF@) -set(SDL3IMAGE_JPG @SDL3IMAGE_JPG@) +set(SDL3IMAGE_BMP @SDL3IMAGE_BMP_ENABLED@) +set(SDL3IMAGE_GIF @SDL3IMAGE_GIF_ENABLED@) +set(SDL3IMAGE_JPG @SDL3IMAGE_JPG_ENABLED@) set(SDL3IMAGE_JPG_SHARED @SDL3IMAGE_JPG_SHARED@) -set(SDL3IMAGE_JXL @SDL3IMAGE_JXL@) +set(SDL3IMAGE_JXL @SDL3IMAGE_JXL_ENABLED@) set(SDL3IMAGE_JXL_SHARED @SDL3IMAGE_JXL_SHARED@) -set(SDL3IMAGE_LBM @SDL3IMAGE_LBM@) -set(SDL3IMAGE_PCX @SDL3IMAGE_PCX@) -set(SDL3IMAGE_PNG @SDL3IMAGE_PNG@) +set(SDL3IMAGE_LBM @SDL3IMAGE_LBM_ENABLED@) +set(SDL3IMAGE_PCX @SDL3IMAGE_PCX_ENABLED@) +set(SDL3IMAGE_PNG @SDL3IMAGE_PNG_ENABLED@) set(SDL3IMAGE_PNG_SHARED @SDL3IMAGE_PNG_SHARED@) -set(SDL3IMAGE_PNM @SDL3IMAGE_PNM@) -set(SDL3IMAGE_QOI @SDL3IMAGE_QOI@) -set(SDL3IMAGE_SVG @SDL3IMAGE_SVG@) -set(SDL3IMAGE_TGA @SDL3IMAGE_TGA@) -set(SDL3IMAGE_TIF @SDL3IMAGE_TIF@) +set(SDL3IMAGE_PNM @SDL3IMAGE_PNM_ENABLED@) +set(SDL3IMAGE_QOI @SDL3IMAGE_QOI_ENABLED@) +set(SDL3IMAGE_SVG @SDL3IMAGE_SVG_ENABLED@) +set(SDL3IMAGE_TGA @SDL3IMAGE_TGA_ENABLED@) +set(SDL3IMAGE_TIF @SDL3IMAGE_TIF_ENABLED@) set(SDL3IMAGE_TIF_SHARED @SDL3IMAGE_TIF_SHARED@) -set(SDL3IMAGE_XCF @SDL3IMAGE_XCF@) -set(SDL3IMAGE_XPM @SDL3IMAGE_XPM@) -set(SDL3IMAGE_XV @SDL3IMAGE_XV@) +set(SDL3IMAGE_XCF @SDL3IMAGE_XCF_ENABLED@) +set(SDL3IMAGE_XPM @SDL3IMAGE_XPM_ENABLED@) +set(SDL3IMAGE_XV @SDL3IMAGE_XV_ENABLED@) +set(SDL3IMAGE_WEBP @SDL3IMAGE_WEBP_ENABLED@) set(SDL3IMAGE_WEBP_SHARED @SDL3IMAGE_WEBP_SHARED@) set(SDL3IMAGE_JPG_SAVE @SDL3IMAGE_JPG_SAVE@)