Debian Codegraph @

cmake/backports/3.15.7/FindGIF.cmake

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