1 cmake_minimum_required(VERSION 2.6)
6 list(APPEND CMAKE_MODULE_PATH "${CURRENT_INSTALLED_DIR}/share/libwebp")
7 # enable all file formats which are supported natively
8 set(SUPPORTED_FORMATS BMP GIF LBM PCX PNM TGA XPM XCF XV SVG)
10 # enable all file formats which are supported through external dependencies
11 # first try to load them statically (lib file in vcpkg installation)
12 # if this fails try to make them a dynamic dependency (dll will be loaded at runtime) if possible. vcpkg cannot resolve these dependencies!
13 # else do not support this file format at all
15 # Can be explicitly enabled or disabled via USE_XYZ
16 set(DEPENDENCIES PNG JPEG TIFF WEBP)
18 # patch library names for preprocessor flags
22 # names of potentially dynamically loaded libraries
23 set(JPEG_DYNAMIC \"libjpeg-9.dll\")
24 set(PNG_DYNAMIC \"libpng16-16.dll\")
25 set(TIFF_DYNAMIC \"libtiff-5.dll\")
26 set(WEBP_DYNAMIC \"libwebp-4.dll\")
28 ### implementation ###
30 add_library(SDL2_image
52 target_sources(SDL2_image PRIVATE
55 target_compile_options(SDL2_image BEFORE PRIVATE
60 set_target_properties(SDL2_image PROPERTIES DEFINE_SYMBOL DLL_EXPORT)
62 foreach(FORMAT ${SUPPORTED_FORMATS})
63 add_definitions(-DLOAD_${FORMAT})
67 find_path(SDL_INCLUDE_DIR SDL2/SDL.h)
68 find_package(SDL2 CONFIG REQUIRED)
70 include_directories(${SDL_INCLUDE_DIR})
71 include_directories(${SDL_INCLUDE_DIR}/SDL2)
72 include_directories(${CMAKE_SOURCE_DIR})
74 target_link_libraries(SDL2_image SDL2::SDL2)
76 # external dependencies
77 foreach(DEPENDENCY IN LISTS DEPENDENCIES)
78 if(NOT USE_${DEPENDENCY})
81 find_package(${DEPENDENCY})
83 if(NOT DEFINED ${DEPENDENCY}_FLAG)
84 set(${DEPENDENCY}_FLAG ${DEPENDENCY})
87 add_definitions(-DLOAD_${${DEPENDENCY}_FLAG})
88 if(${DEPENDENCY}_FOUND)
89 message(STATUS " --> linking statically.")
90 target_link_libraries(SDL2_image ${${DEPENDENCY}_LIBRARIES})
91 elseif(DEFINED ${DEPENDENCY}_DYNAMIC)
92 message(STATUS " --> linking dynamically.")
93 add_definitions(-DLOAD_${${DEPENDENCY}_FLAG}_DYNAMIC=${${DEPENDENCY}_DYNAMIC})
94 set(RUNTIME_DEPENDENCIES ON)
96 message(STATUS " --> skipping.")
98 endforeach(DEPENDENCY)
100 if(DEFINED RUNTIME_DEPENDENCIES)
101 include_directories(VisualC/external/include)
105 install(TARGETS SDL2_image
107 RUNTIME DESTINATION bin
108 ARCHIVE DESTINATION lib
109 LIBRARY DESTINATION lib)
111 install(FILES SDL_image.h DESTINATION include/SDL2 CONFIGURATIONS Release)
113 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sdl2-image-config.cmake"
114 [[include(CMakeFindDependencyMacro)
115 find_dependency(SDL2 CONFIG)
116 include("${CMAKE_CURRENT_LIST_DIR}/sdl2-image-targets.cmake")
119 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdl2-image-config.cmake DESTINATION share/sdl2-image)
121 install(EXPORT SDL2_image
122 DESTINATION share/sdl2-image/
123 FILE sdl2-image-targets.cmake
127 message(STATUS "Link-time dependencies:")
128 message(STATUS " " SDL2::SDL2)
129 foreach(DEPENDENCY ${DEPENDENCIES})
130 if(${DEPENDENCY}_FOUND)
131 message(STATUS " " ${DEPENDENCY})
133 endforeach(DEPENDENCY)
135 if(DEFINED RUNTIME_DEPENDENCIES)
136 message(STATUS "Run-time dependencies:")
137 foreach(DEPENDENCY ${DEPENDENCIES})
138 if(NOT ${DEPENDENCY}_FOUND AND DEFINED ${DEPENDENCY}_DYNAMIC)
139 message(STATUS " " ${${DEPENDENCY}_DYNAMIC})
141 endforeach(DEPENDENCY)