2017-01-05 23:42:52 +08:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2017-07-21 19:01:00 +08:00
|
|
|
project(SDL2_image C)
|
2017-01-05 23:42:52 +08:00
|
|
|
|
2017-01-07 02:08:31 +08:00
|
|
|
### configuration ###
|
2017-01-05 23:42:52 +08:00
|
|
|
|
2018-07-04 16:01:08 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CURRENT_INSTALLED_DIR}/share/libwebp")
|
2017-01-07 02:08:31 +08:00
|
|
|
# enable all file formats which are supported natively
|
2018-01-09 05:58:01 +08:00
|
|
|
set(SUPPORTED_FORMATS BMP GIF LBM PCX PNM TGA XPM XCF XV SVG)
|
2017-01-05 23:42:52 +08:00
|
|
|
|
2017-01-07 02:08:31 +08:00
|
|
|
# enable all file formats which are supported through external dependencies
|
|
|
|
# first try to load them statically (lib file in vcpkg installation)
|
|
|
|
# if this fails try to make them a dynamic dependency (dll will be loaded at runtime) if possible. vcpkg cannot resolve these dependencies!
|
|
|
|
# else do not support this file format at all
|
2018-07-04 16:01:08 +08:00
|
|
|
|
|
|
|
# Can be explicitly enabled or disabled via USE_XYZ
|
2017-01-07 02:08:31 +08:00
|
|
|
set(DEPENDENCIES PNG JPEG TIFF WEBP)
|
2017-01-05 23:42:52 +08:00
|
|
|
|
2017-01-07 02:08:31 +08:00
|
|
|
# patch library names for preprocessor flags
|
|
|
|
set(JPEG_FLAG JPG)
|
|
|
|
set(TIFF_FLAG TIF)
|
|
|
|
|
|
|
|
# names of potentially dynamically loaded libraries
|
|
|
|
set(JPEG_DYNAMIC \"libjpeg-9.dll\")
|
|
|
|
set(PNG_DYNAMIC \"libpng16-16.dll\")
|
|
|
|
set(TIFF_DYNAMIC \"libtiff-5.dll\")
|
|
|
|
set(WEBP_DYNAMIC \"libwebp-4.dll\")
|
|
|
|
|
|
|
|
### implementation ###
|
2017-01-05 23:42:52 +08:00
|
|
|
|
|
|
|
add_library(SDL2_image
|
|
|
|
IMG.c
|
2017-07-21 19:01:00 +08:00
|
|
|
IMG_bmp.c
|
|
|
|
IMG_gif.c
|
|
|
|
IMG_jpg.c
|
|
|
|
IMG_lbm.c
|
|
|
|
IMG_pcx.c
|
|
|
|
IMG_png.c
|
|
|
|
IMG_pnm.c
|
2018-01-09 05:58:01 +08:00
|
|
|
IMG_svg.c
|
2017-07-21 19:01:00 +08:00
|
|
|
IMG_tga.c
|
|
|
|
IMG_tif.c
|
|
|
|
IMG_webp.c
|
|
|
|
IMG_xcf.c
|
|
|
|
IMG_xpm.c
|
|
|
|
IMG_xv.c
|
|
|
|
IMG_xxx.c
|
2019-03-12 04:15:08 +08:00
|
|
|
IMG_WIC.c
|
2018-01-10 04:44:37 +08:00
|
|
|
version.rc
|
2017-07-21 19:01:00 +08:00
|
|
|
)
|
|
|
|
|
2019-03-27 00:57:16 +08:00
|
|
|
if (APPLE)
|
|
|
|
target_sources(SDL2_image PRIVATE
|
|
|
|
IMG_ImageIO.m
|
|
|
|
)
|
|
|
|
target_compile_options(SDL2_image BEFORE PRIVATE
|
|
|
|
"-x" "objective-c"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-07-21 19:01:00 +08:00
|
|
|
set_target_properties(SDL2_image PROPERTIES DEFINE_SYMBOL SDL2_EXPORTS)
|
2017-01-05 23:42:52 +08:00
|
|
|
|
2017-01-07 02:08:31 +08:00
|
|
|
foreach(FORMAT ${SUPPORTED_FORMATS})
|
2017-07-21 19:01:00 +08:00
|
|
|
add_definitions(-DLOAD_${FORMAT})
|
2017-01-07 02:08:31 +08:00
|
|
|
endforeach(FORMAT)
|
|
|
|
|
|
|
|
# SDL
|
|
|
|
find_path(SDL_INCLUDE_DIR SDL2/SDL.h)
|
2019-04-24 07:33:58 +08:00
|
|
|
find_library(SDL_LIBRARY_RELEASE NAMES SDL2)
|
|
|
|
find_library(SDL_LIBRARY_DEBUG NAMES SDL2d)
|
|
|
|
SET(SDL_LIBRARY
|
|
|
|
debug ${SDL_LIBRARY_DEBUG}
|
|
|
|
optimized ${SDL_LIBRARY_RELEASE}
|
|
|
|
)
|
2017-01-07 02:08:31 +08:00
|
|
|
|
|
|
|
include_directories(${SDL_INCLUDE_DIR})
|
|
|
|
include_directories(${SDL_INCLUDE_DIR}/SDL2)
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR})
|
|
|
|
|
2017-01-05 23:42:52 +08:00
|
|
|
target_link_libraries(SDL2_image ${SDL_LIBRARY})
|
|
|
|
|
2017-01-07 02:08:31 +08:00
|
|
|
# external dependencies
|
2018-07-04 16:01:08 +08:00
|
|
|
foreach(DEPENDENCY IN LISTS DEPENDENCIES)
|
|
|
|
if(NOT USE_${DEPENDENCY})
|
|
|
|
continue()
|
|
|
|
endif()
|
2017-07-21 19:01:00 +08:00
|
|
|
find_package(${DEPENDENCY})
|
|
|
|
|
|
|
|
if(NOT DEFINED ${DEPENDENCY}_FLAG)
|
|
|
|
set(${DEPENDENCY}_FLAG ${DEPENDENCY})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_definitions(-DLOAD_${${DEPENDENCY}_FLAG})
|
|
|
|
if(${DEPENDENCY}_FOUND)
|
|
|
|
message(STATUS " --> linking statically.")
|
|
|
|
target_link_libraries(SDL2_image ${${DEPENDENCY}_LIBRARIES})
|
|
|
|
elseif(DEFINED ${DEPENDENCY}_DYNAMIC)
|
|
|
|
message(STATUS " --> linking dynamically.")
|
|
|
|
add_definitions(-DLOAD_${${DEPENDENCY}_FLAG}_DYNAMIC=${${DEPENDENCY}_DYNAMIC})
|
|
|
|
set(RUNTIME_DEPENDENCIES ON)
|
|
|
|
else()
|
|
|
|
message(STATUS " --> skipping.")
|
|
|
|
endif()
|
2017-01-07 02:08:31 +08:00
|
|
|
endforeach(DEPENDENCY)
|
|
|
|
|
|
|
|
if(DEFINED RUNTIME_DEPENDENCIES)
|
2017-07-21 19:01:00 +08:00
|
|
|
include_directories(VisualC/external/include)
|
2017-01-07 02:08:31 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2017-01-05 23:42:52 +08:00
|
|
|
install(TARGETS SDL2_image
|
2019-03-27 00:57:16 +08:00
|
|
|
EXPORT SDL2_image
|
2017-01-05 23:42:52 +08:00
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib)
|
|
|
|
|
2017-01-07 18:51:07 +08:00
|
|
|
install(FILES SDL_image.h DESTINATION include/SDL2 CONFIGURATIONS Release)
|
2017-01-05 23:42:52 +08:00
|
|
|
|
2019-03-27 00:57:16 +08:00
|
|
|
install(EXPORT SDL2_image
|
|
|
|
DESTINATION share/sdl2-image/
|
|
|
|
FILE sdl2-image-config.cmake
|
|
|
|
NAMESPACE SDL2::
|
|
|
|
)
|
|
|
|
|
2017-01-05 23:42:52 +08:00
|
|
|
|
|
|
|
message(STATUS "Link-time dependencies:")
|
|
|
|
message(STATUS " " ${SDL_LIBRARY})
|
2017-01-07 02:08:31 +08:00
|
|
|
foreach(DEPENDENCY ${DEPENDENCIES})
|
2017-07-21 19:01:00 +08:00
|
|
|
if(${DEPENDENCY}_FOUND)
|
|
|
|
message(STATUS " " ${DEPENDENCY})
|
|
|
|
endif()
|
2017-01-07 02:08:31 +08:00
|
|
|
endforeach(DEPENDENCY)
|
|
|
|
|
|
|
|
if(DEFINED RUNTIME_DEPENDENCIES)
|
2017-07-21 19:01:00 +08:00
|
|
|
message(STATUS "Run-time dependencies:")
|
|
|
|
foreach(DEPENDENCY ${DEPENDENCIES})
|
|
|
|
if(NOT ${DEPENDENCY}_FOUND AND DEFINED ${DEPENDENCY}_DYNAMIC)
|
|
|
|
message(STATUS " " ${${DEPENDENCY}_DYNAMIC})
|
|
|
|
endif()
|
|
|
|
endforeach(DEPENDENCY)
|
|
|
|
endif()
|