FindSDL_image.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSDL_image
  5. -------------
  6. Locate SDL_image library
  7. This module defines:
  8. ::
  9. SDL_IMAGE_LIBRARIES, the name of the library to link against
  10. SDL_IMAGE_INCLUDE_DIRS, where to find the headers
  11. SDL_IMAGE_FOUND, if false, do not try to link against
  12. SDL_IMAGE_VERSION_STRING - human-readable string containing the
  13. version of SDL_image
  14. For backward compatibility the following variables are also set:
  15. ::
  16. SDLIMAGE_LIBRARY (same value as SDL_IMAGE_LIBRARIES)
  17. SDLIMAGE_INCLUDE_DIR (same value as SDL_IMAGE_INCLUDE_DIRS)
  18. SDLIMAGE_FOUND (same value as SDL_IMAGE_FOUND)
  19. $SDLDIR is an environment variable that would correspond to the
  20. ./configure --prefix=$SDLDIR used in building SDL.
  21. Created by Eric Wing. This was influenced by the FindSDL.cmake
  22. module, but with modifications to recognize OS X frameworks and
  23. additional Unix paths (FreeBSD, etc).
  24. #]=======================================================================]
  25. if(NOT SDL_IMAGE_INCLUDE_DIR AND SDLIMAGE_INCLUDE_DIR)
  26. set(SDL_IMAGE_INCLUDE_DIR ${SDLIMAGE_INCLUDE_DIR} CACHE PATH "directory cache
  27. entry initialized from old variable name")
  28. endif()
  29. find_path(SDL_IMAGE_INCLUDE_DIR SDL_image.h
  30. HINTS
  31. ENV SDLIMAGEDIR
  32. ENV SDLDIR
  33. PATH_SUFFIXES SDL
  34. # path suffixes to search inside ENV{SDLDIR}
  35. include/SDL include/SDL12 include/SDL11 include
  36. )
  37. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  38. set(VC_LIB_PATH_SUFFIX lib/x64)
  39. else()
  40. set(VC_LIB_PATH_SUFFIX lib/x86)
  41. endif()
  42. if(NOT SDL_IMAGE_LIBRARY AND SDLIMAGE_LIBRARY)
  43. set(SDL_IMAGE_LIBRARY ${SDLIMAGE_LIBRARY} CACHE FILEPATH "file cache entry
  44. initialized from old variable name")
  45. endif()
  46. find_library(SDL_IMAGE_LIBRARY
  47. NAMES SDL_image
  48. HINTS
  49. ENV SDLIMAGEDIR
  50. ENV SDLDIR
  51. PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
  52. )
  53. if(SDL_IMAGE_INCLUDE_DIR AND EXISTS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h")
  54. file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
  55. file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
  56. file(STRINGS "${SDL_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
  57. string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MAJOR "${SDL_IMAGE_VERSION_MAJOR_LINE}")
  58. string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_MINOR "${SDL_IMAGE_VERSION_MINOR_LINE}")
  59. string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL_IMAGE_VERSION_PATCH "${SDL_IMAGE_VERSION_PATCH_LINE}")
  60. set(SDL_IMAGE_VERSION_STRING ${SDL_IMAGE_VERSION_MAJOR}.${SDL_IMAGE_VERSION_MINOR}.${SDL_IMAGE_VERSION_PATCH})
  61. unset(SDL_IMAGE_VERSION_MAJOR_LINE)
  62. unset(SDL_IMAGE_VERSION_MINOR_LINE)
  63. unset(SDL_IMAGE_VERSION_PATCH_LINE)
  64. unset(SDL_IMAGE_VERSION_MAJOR)
  65. unset(SDL_IMAGE_VERSION_MINOR)
  66. unset(SDL_IMAGE_VERSION_PATCH)
  67. endif()
  68. set(SDL_IMAGE_LIBRARIES ${SDL_IMAGE_LIBRARY})
  69. set(SDL_IMAGE_INCLUDE_DIRS ${SDL_IMAGE_INCLUDE_DIR})
  70. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  71. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_image
  72. REQUIRED_VARS SDL_IMAGE_LIBRARIES SDL_IMAGE_INCLUDE_DIRS
  73. VERSION_VAR SDL_IMAGE_VERSION_STRING)
  74. # for backward compatibility
  75. set(SDLIMAGE_LIBRARY ${SDL_IMAGE_LIBRARIES})
  76. set(SDLIMAGE_INCLUDE_DIR ${SDL_IMAGE_INCLUDE_DIRS})
  77. set(SDLIMAGE_FOUND ${SDL_IMAGE_FOUND})
  78. mark_as_advanced(SDL_IMAGE_LIBRARY SDL_IMAGE_INCLUDE_DIR)