2017-01-05 16:42:52 +01:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2017-07-21 13:01:00 +02:00
|
|
|
project(SDL2_image C)
|
2017-01-05 16:42:52 +01:00
|
|
|
|
2017-01-06 19:08:31 +01:00
|
|
|
### configuration ###
|
2017-01-05 16:42:52 +01:00
|
|
|
|
2017-01-06 19:08:31 +01:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
|
|
|
# enable all file formats which are supported natively
|
|
|
|
set(SUPPORTED_FORMATS BMP GIF LBM PCX PNM TGA XPM XCF XV)
|
2017-01-05 16:42:52 +01:00
|
|
|
|
2017-01-06 19:08:31 +01: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
|
|
|
|
set(DEPENDENCIES PNG JPEG TIFF WEBP)
|
2017-01-05 16:42:52 +01:00
|
|
|
|
2017-01-06 19:08:31 +01: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 16:42:52 +01:00
|
|
|
|
|
|
|
add_library(SDL2_image
|
|
|
|
IMG.c
|
2017-07-21 13:01:00 +02:00
|
|
|
IMG_bmp.c
|
|
|
|
IMG_gif.c
|
|
|
|
IMG_jpg.c
|
|
|
|
IMG_lbm.c
|
|
|
|
IMG_pcx.c
|
|
|
|
IMG_png.c
|
|
|
|
IMG_pnm.c
|
|
|
|
IMG_tga.c
|
|
|
|
IMG_tif.c
|
|
|
|
IMG_webp.c
|
|
|
|
IMG_xcf.c
|
|
|
|
IMG_xpm.c
|
|
|
|
IMG_xv.c
|
|
|
|
IMG_xxx.c
|
|
|
|
)
|
|
|
|
|
|
|
|
set_target_properties(SDL2_image PROPERTIES DEFINE_SYMBOL SDL2_EXPORTS)
|
2017-01-05 16:42:52 +01:00
|
|
|
|
2017-01-06 19:08:31 +01:00
|
|
|
foreach(FORMAT ${SUPPORTED_FORMATS})
|
2017-07-21 13:01:00 +02:00
|
|
|
add_definitions(-DLOAD_${FORMAT})
|
2017-01-06 19:08:31 +01:00
|
|
|
endforeach(FORMAT)
|
|
|
|
|
|
|
|
# SDL
|
|
|
|
find_path(SDL_INCLUDE_DIR SDL2/SDL.h)
|
2017-10-19 19:24:49 -07:00
|
|
|
find_library(SDL_LIBRARY NAMES SDL2d SDL2)
|
2017-01-06 19:08:31 +01:00
|
|
|
|
|
|
|
include_directories(${SDL_INCLUDE_DIR})
|
|
|
|
include_directories(${SDL_INCLUDE_DIR}/SDL2)
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR})
|
|
|
|
|
2017-01-05 16:42:52 +01:00
|
|
|
target_link_libraries(SDL2_image ${SDL_LIBRARY})
|
|
|
|
|
2017-01-06 19:08:31 +01:00
|
|
|
# external dependencies
|
|
|
|
foreach(DEPENDENCY ${DEPENDENCIES})
|
2017-07-21 13:01:00 +02: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-06 19:08:31 +01:00
|
|
|
endforeach(DEPENDENCY)
|
|
|
|
|
|
|
|
if(DEFINED RUNTIME_DEPENDENCIES)
|
2017-07-21 13:01:00 +02:00
|
|
|
include_directories(VisualC/external/include)
|
2017-01-06 19:08:31 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2017-01-05 16:42:52 +01:00
|
|
|
install(TARGETS SDL2_image
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib)
|
|
|
|
|
2017-01-07 11:51:07 +01:00
|
|
|
install(FILES SDL_image.h DESTINATION include/SDL2 CONFIGURATIONS Release)
|
2017-01-05 16:42:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
message(STATUS "Link-time dependencies:")
|
|
|
|
message(STATUS " " ${SDL_LIBRARY})
|
2017-01-06 19:08:31 +01:00
|
|
|
foreach(DEPENDENCY ${DEPENDENCIES})
|
2017-07-21 13:01:00 +02:00
|
|
|
if(${DEPENDENCY}_FOUND)
|
|
|
|
message(STATUS " " ${DEPENDENCY})
|
|
|
|
endif()
|
2017-01-06 19:08:31 +01:00
|
|
|
endforeach(DEPENDENCY)
|
|
|
|
|
|
|
|
if(DEFINED RUNTIME_DEPENDENCIES)
|
2017-07-21 13:01:00 +02: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()
|