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
|
|
|
|
2017-01-07 02:08:31 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
|
|
|
# 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
|
|
|
|
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
|
2018-01-10 04:44:37 +08:00
|
|
|
version.rc
|
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)
|
2017-10-20 10:24:49 +08:00
|
|
|
find_library(SDL_LIBRARY NAMES SDL2d SDL2)
|
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
|
|
|
|
foreach(DEPENDENCY ${DEPENDENCIES})
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
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()
|