Browse Source

Add CMake option to use system SDL_image

pull/3407/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
692217d1fe
  1. 8
      3rdParty/SDL_image/CMakeLists.txt
  2. 26
      CMake/FindSDL2_image.cmake
  3. 35
      CMakeLists.txt
  4. 3
      vcpkg.json

8
3rdParty/SDL_image/CMakeLists.txt vendored

@ -14,7 +14,12 @@ else()
endif()
FetchContent_MakeAvailableExcludeFromAll(SDL_image)
add_library(SDL_image STATIC ${CMAKE_CURRENT_LIST_DIR}/IMG.c ${sdl_image_SOURCE_DIR}/IMG_png.c)
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)
@ -23,4 +28,5 @@ 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()

26
CMake/FindSDL2_image.cmake

@ -0,0 +1,26 @@
find_package(PkgConfig)
pkg_check_modules(PC_SDL2_image QUIET SDL2_image>=2.0.0)
find_path(SDL2_image_INCLUDE_DIR SDL_image.h
HINTS ${PC_SDL2_image_INCLUDEDIR} ${PC_SDL2_image_INCLUDE_DIRS})
find_library(SDL2_image_LIBRARY
NAMES SDL2_image libSDL2_image
HINTS ${PC_SDL2_image_LIBDIR} ${PC_SDL2_image_LIBRARY_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SDL2_image DEFAULT_MSG
SDL2_image_INCLUDE_DIR SDL2_image_LIBRARY)
if(SDL2_image_FOUND AND NOT TARGET SDL2::SDL2_image)
add_library(SDL2::SDL2_image UNKNOWN IMPORTED)
set_target_properties(SDL2::SDL2_image PROPERTIES
IMPORTED_LOCATION ${SDL2_image_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${SDL2_image_INCLUDE_DIR})
endif()
if(SDL2_image_FOUND)
mark_as_advanced(SDL2_image_INCLUDE_DIR SDL2_image_LIBRARY)
set(SDL2_image_LIBRARIES ${SDL2_image_LIBRARY})
set(SDL2_image_INCLUDE_DIRS ${SDL2_image_INCLUDE_DIR})
endif()

35
CMakeLists.txt

@ -93,6 +93,10 @@ option(DEVILUTIONX_SYSTEM_LIBPNG "Use system-provided libpng" ON)
cmake_dependent_option(DEVILUTIONX_STATIC_LIBPNG "Link static libpng" OFF
"DEVILUTIONX_SYSTEM_LIBPNG AND NOT DIST" ON)
option(DEVILUTIONX_SYSTEM_SDL_IMAGE "Use system-provided SDL_image" ON)
cmake_dependent_option(DEVILUTIONX_STATIC_SDL_IMAGE "Link static SDL_image" OFF
"DEVILUTIONX_SYSTEM_SDL_IMAGE AND NOT DIST" ON)
if(NOT VERSION_NUM)
include(CMake/git.cmake)
get_git_tag(VERSION_NUM)
@ -313,7 +317,29 @@ if(NOT NONET AND NOT DISABLE_TCP)
endif()
endif()
add_subdirectory(3rdParty/SDL_image)
if(DEVILUTIONX_SYSTEM_SDL_IMAGE)
if(USE_SDL1)
find_package(SDL_image QUIET)
else()
# vcpkg uses sdl2-image as the package name
find_package(sdl2-image QUIET)
set(SDL_image_FOUND ${sdl2-image_FOUND})
if(NOT SDL_image_FOUND)
# Fall back on PkgConfig via FindSDL2_image.cmake
find_package(SDL2_image QUIET)
set(SDL_image_FOUND ${SDL2_image_FOUND})
endif()
endif()
if(SDL_image_FOUND)
message("-- Found SDL_image")
else()
message("-- Suitable system SDL_image package not found, will use SDL_image from source")
endif()
endif()
if(NOT SDL_image_FOUND)
add_subdirectory(3rdParty/SDL_image)
endif()
if(NOT NOSOUND)
if(DEVILUTIONX_SYSTEM_SDL_AUDIOLIB)
@ -986,14 +1012,15 @@ endif()
if(USE_SDL1)
target_link_libraries(libdevilutionx PUBLIC
${SDL_LIBRARY})
${SDL_LIBRARY}
SDL_image)
target_compile_definitions(libdevilutionx PUBLIC USE_SDL1)
else()
target_link_libraries(libdevilutionx PUBLIC
SDL2::SDL2
${SDL2_MAIN})
${SDL2_MAIN}
SDL2::SDL2_image)
endif()
target_link_libraries(libdevilutionx PUBLIC SDL_image)
if(NOT NOSOUND)
target_link_libraries(libdevilutionx PUBLIC SDL_audiolib)

3
vcpkg.json

@ -4,7 +4,8 @@
"dependencies": [
"fmt",
"libpng",
"sdl2"
"sdl2",
"sdl2-image"
],
"features": {
"encryption": {

Loading…
Cancel
Save