1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Locate SDL_image library
14 SDL_IMAGE_LIBRARIES, the name of the library to link against
15 SDL_IMAGE_INCLUDE_DIRS, where to find the headers
16 SDL_IMAGE_FOUND, if false, do not try to link against
17 SDL_IMAGE_VERSION_STRING - human-readable string containing the
22 For backward compatibility the following variables are also set:
26 SDLIMAGE_LIBRARY (same value as SDL_IMAGE_LIBRARIES)
27 SDLIMAGE_INCLUDE_DIR (same value as SDL_IMAGE_INCLUDE_DIRS)
28 SDLIMAGE_FOUND (same value as SDL_IMAGE_FOUND)
32 $SDLDIR is an environment variable that would correspond to the
33 ./configure --prefix=$SDLDIR used in building SDL.
34 #]=======================================================================]
37 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
39 if(NOT SDL_IMAGE_INCLUDE_DIR AND SDLIMAGE_INCLUDE_DIR)
40 set(SDL_IMAGE_INCLUDE_DIR ${SDLIMAGE_INCLUDE_DIR} CACHE PATH "directory cache
41 entry initialized from old variable name")
43 find_path(SDL_IMAGE_INCLUDE_DIR SDL_image.h
48 # path suffixes to search inside ENV{SDLDIR}
49 include/SDL include/SDL12 include/SDL11 include
52 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
53 set(VC_LIB_PATH_SUFFIX lib/x64)
55 set(VC_LIB_PATH_SUFFIX lib/x86)
58 if(NOT SDL_IMAGE_LIBRARY AND SDLIMAGE_LIBRARY)
59 set(SDL_IMAGE_LIBRARY ${SDLIMAGE_LIBRARY} CACHE FILEPATH "file cache entry
60 initialized from old variable name")
62 find_library(SDL_IMAGE_LIBRARY
67 PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
70 if(SDL_IMAGE_INCLUDE_DIR AND EXISTS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h")
71 file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
72 file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
73 file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
74 string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MAJOR "${SDL_IMAGE_VERSION_MAJOR_LINE}")
75 string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MINOR "${SDL_IMAGE_VERSION_MINOR_LINE}")
76 string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_PATCH "${SDL_IMAGE_VERSION_PATCH_LINE}")
77 set(SDL_IMAGE_VERSION_STRING ${SDL_IMAGE_VERSION_MAJOR}.${SDL_IMAGE_VERSION_MINOR}.${SDL_IMAGE_VERSION_PATCH})
78 unset(SDL_IMAGE_VERSION_MAJOR_LINE)
79 unset(SDL_IMAGE_VERSION_MINOR_LINE)
80 unset(SDL_IMAGE_VERSION_PATCH_LINE)
81 unset(SDL_IMAGE_VERSION_MAJOR)
82 unset(SDL_IMAGE_VERSION_MINOR)
83 unset(SDL_IMAGE_VERSION_PATCH)
86 set(SDL_IMAGE_LIBRARIES ${SDL_IMAGE_LIBRARY})
87 set(SDL_IMAGE_INCLUDE_DIRS ${SDL_IMAGE_INCLUDE_DIR})
89 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
91 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_image
92 REQUIRED_VARS SDL_IMAGE_LIBRARIES SDL_IMAGE_INCLUDE_DIRS
93 VERSION_VAR SDL_IMAGE_VERSION_STRING)
95 # for backward compatibility
96 set(SDLIMAGE_LIBRARY ${SDL_IMAGE_LIBRARIES})
97 set(SDLIMAGE_INCLUDE_DIR ${SDL_IMAGE_INCLUDE_DIRS})
98 set(SDLIMAGE_FOUND ${SDL_IMAGE_FOUND})
100 mark_as_advanced(SDL_IMAGE_LIBRARY SDL_IMAGE_INCLUDE_DIR)