FindGIF.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 Graphics Interchange Format (GIF) library (``giflib``)
  7. Imported targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines the following :prop_tgt:`IMPORTED` target:
  10. ``GIF::GIF``
  11. The ``giflib`` library, if found.
  12. Result variables
  13. ^^^^^^^^^^^^^^^^
  14. This module will set the following variables in your project:
  15. ``GIF_FOUND``
  16. If false, do not try to use GIF.
  17. ``GIF_INCLUDE_DIRS``
  18. where to find gif_lib.h, etc.
  19. ``GIF_LIBRARIES``
  20. the libraries needed to use GIF.
  21. ``GIF_VERSION``
  22. 3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6.
  23. Cache variables
  24. ^^^^^^^^^^^^^^^
  25. The following cache variables may also be set:
  26. ``GIF_INCLUDE_DIR``
  27. where to find the GIF headers.
  28. ``GIF_LIBRARY``
  29. where to find the GIF library.
  30. Hints
  31. ^^^^^
  32. ``GIF_DIR`` is an environment variable that would correspond to the
  33. ``./configure --prefix=$GIF_DIR``.
  34. #]=======================================================================]
  35. # Created by Eric Wing.
  36. # Modifications by Alexander Neundorf, Ben Campbell
  37. find_path(GIF_INCLUDE_DIR gif_lib.h
  38. HINTS
  39. ENV GIF_DIR
  40. PATH_SUFFIXES include
  41. )
  42. # the gif library can have many names :-/
  43. set(POTENTIAL_GIF_LIBS gif libgif ungif libungif giflib giflib4)
  44. find_library(GIF_LIBRARY
  45. NAMES ${POTENTIAL_GIF_LIBS}
  46. HINTS
  47. ENV GIF_DIR
  48. PATH_SUFFIXES lib
  49. )
  50. # Very basic version detection.
  51. # The GIF_LIB_VERSION string in gif_lib.h seems to be unreliable, since it seems
  52. # to be always " Version 2.0, " in versions 3.x of giflib.
  53. # In version 4 the member UserData was added to GifFileType, so we check for this
  54. # one.
  55. # Versions after 4.1.6 define GIFLIB_MAJOR, GIFLIB_MINOR, and GIFLIB_RELEASE
  56. # see http://giflib.sourceforge.net/gif_lib.html#compatibility
  57. if(GIF_INCLUDE_DIR)
  58. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  59. include(${CMAKE_CURRENT_LIST_DIR}/CheckStructHasMember.cmake)
  60. CMAKE_PUSH_CHECK_STATE()
  61. set(CMAKE_REQUIRED_QUIET ${GIF_FIND_QUIETLY})
  62. set(CMAKE_REQUIRED_INCLUDES "${GIF_INCLUDE_DIR}")
  63. # Check for the specific version defines (>=4.1.6 only)
  64. file(STRINGS ${GIF_INCLUDE_DIR}/gif_lib.h _GIF_DEFS REGEX "^[ \t]*#define[ \t]+GIFLIB_(MAJOR|MINOR|RELEASE)")
  65. if(_GIF_DEFS)
  66. # yay - got exact version info
  67. string(REGEX REPLACE ".*GIFLIB_MAJOR ([0-9]+).*" "\\1" _GIF_MAJ "${_GIF_DEFS}")
  68. string(REGEX REPLACE ".*GIFLIB_MINOR ([0-9]+).*" "\\1" _GIF_MIN "${_GIF_DEFS}")
  69. string(REGEX REPLACE ".*GIFLIB_RELEASE ([0-9]+).*" "\\1" _GIF_REL "${_GIF_DEFS}")
  70. set(GIF_VERSION "${_GIF_MAJ}.${_GIF_MIN}.${_GIF_REL}")
  71. else()
  72. # use UserData field to sniff version instead
  73. CHECK_STRUCT_HAS_MEMBER(GifFileType UserData gif_lib.h GIF_GifFileType_UserData )
  74. if(GIF_GifFileType_UserData)
  75. set(GIF_VERSION 4)
  76. else()
  77. set(GIF_VERSION 3)
  78. endif()
  79. endif()
  80. unset(_GIF_MAJ)
  81. unset(_GIF_MIN)
  82. unset(_GIF_REL)
  83. unset(_GIF_DEFS)
  84. CMAKE_POP_CHECK_STATE()
  85. endif()
  86. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  87. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GIF REQUIRED_VARS GIF_LIBRARY GIF_INCLUDE_DIR
  88. VERSION_VAR GIF_VERSION )
  89. if(GIF_FOUND)
  90. set(GIF_INCLUDE_DIRS "${GIF_INCLUDE_DIR}")
  91. set(GIF_LIBRARIES ${GIF_LIBRARY})
  92. if(NOT TARGET GIF::GIF)
  93. add_library(GIF::GIF UNKNOWN IMPORTED)
  94. set_target_properties(GIF::GIF PROPERTIES
  95. INTERFACE_INCLUDE_DIRECTORIES "${GIF_INCLUDE_DIRS}")
  96. if(EXISTS "${GIF_LIBRARY}")
  97. set_target_properties(GIF::GIF PROPERTIES
  98. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  99. IMPORTED_LOCATION "${GIF_LIBRARY}")
  100. endif()
  101. endif()
  102. endif()
  103. mark_as_advanced(GIF_INCLUDE_DIR GIF_LIBRARY)