1 # - FindGTK2.cmake
2 # This module finds the GTK2/GTKMM widget libraries
3 #
4 # Specify one or more of the following components
5 # as you call this Find macro:
6 #
7 # gtk
8 # gtkmm
9 # glade
10 # glademm
11 #
12 # The following variables will be defined for your use
13 # GTK2_FOUND - Were all of your specified components found?
14 # GTK2_INCLUDE_DIRS - All include directories
15 # GTK2_LIBRARIES - All libraries
16 #
17 # Optional variables you can define prior to calling this module
18 # GTK2_DEBUG - Enables verbose debugging of the module
19 # GTK2_SKIP_MARK_AS_ADVANCED - Disable marking cache variables as advanced
20 #
21 #=================
22 # Example Usage:
23 #
24 # FIND_PACKAGE(GTK2 COMPONENTS gtk)
25 # or
26 # FIND_PACKAGE(GTK2 COMPONENTS gtk glade) # if you're also using glade
27 #
28 # INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS})
29 # ADD_EXECUTABLE(foo foo.cc)
30 # TARGET_LINK_LIBRARIES(foo ${GTK2_LIBRARIES})
31 #=================
32 #
33 # Copyright (c) 2008
34 # Philip Lowman <philip@yhbt.com>
35 #
36 # Version 0.6 (1/8/08)
37 # Added GTK2_SKIP_MARK_AS_ADVANCED option
38 # Version 0.5 (12/19/08)
39 # Second release to cmake mailing list
40 #
41 # Redistribution and use is allowed according to the terms of the BSD license.
42 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
44 #=============================================================
45 # _GTK2_FIND_INCLUDE_DIR
46 # Internal macro to find the GTK include directories
47 # _var = variable to set
48 # _hdr = header file to look for
49 #=============================================================
50 MACRO(_GTK2_FIND_INCLUDE_DIR _var _hdr)
52 IF(GTK2_DEBUG)
53 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}]
54 _GTK2_FIND_INCLUDE_DIR( ${_var} ${_hdr} )")
55 ENDIF()
57 SET(_relatives
58 # FIXME
59 glibmm-2.4
60 glib-2.0
61 atk-1.0
62 atkmm-1.6
63 cairo
64 cairomm-1.0
65 gdkmm-2.4
66 giomm-2.4
67 gtk-2.0
68 gtkmm-2.4
69 libglade-2.0
70 libglademm-2.4
71 pango-1.0
72 pangomm-1.4
73 sigc++-2.0
74 )
76 SET(_suffixes)
77 FOREACH(_d ${_relatives})
78 LIST(APPEND _suffixes ${_d})
79 LIST(APPEND _suffixes ${_d}/include) # for /usr/lib/gtk-2.0/include
80 ENDFOREACH()
82 IF(GTK2_DEBUG)
83 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] include suffixes = ${_suffixes}")
84 ENDIF()
86 FIND_PATH(${_var} ${_hdr}
87 PATHS
88 /usr/local/include
89 /usr/local/lib
90 /usr/include
91 /usr/lib
92 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/include
93 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
94 PATH_SUFFIXES
95 ${_suffixes}
96 )
98 IF(${_var})
99 LIST(APPEND GTK2_INCLUDE_DIRS ${${_var}})
100 IF(NOT GTK2_SKIP_MARK_AS_ADVANCED)
101 MARK_AS_ADVANCED(${_var})
102 ENDIF()
103 ENDIF()
104 ENDMACRO()
106 #=============================================================
107 # _GTK2_FIND_LIBRARY
108 # Internal macro to find libraries packaged with GTK2
109 # _var = library variable to create
110 #=============================================================
111 MACRO(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version)
113 IF(GTK2_DEBUG)
114 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}]
115 _GTK2_FIND_LIBRARY( ${_var} ${_lib} ${_expand_vc} ${_append_version} )")
116 ENDIF()
118 # Not GTK versions per se but the versions encoded into Windows
119 # import libraries (GtkMM 2.14.1 has a gtkmm-vc80-2_4.lib for example)
120 # Also the MSVC libraries use _ for . (this is handled below)
121 SET(_versions 2.20 2.18 2.16 2.14 2.12
122 2.10 2.8 2.6 2.4 2.2 2.0
123 1.20 1.18 1.16 1.14 1.12
124 1.10 1.8 1.6 1.4 1.2 1.0)
126 SET(_library)
127 SET(_library_d)
129 SET(_library ${_lib})
131 IF(${_expand_vc})
132 # Add vc80/vc90 midfixes
133 IF(MSVC80)
134 SET(_library ${_library}-vc80)
135 SET(_library_d ${_library}-d)
136 ELSEIF(MSVC90)
137 SET(_library ${_library}-vc90)
138 SET(_library_d ${_library}-d)
139 ENDIF()
140 ENDIF()
142 IF(GTK2_DEBUG)
143 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] After midfix addition = ${_library} and ${_library_d}")
144 ENDIF()
146 SET(_lib_list)
147 SET(_libd_list)
148 IF(${_append_version})
149 FOREACH(_ver ${_versions})
150 LIST(APPEND _lib_list "${_library}-${_ver}")
151 LIST(APPEND _libd_list "${_library_d}-${_ver}")
152 ENDFOREACH()
153 ELSE()
154 SET(_lib_list ${_library})
155 SET(_libd_list ${_library_d})
156 ENDIF()
158 IF(GTK2_DEBUG)
159 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] library list = ${_lib_list} and library debug list = ${_libd_list}")
160 ENDIF()
162 # For some silly reason the MSVC libraries use _ instead of .
163 # in the version fields
164 IF(${_expand_vc} AND MSVC)
165 SET(_no_dots_lib_list)
166 SET(_no_dots_libd_list)
167 FOREACH(_l ${_lib_list})
168 STRING(REPLACE "." "_" _no_dots_library ${_l})
169 LIST(APPEND _no_dots_lib_list ${_no_dots_library})
170 ENDFOREACH()
171 # And for debug
172 SET(_no_dots_libsd_list)
173 FOREACH(_l ${_libd_list})
174 STRING(REPLACE "." "_" _no_dots_libraryd ${_l})
175 LIST(APPEND _no_dots_libd_list ${_no_dots_libraryd})
176 ENDFOREACH()
178 # Copy list back to original names
179 SET(_lib_list ${_no_dots_lib_list})
180 SET(_libd_list ${_no_dots_libd_list})
181 ENDIF()
183 IF(GTK2_DEBUG)
184 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] Whilst searching for ${_var} our proposed library list is ${_lib_list}")
185 ENDIF()
187 FIND_LIBRARY(${_var}
188 NAMES ${_lib_list}
189 PATHS
190 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
191 )
192 IF(${_expand_vc} AND MSVC)
194 IF(GTK2_DEBUG)
195 MESSAGE(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] Whilst searching for ${_var}_DEBUG our proposed library list is ${_libd_list}")
196 ENDIF()
198 FIND_LIBRARY(${_var}_DEBUG
199 NAMES ${_libd_list}
200 PATHS
201 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
202 )
203 IF(NOT GTK2_SKIP_MARK_AS_ADVANCED)
204 MARK_AS_ADVANCED(${_var}_DEBUG)
205 ENDIF()
206 ELSE()
207 SET(${_var}_DEBUG ${${_var}})
208 ENDIF()
210 IF(${_var})
211 LIST(APPEND GTK2_LIBRARIES optimized ${${_var}} debug ${${_var}_DEBUG} )
212 IF(NOT GTK2_SKIP_MARK_AS_ADVANCED)
213 MARK_AS_ADVANCED(${_var})
214 ENDIF()
215 ENDIF()
216 ENDMACRO()
217 #=============================================================
219 #
220 # main()
221 #
223 SET(GTK2_FOUND)
224 SET(GTK2_INCLUDE_DIRS)
225 SET(GTK2_LIBRARIES)
227 IF(NOT GTK2_FIND_COMPONENTS)
228 MESSAGE(FATAL_ERROR "You must specify components with this module. See the documentation at the top of FindGTK2.cmake")
229 ENDIF()
231 FOREACH(_component ${GTK2_FIND_COMPONENTS})
232 IF(_component STREQUAL "gtk")
234 _GTK2_FIND_INCLUDE_DIR(GTK2_GLIB_INCLUDE_DIR glib.h)
235 _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBCONFIG_INCLUDE_DIR glibconfig.h)
236 _GTK2_FIND_LIBRARY (GTK2_GLIB_LIBRARY glib 0 1)
238 _GTK2_FIND_INCLUDE_DIR(GTK2_GDK_INCLUDE_DIR gdk/gdk.h)
239 _GTK2_FIND_INCLUDE_DIR(GTK2_GDKCONFIG_INCLUDE_DIR gdkconfig.h)
240 _GTK2_FIND_LIBRARY (GTK2_GDK_LIBRARY gdk-x11 0 1)
241 _GTK2_FIND_LIBRARY (GTK2_GDK_LIBRARY gdk-win32 0 1)
243 _GTK2_FIND_INCLUDE_DIR(GTK2_GTK_INCLUDE_DIR gtk/gtk.h)
244 _GTK2_FIND_LIBRARY (GTK2_GTK_LIBRARY gtk-x11 0 1)
245 _GTK2_FIND_LIBRARY (GTK2_GTK_LIBRARY gtk-win32 0 1)
247 _GTK2_FIND_INCLUDE_DIR(GTK2_CAIRO_INCLUDE_DIR cairo.h)
248 _GTK2_FIND_LIBRARY (GTK2_CAIRO_LIBRARY cairo 0 0)
250 _GTK2_FIND_INCLUDE_DIR(GTK2_PANGO_INCLUDE_DIR pango/pango.h)
251 _GTK2_FIND_LIBRARY (GTK2_PANGO_LIBRARY pango 0 1)
253 _GTK2_FIND_INCLUDE_DIR(GTK2_ATK_INCLUDE_DIR atk/atk.h)
254 _GTK2_FIND_LIBRARY (GTK2_ATK_LIBRARY atk 0 1)
256 #ELSEIF(_component STREQUAL "gdk_pixbuf")
257 #_GTK2_FIND_INCLUDE_DIR(GTK2_GDKPIXBUF_INCLUDE_DIR gdk-pixbuf/gdk-pixbuf.h)
258 #_GTK2_FIND_LIBRARY (GTK2_GDKPIXBUF_LIBRARY gdk_pixbuf 0 1)
260 ELSEIF(_component STREQUAL "gtkmm")
262 _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBMM_INCLUDE_DIR glibmm.h)
263 _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBMMCONFIG_INCLUDE_DIR glibmmconfig.h)
264 _GTK2_FIND_LIBRARY (GTK2_GLIBMM_LIBRARY glibmm 1 1)
266 _GTK2_FIND_INCLUDE_DIR(GTK2_GDKMM_INCLUDE_DIR gdkmm.h)
267 _GTK2_FIND_INCLUDE_DIR(GTK2_GDKMMCONFIG_INCLUDE_DIR gdkmmconfig.h)
268 _GTK2_FIND_LIBRARY (GTK2_GDKMM_LIBRARY gdkmm 1 1)
270 _GTK2_FIND_INCLUDE_DIR(GTK2_GTKMM_INCLUDE_DIR gtkmm.h)
271 _GTK2_FIND_INCLUDE_DIR(GTK2_GTKMMCONFIG_INCLUDE_DIR gtkmmconfig.h)
272 _GTK2_FIND_LIBRARY (GTK2_GTKMM_LIBRARY gtkmm 1 1)
274 _GTK2_FIND_INCLUDE_DIR(GTK2_CAIROMM_INCLUDE_DIR cairomm/cairomm.h)
275 _GTK2_FIND_LIBRARY (GTK2_CAIROMM_LIBRARY cairomm 1 1)
277 _GTK2_FIND_INCLUDE_DIR(GTK2_PANGOMM_INCLUDE_DIR pangomm.h)
278 _GTK2_FIND_LIBRARY (GTK2_PANGOMM_LIBRARY pangomm 1 1)
280 _GTK2_FIND_INCLUDE_DIR(GTK2_SIGC++_INCLUDE_DIR sigc++/sigc++.h)
281 _GTK2_FIND_INCLUDE_DIR(GTK2_SIGC++CONFIG_INCLUDE_DIR sigc++config.h)
282 _GTK2_FIND_LIBRARY (GTK2_SIGC++_LIBRARY sigc 1 1)
284 _GTK2_FIND_INCLUDE_DIR(GTK2_GIOMM_INCLUDE_DIR giomm.h)
285 _GTK2_FIND_INCLUDE_DIR(GTK2_GIOMMCONFIG_INCLUDE_DIR giommconfig.h)
286 _GTK2_FIND_LIBRARY (GTK2_GIOMM_LIBRARY giomm 1 1)
288 _GTK2_FIND_INCLUDE_DIR(GTK2_ATKMM_INCLUDE_DIR atkmm.h)
289 _GTK2_FIND_LIBRARY (GTK2_ATKMM_LIBRARY atkmm 1 1)
291 ELSEIF(_component STREQUAL "glade")
293 _GTK2_FIND_INCLUDE_DIR(GTK2_GLADE_INCLUDE_DIR glade/glade.h)
294 _GTK2_FIND_LIBRARY (GTK2_GLADE_LIBRARY glade 0 1)
296 ELSEIF(_component STREQUAL "glademm")
298 _GTK2_FIND_INCLUDE_DIR(GTK2_GLADEMM_INCLUDE_DIR libglademm.h)
299 _GTK2_FIND_INCLUDE_DIR(GTK2_GLADEMMCONFIG_INCLUDE_DIR libglademmconfig.h)
300 _GTK2_FIND_LIBRARY (GTK2_GLADEMM_LIBRARY glademm 1 1)
302 ELSE()
303 MESSAGE(FATAL_ERROR "Unknown GTK2 component ${_component}")
304 ENDIF()
305 ENDFOREACH()
307 #
308 # Try to enforce components
309 #
311 SET(_did_we_find_everything true) # This gets set to GTK2_FOUND
313 INCLUDE(FindPackageHandleStandardArgs)
315 FOREACH(_component ${GTK2_FIND_COMPONENTS})
316 STRING(TOUPPER ${_component} _COMPONENT_UPPER)
318 IF(_component STREQUAL "gtk")
319 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtk libraries were not found."
320 GTK2_GTK_LIBRARY
321 GTK2_GTK_INCLUDE_DIR
323 GTK2_GLIB_INCLUDE_DIR
324 GTK2_GLIBCONFIG_INCLUDE_DIR
325 GTK2_GLIB_LIBRARY
327 GTK2_GDK_INCLUDE_DIR
328 GTK2_GDKCONFIG_INCLUDE_DIR
329 GTK2_GDK_LIBRARY
330 )
331 ELSEIF(_component STREQUAL "gtkmm")
332 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtkmm libraries were not found."
333 GTK2_GTKMM_LIBRARY
334 GTK2_GTKMM_INCLUDE_DIR
335 GTK2_GTKMMCONFIG_INCLUDE_DIR
337 GTK2_GLIBMM_INCLUDE_DIR
338 GTK2_GLIBMMCONFIG_INCLUDE_DIR
339 GTK2_GLIBMM_LIBRARY
341 GTK2_GDKMM_INCLUDE_DIR
342 GTK2_GDKMMCONFIG_INCLUDE_DIR
343 GTK2_GDKMM_LIBRARY
344 )
345 ELSEIF(_component STREQUAL "glade")
346 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glade library was not found."
347 GTK2_GLADE_LIBRARY
348 GTK2_GLADE_INCLUDE_DIR
349 )
350 ELSEIF(_component STREQUAL "glademm")
351 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glademm library was not found."
352 GTK2_GLADEMM_LIBRARY
353 GTK2_GLADEMM_INCLUDE_DIR
354 GTK2_GLADEMMCONFIG_INCLUDE_DIR
355 )
356 ENDIF()
358 IF(NOT GTK2_${_COMPONENT_UPPER}_FOUND)
359 SET(_did_we_find_everything false)
360 ENDIF()
361 ENDFOREACH()
363 SET(GTK2_FOUND ${_did_we_find_everything})