FindGIF.cmake 2.9 KB

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