Updating buildsystem files to closest as possible to file-sync plugin.
[gdataplugin.git] / cmake / modules / FindGLIB2.cmake
blobb393a01b533c538ac736cd3095aac2152deb9698
1 # - Try to find GLib2
2 # Once done this will define
4 #  GLIB2_FOUND - system has GLib2
5 #  GLIB2_INCLUDE_DIRS - the GLib2 include directory
6 #  GLIB2_LIBRARIES - Link these to use GLib2
8 #  Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
9 #  Copyright (c) 2006 Philippe Bernery <philippe.bernery@gmail.com>
10 #  Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
11 #  Copyright (c) 2007 Alban Browaeys <prahal@yahoo.com>
13 #  Redistribution and use is allowed according to the terms of the New
14 #  BSD license.
15 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
19 if (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
20   # in cache already
21   set(GLIB2_FOUND TRUE)
22 else (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
24   include(FindPkgConfig)
26   ## Glib
27   IF ( GLIB2_FIND_REQUIRED )
28     SET( _pkgconfig_REQUIRED "REQUIRED" )
29   ELSE ( GLIB2_FIND_REQUIRED )
30     SET( _pkgconfig_REQUIRED "" )
31   ENDIF ( GLIB2_FIND_REQUIRED )
33   pkg_search_module( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 )
35   # Look for glib2 include dir and libraries w/o pkgconfig
36   IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
37     find_path(_glibconfig_include_DIR
38       NAMES
39         glibconfig.h
40       PATHS
41         /opt/gnome/lib64/glib-2.0/include
42         /opt/gnome/lib/glib-2.0/include
43         /opt/lib/glib-2.0/include
44         /opt/local/lib/glib-2.0/include
45         /sw/lib/glib-2.0/include
46         /usr/lib64/glib-2.0/include
47         /usr/lib/glib-2.0/include
48         /usr/local/include/glib-2.0
49     )
51     find_path(_glib2_include_DIR
52       NAMES
53         glib.h
54       PATHS
55         /opt/gnome/include/glib-2.0
56         /opt/local/include/glib-2.0
57         /sw/include/glib-2.0
58         /usr/include/glib-2.0
59         /usr/local/include/glib-2.0
60     )
62     find_library( _glib2_link_DIR
63       NAMES
64         glib-2.0
65       PATHS
66         /opt/gnome/lib
67         /opt/local/lib
68         /sw/lib
69         /usr/lib
70         /usr/local/lib
71     )
72     IF ( _glib2_include_DIR AND _glib2_link_DIR )
73             SET ( _glib2_FOUND TRUE )
74     ENDIF ( _glib2_include_DIR AND _glib2_link_DIR )
77     IF ( _glib2_FOUND )
78             SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} )
79             SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} )
80     ENDIF ( _glib2_FOUND )
82     # Handle dependencies
83     # libintl
84     IF ( NOT LIBINTL_FOUND )
85       find_path(LIBINTL_INCLUDE_DIR
86         NAMES
87           libintl.h
88         NO_DEFAULT_PATH
89         PATHS
90           /opt/gnome/include
91           /opt/local/include
92           /sw/include
93           /usr/include
94           /usr/local/include
95       )
97       find_library(LIBINTL_LIBRARY
98         NAMES
99           intl
100         NO_DEFAULT_PATH
101         PATHS
102           /opt/gnome/lib
103           /opt/local/lib
104           /sw/lib
105           /usr/local/lib
106           /usr/lib
107       )
109       if (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
110         set(LIBINTL_FOUND TRUE)
111       endif (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
112     ENDIF ( NOT LIBINTL_FOUND )
114     # libiconv
115     IF ( NOT LIBICONV_FOUND )
116       find_path(LIBICONV_INCLUDE_DIR
117         NAMES
118           iconv.h
119         NO_DEFAULT_PATH
120         PATHS
121           /opt/gnome/include/glib-2.0
122           /opt/local/include/glib-2.0
123           /opt/local/include
124           /sw/include
125           /sw/include/glib-2.0
126           /usr/local/include/glib-2.0
127           /usr/include/glib-2.0
128       )
130       find_library(LIBICONV_LIBRARY
131         NAMES
132           iconv
133         NO_DEFAULT_PATH 
134         PATHS
135           /opt/gnome/lib
136           /opt/local/lib
137           /sw/lib
138           /usr/lib
139           /usr/local/lib
140       )
142       if (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
143         set(LIBICONV_FOUND TRUE)
144       endif (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
145     ENDIF ( NOT LIBICONV_FOUND )
147     if (LIBINTL_FOUND)
148       set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY})
149       set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR})
150     endif (LIBINTL_FOUND)
152     if (LIBICONV_FOUND)
153       set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
154       set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
155     endif (LIBICONV_FOUND)
157   ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
158   ##
160   ## GModule
161   pkg_search_module(GMODULE2 gmodule-2.0 )
163   # Look for gmodule2 include dir and libraries w/o pkgconfig
164   IF ( NOT GMODULE2_FOUND AND NOT PKG_CONFIG_FOUND )
165     find_path( GMODULE2_INCLUDE_DIR
166       NAMES
167         gmodule.h
168       PATHS
169         /opt/gnome/include/glib-2.0
170         /opt/local/include/glib-2.0
171         /sw/include/glib-2.0
172         /usr/include/glib-2.0
173         /usr/local/include/glib-2.0
174     )
176     find_library( GMODULE2_LIBRARY
177       NAMES
178         gmodule-2.0
179       PATHS
180         /opt/gnome/lib
181         /opt/local/lib
182         /sw/lib
183         /usr/lib
184         /usr/local/lib
185     )
187     if (GMODULE2_LIBRARY AND GMODULE2_INCLUDE_DIR)
188       set(GMODULE2_FOUND TRUE)
189     endif (GMODULE2_LIBRARY AND GMODULE2_INCLUDE_DIR)
191     if (GMODULE2_FOUND)
192       set(GMODULE2_INCLUDE_DIRS ${GMODULE2_INCLUDE_DIR})
193       set(GMODULE2_LIBRARIES ${GMODULE2_LIBRARY})
194     endif (GMODULE2_FOUND)
197     # Handle dependencies
198     # FIXME : glib2 - requires a split in different cmake modules and the user code to call the proper module instead of FindGLIB2 directly
200   ENDIF ( NOT GMODULE2_FOUND AND NOT PKG_CONFIG_FOUND )
201   ##
203   ## GThread
204   pkg_search_module( GTHREAD2 gthread-2.0)
206   # Look for gthread2 include dir and libraries w/o pkgconfig
207   IF ( NOT GTHREAD2_FOUND AND NOT PKG_CONFIG_FOUND )
208     find_path(GTHREAD2_INCLUDE_DIR
209       NAMES
210         gthread.h
211       PATHS
212         /opt/gnome/include/glib-2.0
213         /opt/local/include/glib-2.0
214         /sw/include/glib-2.0
215         /usr/include/glib-2.0
216         /usr/local/include/glib-2.0
217       PATH_SUFFIXES
218         glib
219     )
221     find_library(GTHREAD2_LIBRARY
222       NAMES
223         gthread-2.0
224       PATHS
225         /opt/gnome/lib
226         /opt/local/lib
227         /sw/lib
228         /usr/lib
229         /usr/local/lib
230     )
232     if (GTHREAD2_LIBRARY AND GTHREAD2_INCLUDE_DIR)
233       set(GTHREAD2_FOUND TRUE)
234     endif (GTHREAD2_LIBRARY AND GTHREAD2_INCLUDE_DIR)
236     if (GTHREAD2_FOUND)
237       set(GTHREAD2_INCLUDE_DIRS ${GTHREAD2_INCLUDE_DIR})
238       set(GTHREAD2_LIBRARIES ${GTHREAD2_LIBRARY})
239     endif (GTHREAD2_FOUND)
241     # Handle dependencies
242     # FIXME : glib2 - requires a split in different cmake modules and the user code to call the proper module instead of FindGLIB2 directly
244   ENDIF ( NOT GTHREAD2_FOUND AND NOT PKG_CONFIG_FOUND )
245   ##
247   ## GObject
248   pkg_search_module( GOBJECT2 gobject-2.0)
250   # Look for gmodule2 include dir and libraries w/o pkgconfig
251   IF ( NOT GOBJECT2_FOUND AND NOT PKG_CONFIG_FOUND )
252     find_path(GOBJECT2_INCLUDE_DIR
253       NAMES
254         gobject.h
255       PATHS
256         /opt/gnome/include/glib-2.0
257         /opt/local/include/glib-2.0
258         /sw/include/glib-2.0
259         /usr/include/glib-2.0
260         /usr/local/include/glib-2.0
261       PATH_SUFFIXES
262         gobject
263     )
265     find_library(GOBJECT2_LIBRARY
266       NAMES
267         gobject-2.0
268       PATHS
269         /opt/gnome/lib
270         /opt/local/lib
271         /sw/lib
272         /usr/lib
273         /usr/local/lib
274     )
276     if (GOBJECT2_LIBRARY AND GOBJECT2_INCLUDE_DIR)
277       set(GOBJECT2_FOUND TRUE)
278     endif (GOBJECT2_LIBRARY AND GOBJECT2_INCLUDE_DIR)
280     if (GOBJECT2_FOUND)
281       set(GOBJECT2_INCLUDE_DIRS ${GOBJECT2_INCLUDE_DIR})
282       set(GOBJECT2_LIBRARIES ${GOBJECT2_LIBRARY})
283     endif (GOBJECT2_FOUND)
285     # Handle dependencies
286     # FIXME : glib2 - requires a split in different cmake modules and the user code to call the proper module instead of FindGLIB2 directly
288   ENDIF ( NOT GOBJECT2_FOUND AND NOT PKG_CONFIG_FOUND )
289   ##
296   if (GMODULE2_FOUND)
297     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GMODULE2_LIBRARIES})
298     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GMODULE2_INCLUDE_DIRS})
299   endif (GMODULE2_FOUND)
301   if (GTHREAD2_FOUND)
302     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES})
303     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GTHREAD2_INCLUDE_DIRS})
304   endif (GTHREAD2_FOUND)
306   if (GOBJECT2_FOUND)
307     set(GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARY})
308     set(GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${GOBJECT2_INCLUDE_DIR})
309   endif (GOBJECT2_FOUND)
311   if (GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
312     set(GLIB2_FOUND TRUE)
313   endif (GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
315     if (GLIB2_FOUND)
316       if (NOT GLIB2_FIND_QUIETLY)
317         message(STATUS "Found GLib2: ${GLIB2_LIBRARIES}")
318       endif (NOT GLIB2_FIND_QUIETLY)
319     else (GLIB2_FOUND)
320       if (GLIB2_FIND_REQUIRED)
321         message(SEND_ERROR "Could not find GLib2")
322       endif (GLIB2_FIND_REQUIRED)
323     endif (GLIB2_FOUND)
325   # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view
326   mark_as_advanced(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES)
327   mark_as_advanced(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY)
328   mark_as_advanced(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY)
330   # same for all other variables
331   mark_as_advanced(GMODULE2_INCLUDE_DIR GMODULE2_LIBRARY)
332   mark_as_advanced(GMODULE2_INCLUDE_DIRS GMODULE2_LIBRARIES)
333   mark_as_advanced(GOBJECT2_INCLUDE_DIR GOBJECT2_LIBRARY)
334   mark_as_advanced(GOBJECT2_INCLUDE_DIRS GOBJECT2_LIBRARIES)
335   mark_as_advanced(GTHREAD2_INCLUDE_DIR GTHREAD2_LIBRARY)
336   mark_as_advanced(GTHREAD2_INCLUDE_DIRS GTHREAD2_LIBRARIES)
338 endif (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)