Fix timers
[ryzomcore.git] / CMakeModules / FindGLIB2.cmake
blob942b04530a2b0739e06e3600e205cd0dbf2e4632
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 #  HAVE_GLIB_GREGEX_H  glib has gregex.h header and 
9 #                      supports g_regex_match_simple
11 #  Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
12 #  Copyright (c) 2006 Philippe Bernery <philippe.bernery@gmail.com>
13 #  Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
14 #  Copyright (c) 2007 Alban Browaeys <prahal@yahoo.com>
15 #  Copyright (c) 2008 Michael Bell <michael.bell@web.de>
16 #  Copyright (c) 2008 Bjoern Ricks <bjoern.ricks@googlemail.com>
18 #  Redistribution and use is allowed according to the terms of the New
19 #  BSD license.
20 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
24 IF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
25   # in cache already
26   SET(GLIB2_FOUND TRUE)
27 ELSE (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
29   INCLUDE(FindPkgConfig)
31   ## Glib
32   IF ( GLIB2_FIND_REQUIRED )
33     SET( _pkgconfig_REQUIRED "REQUIRED" )
34   ELSE ( GLIB2_FIND_REQUIRED )
35     SET( _pkgconfig_REQUIRED "" )
36   ENDIF ( GLIB2_FIND_REQUIRED )
38   IF ( GLIB2_MIN_VERSION )
39     PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0>=${GLIB2_MIN_VERSION} )
40   ELSE ( GLIB2_MIN_VERSION )
41     PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 )
42   ENDIF ( GLIB2_MIN_VERSION )
43   IF ( PKG_CONFIG_FOUND )
44     IF ( GLIB2_FOUND )
45       SET ( GLIB2_CORE_FOUND TRUE )
46     ELSE ( GLIB2_FOUND )
47       SET ( GLIB2_CORE_FOUND FALSE )
48     ENDIF ( GLIB2_FOUND )
49   ENDIF ( PKG_CONFIG_FOUND )
51   # Look for glib2 include dir and libraries w/o pkgconfig
52   IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
53     FIND_PATH(
54       _glibconfig_include_DIR
55     NAMES
56       glibconfig.h
57     PATHS
58       /opt/gnome/lib64
59       /opt/gnome/lib
60       /opt/lib/
61       /opt/local/lib
62       /sw/lib/
63       /usr/lib64
64       /usr/lib
65       /usr/local/include
66       ${CMAKE_LIBRARY_PATH}
67     PATH_SUFFIXES
68       glib-2.0/include
69     )
71     FIND_PATH(
72       _glib2_include_DIR
73     NAMES
74       glib.h
75     PATHS
76       /opt/gnome/include
77       /opt/local/include
78       /sw/include
79       /usr/include
80       /usr/local/include
81     PATH_SUFFIXES
82       glib-2.0
83     )
85     #MESSAGE(STATUS "Glib headers: ${_glib2_include_DIR}")
87     FIND_LIBRARY(
88       _glib2_link_DIR
89     NAMES
90       glib-2.0
91       glib
92     PATHS
93       /opt/gnome/lib
94       /opt/local/lib
95       /sw/lib
96       /usr/lib
97       /usr/local/lib
98     )
99     IF ( _glib2_include_DIR AND _glib2_link_DIR )
100         SET ( _glib2_FOUND TRUE )
101     ENDIF ( _glib2_include_DIR AND _glib2_link_DIR )
104     IF ( _glib2_FOUND )
105         SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} )
106         SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} )
107         SET ( GLIB2_CORE_FOUND TRUE )
108     ELSE ( _glib2_FOUND )
109         SET ( GLIB2_CORE_FOUND FALSE )
110     ENDIF ( _glib2_FOUND )
112     # Handle dependencies
113     # libintl
114     IF ( NOT LIBINTL_FOUND )
115       FIND_PATH(LIBINTL_INCLUDE_DIR
116       NAMES
117         libintl.h
118       PATHS
119         /opt/gnome/include
120         /opt/local/include
121         /sw/include
122         /usr/include
123         /usr/local/include
124       )
126       FIND_LIBRARY(LIBINTL_LIBRARY
127       NAMES
128         intl
129       PATHS
130         /opt/gnome/lib
131         /opt/local/lib
132         /sw/lib
133         /usr/local/lib
134         /usr/lib
135       )
137       IF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
138         SET (LIBINTL_FOUND TRUE)
139       ENDIF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
140     ENDIF ( NOT LIBINTL_FOUND )
142     # libiconv
143     IF ( NOT LIBICONV_FOUND )
144       FIND_PATH(LIBICONV_INCLUDE_DIR
145       NAMES
146         iconv.h
147       PATHS
148         /opt/gnome/include
149         /opt/local/include
150         /opt/local/include
151         /sw/include
152         /sw/include
153         /usr/local/include
154         /usr/include
155       PATH_SUFFIXES
156         glib-2.0
157       )
159       FIND_LIBRARY(LIBICONV_LIBRARY
160       NAMES
161         iconv
162       PATHS
163         /opt/gnome/lib
164         /opt/local/lib
165         /sw/lib
166         /usr/lib
167         /usr/local/lib
168       )
170       IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
171         SET (LIBICONV_FOUND TRUE)
172       ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
173     ENDIF ( NOT LIBICONV_FOUND )
175     IF (LIBINTL_FOUND)
176       SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY})
177       SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR})
178     ENDIF (LIBINTL_FOUND)
180     IF (LIBICONV_FOUND)
181       SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
182       SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
183     ENDIF (LIBICONV_FOUND)
185   ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
186   ##
188   IF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
189     SET (GLIB2_FOUND TRUE)
190   ENDIF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
192   IF (GLIB2_FOUND)
193     IF (NOT GLIB2_FIND_QUIETLY)
194       MESSAGE (STATUS "Found GLib2: ${GLIB2_LIBRARIES} ${GLIB2_INCLUDE_DIRS}")
195     ENDIF (NOT GLIB2_FIND_QUIETLY)
196   ELSE (GLIB2_FOUND)
197     IF (GLIB2_FIND_REQUIRED)
198       MESSAGE (SEND_ERROR "Could not find GLib2")
199     ENDIF (GLIB2_FIND_REQUIRED)
200   ENDIF (GLIB2_FOUND)
202   # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view
203   MARK_AS_ADVANCED(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES)
204   MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY)
205   MARK_AS_ADVANCED(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY)
207 ENDIF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)
209 IF ( GLIB2_FOUND )
210         # Check if system has a newer version of glib
211         # which supports g_regex_match_simple
212         INCLUDE( CheckIncludeFiles )
213         SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} )
214         CHECK_INCLUDE_FILES ( glib/gregex.h HAVE_GLIB_GREGEX_H )
215         # Reset CMAKE_REQUIRED_INCLUDES
216         SET( CMAKE_REQUIRED_INCLUDES "" )
217 ENDIF( GLIB2_FOUND )