Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / FindSDL_image.cmake
blob33a0695ccb4ab74829837f8c11b03e9ed404a82a
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:
5 FindSDL_image
6 -------------
8 Locate SDL_image library
10 This module defines:
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
18                              version of SDL_image
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 #]=======================================================================]
36 cmake_policy(PUSH)
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")
42 endif()
43 find_path(SDL_IMAGE_INCLUDE_DIR SDL_image.h
44   HINTS
45     ENV SDLIMAGEDIR
46     ENV SDLDIR
47   PATH_SUFFIXES SDL
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)
54 else()
55   set(VC_LIB_PATH_SUFFIX lib/x86)
56 endif()
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")
61 endif()
62 find_library(SDL_IMAGE_LIBRARY
63   NAMES SDL_image
64   HINTS
65     ENV SDLIMAGEDIR
66     ENV SDLDIR
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)
84 endif()
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)
102 cmake_policy(POP)