Parts of http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=1179
[obnox/wireshark/wip.git] / cmake / modules / FindGLIB2.cmake
1 # - Try to find GLIB2
2 # Once done this will define
3 #
4 #  GLIB2_FOUND - system has GLIB2
5 #  GLIB2_INCLUDE_DIRS - the GLIB2 include directory
6 #  GLIB2_LIBRARIES - Link these to use GLIB2
7 #  GLIB2_DEFINITIONS - Compiler switches required for using GLIB2
8 #
9 #  Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
10 #  Copyright (c) 2006 Philippe Bernery <philippe.bernery@gmail.com>
11 #
12 #  Redistribution and use is allowed according to the terms of the New
13 #  BSD license.
14 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
15 #
16
17
18 if (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)
19   # in cache already
20   set(GLIB2_FOUND TRUE)
21 else (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)
22   # use pkg-config to get the directories and then use these values
23   # in the FIND_PATH() and FIND_LIBRARY() calls
24   include(UsePkgConfig)
25
26   ## GLibConfig
27   find_path(GLIBCONFIG_INCLUDE_DIR
28     NAMES
29       glibconfig.h
30     PATHS
31       ${_GLIB2IncDir}
32       /opt/gnome/lib64/glib-2.0/include
33       /opt/gnome/lib/glib-2.0/include
34       /opt/lib/glib-2.0/include
35       /usr/lib64/glib-2.0/include
36       /usr/lib/glib-2.0/include
37       /sw/lib/glib-2.0/include
38   )
39   ##
40
41   ## Glib
42   pkgconfig(glib-2.0 _GLIB2IncDir _GLIB2LinkDir _GLIB2LinkFlags _GLIB2Cflags)
43
44   set(GLIB2_DEFINITIONS ${_GLIB2Cflags})
45
46   find_path(GLIB2_INCLUDE_DIR
47     NAMES
48       glib.h
49     PATHS
50       ${_GLIB2IncDir}
51       /opt/gnome/include/glib-2.0
52       /usr/include/glib-2.0
53       /usr/local/include/glib-2.0
54       /opt/local/include/glib-2.0
55       /sw/include/glib-2.0
56   )
57
58   find_library(GLIB2_LIBRARY
59     NAMES
60       glib-2.0
61     PATHS
62       ${_GLIB2LinkDir}
63       /opt/gnome/lib
64       /usr/lib
65       /usr/local/lib
66       /opt/local/lib
67       /sw/lib
68   )
69
70   set(GLIB2_LIBRARIES ${GLIB2_LIBRARY})
71   set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIR})
72   ##
73
74   ## GModule
75   pkgconfig(gmodule-2.0 _GMODULE2IncDir _GMODULE2LinkDir _GMODULE2LinkFlags _GMODULE2Cflags)
76
77   set(GMODULE2_DEFINITIONS ${_GMODULE2Cflags})
78
79   find_path(GMODULE2_INCLUDE_DIR
80     NAMES
81       gmodule.h
82     PATHS
83       ${_GMODULE2IncDir}
84       /opt/gnome/include/glib-2.0
85       /usr/include/glib-2.0
86       /usr/local/include/glib-2.0
87       /opt/local/include/glib-2.0
88       /sw/include/glib-2.0
89   )
90  
91   find_library(GMODULE2_LIBRARY
92     NAMES
93       gmodule-2.0
94     PATHS
95       ${_GMODULE2LinkDir}
96       /opt/gnome/lib
97       /usr/lib
98       /usr/local/lib
99       /opt/local/lib
100       /sw/lib
101   )
102   if (GMODULE2_LIBRARY AND GMODULE2_INCLUDE_DIR)
103     set(GMODULE2_FOUND TRUE)
104   endif (GMODULE2_LIBRARY AND GMODULE2_INCLUDE_DIR)
105   ##
106
107   ## GThread
108   pkgconfig(gthread-2.0 _GTHREAD2IncDir _GTHREAD2LinkDir _GTHREAD2LinkFlags _GTHREAD2Cflags)
109
110   set(GTHREAD2_DEFINITIONS ${_GTHREAD2Cflags})
111
112   find_path(GTHREAD2_INCLUDE_DIR
113     NAMES
114       gthread.h
115     PATHS
116       ${_GTHREAD2IncDir}
117       /opt/gnome/include/glib-2.0
118       /usr/include/glib-2.0
119       /usr/local/include/glib-2.0
120       /opt/local/include/glib-2.0
121       /sw/include/glib-2.0
122     PATH_SUFFIXES
123       glib
124   )
125  
126   find_library(GTHREAD2_LIBRARY
127     NAMES
128       gthread-2.0
129     PATHS
130       ${_GTHREAD2LinkDir}
131       /opt/gnome/lib
132       /usr/lib
133       /usr/local/lib
134       /opt/local/lib
135       /sw/lib
136   )
137
138   if (GTHREAD2_LIBRARY AND GTHREAD2_INCLUDE_DIR)
139     set(GTHREAD2_FOUND TRUE)
140   endif (GTHREAD2_LIBRARY AND GTHREAD2_INCLUDE_DIR)
141   ##
142
143   ## libintl
144   find_path(LIBINTL_INCLUDE_DIR
145     NAMES
146       libintl.h
147     PATHS
148       /opt/gnome/include/glib-2.0
149       /usr/include/glib-2.0
150       /usr/local/include/glib-2.0
151       /opt/local/include/glib-2.0
152       /sw/include/glib-2.0
153   )
154  
155   find_library(LIBINTL_LIBRARY
156     NAMES
157       intl
158     PATHS
159       /opt/gnome/lib
160       /usr/lib
161       /usr/local/lib
162       /opt/local/lib
163       /sw/lib
164   )
165
166   if (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
167     set(LIBINTL_FOUND TRUE)
168   endif (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
169   ##
170
171   ## libiconv
172   find_path(LIBICONV_INCLUDE_DIR
173     NAMES
174       iconv.h
175     PATHS
176       /opt/gnome/include/glib-2.0
177       /usr/include/glib-2.0
178       /usr/local/include/glib-2.0
179       /opt/local/include/glib-2.0
180       /sw/include/glib-2.0
181   )
182  
183   find_library(LIBICONV_LIBRARY
184     NAMES
185       iconv
186     PATHS
187       /opt/gnome/lib
188       /usr/lib
189       /usr/local/lib
190       /opt/local/lib
191       /sw/lib
192   )
193
194   if (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
195     set(LIBICONV_FOUND TRUE)
196   endif (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
197   ##
198
199   set(GLIB2_INCLUDE_DIRS
200     ${GLIB_INCLUDE_DIR}
201     ${GLIBCONFIG_INCLUDE_DIR}
202   )
203   set(GLIB2_LIBRARIES
204     ${GLIB_LIBRARY}
205   )
206
207   if (GMODULE2_FOUND)
208     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GMODULE2_LIBRARY})
209     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GMODULE2_INCLUDE_DIR})
210   endif (GMODULE2_FOUND)
211
212   if (GTHREAD2_FOUND)
213     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARY})
214     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GTHREAD2_INCLUDE_DIR})
215   endif (GTHREAD2_FOUND)
216
217   if (LIBINTL_FOUND)
218     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY})
219     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR})
220   endif (LIBINTL_FOUND)
221
222   if (LIBICONV_FOUND)
223     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
224     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
225   endif (LIBICONV_FOUND)
226
227   if (GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
228      set(GLIB2_FOUND TRUE)
229   endif (GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
230
231   if (GLIB2_FOUND)
232     if (NOT GLIB2_FIND_QUIETLY)
233       message(STATUS "Found GLIB2: ${GLIB2_LIBRARIES}")
234     endif (NOT GLIB2_FIND_QUIETLY)
235   else (GLIB2_FOUND)
236     if (GLIB2_FIND_REQUIRED)
237       message(FATAL_ERROR "Could not find GLIB2")
238     endif (GLIB2_FIND_REQUIRED)
239   endif (GLIB2_FOUND)
240
241   # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view
242   mark_as_advanced(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES)
243
244 endif (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)