devilutionX/3rdParty/SDL_image/CMakeLists.txt
Gleb Mazovetskiy 75222ccef8 Overhaul dependency options
Changes how dependency options are handled and moves them out of
`CMakeLists.txt`.

Major changes:

1. The static default now takes `TARGET_SUPPORTS_SHARED_LIBS` into account
2. The `DIST` setting no longer affects the static default.
3. The static option is now visible for system dependencies as well.
   (it was previously hidden by `cmake_dependent_option`).
4. The auto-detection mechanism for `libfmt` and `SDL_image` only
   applies if the setting has not been set.
5. SDL2 on Android is now also linked statically,
   resulting in a 1.1 MiB smaller APK.

When using non-system dependencies, the default should always be static,
as there are 2 main use cases for these:

1. Dependencies that we must currently vendor because our forks have
   significant changes that are not yet merged/released upstream.
2. Platforms that have no system packages, such as Android and iOS.

In both cases, static linking is the most appropriate default.
2021-12-07 18:32:25 +01:00

59 lines
2.1 KiB
CMake

include(dependency_options)
if(NOT DEFINED DEVILUTIONX_SYSTEM_LIBPNG)
find_package(PNG QUIET)
if(PNG_FOUND)
message("-- Found png ${PNG_VERSION_STRING}")
else()
message("-- Suitable system png package not found, will use png from source")
set(DEVILUTIONX_SYSTEM_LIBPNG OFF)
endif()
elseif(DEVILUTIONX_SYSTEM_LIBPNG)
# In previous versions of DevilutionX, libpng could be built from
# source even if `DEVILUTIONX_SYSTEM_LIBPNG` was true.
# Detect the older CMake cache and update to the new behaviour.
#
# This is a temporary upgrade path that will be removed one week from commit date.
find_package(PNG QUIET)
if(NOT PNG_FOUND)
set(DEVILUTIONX_SYSTEM_LIBPNG OFF CACHE BOOL "" FORCE)
endif()
endif()
dependency_options("libpng" DEVILUTIONX_SYSTEM_LIBPNG ON DEVILUTIONX_STATIC_LIBPNG)
if(DEVILUTIONX_SYSTEM_LIBPNG)
find_package(PNG REQUIRED)
else()
add_subdirectory(../libpng libpng)
endif()
include(FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent)
if(USE_SDL1)
FetchContent_Declare(SDL_image
URL https://github.com/libsdl-org/SDL_image/archive/refs/tags/release-1.2.12.tar.gz
URL_HASH MD5=5d499e3cf6be00bfb0a7bff1cbdbd348
)
else()
FetchContent_Declare(SDL_image
URL https://github.com/libsdl-org/SDL_image/archive/refs/tags/release-2.0.5.tar.gz
URL_HASH MD5=3446ed7ee3c700065dcb33426a9b0c6e
)
endif()
FetchContent_MakeAvailableExcludeFromAll(SDL_image)
if(DEVILUTIONX_STATIC_SDL_IMAGE)
add_library(SDL_image STATIC ${CMAKE_CURRENT_LIST_DIR}/IMG.c ${sdl_image_SOURCE_DIR}/IMG_png.c)
else()
add_library(SDL_image SHARED ${CMAKE_CURRENT_LIST_DIR}/IMG.c ${sdl_image_SOURCE_DIR}/IMG_png.c)
endif()
target_include_directories(SDL_image PRIVATE ${sdl_image_SOURCE_DIR})
target_compile_definitions(SDL_image PRIVATE LOAD_PNG SDL_IMAGE_USE_COMMON_BACKEND)
target_link_libraries(SDL_image PNG::PNG)
if(USE_SDL1)
target_link_libraries(SDL_image ${SDL_LIBRARY})
else()
target_link_libraries(SDL_image SDL2::SDL2)
add_library(SDL2::SDL2_image ALIAS SDL_image)
endif()