FindGIF.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. FindGIF
  5. -------
  6. This finds the GIF library (giflib)
  7. The module defines the following variables:
  8. ``GIF_FOUND``
  9. True if giflib was found
  10. ``GIF_LIBRARIES``
  11. Libraries to link to in order to use giflib
  12. ``GIF_INCLUDE_DIR``
  13. where to find the headers
  14. ``GIF_VERSION``
  15. 3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6
  16. The minimum required version of giflib can be specified using the
  17. standard syntax, e.g. find_package(GIF 4)
  18. $GIF_DIR is an environment variable that would correspond to the
  19. ./configure --prefix=$GIF_DIR
  20. #]=======================================================================]
  21. # Created by Eric Wing.
  22. # Modifications by Alexander Neundorf, Ben Campbell
  23. find_path(GIF_INCLUDE_DIR gif_lib.h
  24. HINTS
  25. ENV GIF_DIR
  26. PATH_SUFFIXES include
  27. )
  28. # the gif library can have many names :-/
  29. set(POTENTIAL_GIF_LIBS gif libgif ungif libungif giflib giflib4)
  30. find_library(GIF_LIBRARY
  31. NAMES ${POTENTIAL_GIF_LIBS}
  32. HINTS
  33. ENV GIF_DIR
  34. PATH_SUFFIXES lib
  35. )
  36. # see readme.txt
  37. set(GIF_LIBRARIES ${GIF_LIBRARY})
  38. # Very basic version detection.
  39. # The GIF_LIB_VERSION string in gif_lib.h seems to be unreliable, since it seems
  40. # to be always " Version 2.0, " in versions 3.x of giflib.
  41. # In version 4 the member UserData was added to GifFileType, so we check for this
  42. # one.
  43. # Versions after 4.1.6 define GIFLIB_MAJOR, GIFLIB_MINOR, and GIFLIB_RELEASE
  44. # see http://giflib.sourceforge.net/gif_lib.html#compatibility
  45. if(GIF_INCLUDE_DIR)
  46. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  47. include(${CMAKE_CURRENT_LIST_DIR}/CheckStructHasMember.cmake)
  48. CMAKE_PUSH_CHECK_STATE()
  49. set(CMAKE_REQUIRED_QUIET ${GIF_FIND_QUIETLY})
  50. set(CMAKE_REQUIRED_INCLUDES "${GIF_INCLUDE_DIR}")
  51. # Check for the specific version defines (>=4.1.6 only)
  52. file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h _GIF_DEFS REGEX "^[ \t]*#define[ \t]+GIFLIB_(MAJOR|MINOR|RELEASE)")
  53. if(_GIF_DEFS)
  54. # yay - got exact version info
  55. string(REGEX REPLACE ".*GIFLIB_MAJOR ([0-9]+).*" "\\1" _GIF_MAJ "${_GIF_DEFS}")
  56. string(REGEX REPLACE ".*GIFLIB_MINOR ([0-9]+).*" "\\1" _GIF_MIN "${_GIF_DEFS}")
  57. string(REGEX REPLACE ".*GIFLIB_RELEASE ([0-9]+).*" "\\1" _GIF_REL "${_GIF_DEFS}")
  58. set(GIF_VERSION "${_GIF_MAJ}.${_GIF_MIN}.${_GIF_REL}")
  59. else()
  60. # use UserData field to sniff version instead
  61. CHECK_STRUCT_HAS_MEMBER(GifFileType UserData gif_lib.h GIF_GifFileType_UserData )
  62. if(GIF_GifFileType_UserData)
  63. set(GIF_VERSION 4)
  64. else()
  65. set(GIF_VERSION 3)
  66. endif()
  67. endif()
  68. unset(_GIF_MAJ)
  69. unset(_GIF_MIN)
  70. unset(_GIF_REL)
  71. unset(_GIF_DEFS)
  72. CMAKE_POP_CHECK_STATE()
  73. endif()
  74. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  75. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GIF REQUIRED_VARS GIF_LIBRARY GIF_INCLUDE_DIR
  76. VERSION_VAR GIF_VERSION )
  77. mark_as_advanced(GIF_INCLUDE_DIR GIF_LIBRARY)