Remove iconv/libiconv checks from *NIX builds: GLIB-2 provides iconv replacements.
[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   set(GLIB2_INCLUDE_DIRS
172     ${GLIB_INCLUDE_DIR}
173     ${GLIBCONFIG_INCLUDE_DIR}
174   )
175   set(GLIB2_LIBRARIES
176     ${GLIB_LIBRARY}
177   )
178
179   if (GMODULE2_FOUND)
180     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GMODULE2_LIBRARY})
181     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GMODULE2_INCLUDE_DIR})
182   endif (GMODULE2_FOUND)
183
184   if (GTHREAD2_FOUND)
185     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARY})
186     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GTHREAD2_INCLUDE_DIR})
187   endif (GTHREAD2_FOUND)
188
189   if (LIBINTL_FOUND)
190     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY})
191     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR})
192   endif (LIBINTL_FOUND)
193
194   if (GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
195      set(GLIB2_FOUND TRUE)
196   endif (GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
197
198   if (GLIB2_FOUND)
199     if (NOT GLIB2_FIND_QUIETLY)
200       message(STATUS "Found GLIB2: ${GLIB2_LIBRARIES}")
201     endif (NOT GLIB2_FIND_QUIETLY)
202   else (GLIB2_FOUND)
203     if (GLIB2_FIND_REQUIRED)
204       message(FATAL_ERROR "Could not find GLIB2")
205     endif (GLIB2_FIND_REQUIRED)
206   endif (GLIB2_FOUND)
207
208   # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view
209   mark_as_advanced(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES)
210
211 endif (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)