FindGTK2.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. # - FindGTK2.cmake
  2. # This module can find the GTK2 widget libraries and several of its other
  3. # optional components like gtkmm, glade, and glademm.
  4. #
  5. # NOTE: If you intend to use version checking, CMake 2.6.2 or later is
  6. # required.
  7. #
  8. # Specify one or more of the following components
  9. # as you call this find module. See example below.
  10. #
  11. # gtk
  12. # gtkmm
  13. # glade
  14. # glademm
  15. #
  16. # The following variables will be defined for your use
  17. #
  18. # GTK2_FOUND - Were all of your specified components found?
  19. # GTK2_INCLUDE_DIRS - All include directories
  20. # GTK2_LIBRARIES - All libraries
  21. #
  22. # GTK2_VERSION - The version of GTK2 found (x.y.z)
  23. # GTK2_MAJOR_VERSION - The major version of GTK2
  24. # GTK2_MINOR_VERSION - The minor version of GTK2
  25. # GTK2_PATCH_VERSION - The patch version of GTK2
  26. #
  27. # Optional variables you can define prior to calling this module:
  28. #
  29. # GTK2_DEBUG - Enables verbose debugging of the module
  30. # GTK2_SKIP_MARK_AS_ADVANCED - Disable marking cache variables as advanced
  31. # GTK2_ADDITIONAL_SUFFIXES - Allows defining additional directories to
  32. # search for include files
  33. #
  34. #=================
  35. # Example Usage:
  36. #
  37. # Call find_package() once, here are some examples to pick from:
  38. #
  39. # Require GTK 2.6 or later
  40. # find_package(GTK2 2.6 REQUIRED gtk)
  41. #
  42. # Require GTK 2.10 or later and Glade
  43. # find_package(GTK2 2.10 REQUIRED gtk glade)
  44. #
  45. # Search for GTK/GTKMM 2.8 or later
  46. # find_package(GTK2 2.8 COMPONENTS gtk gtkmm)
  47. #
  48. # if(GTK2_FOUND)
  49. # include_directories(${GTK2_INCLUDE_DIRS})
  50. # add_executable(mygui mygui.cc)
  51. # target_link_libraries(mygui ${GTK2_LIBRARIES})
  52. # endif()
  53. #
  54. #=============================================================================
  55. # Copyright 2009 Kitware, Inc.
  56. # Copyright 2008-2009 Philip Lowman <[email protected]>
  57. #
  58. # Distributed under the OSI-approved BSD License (the "License");
  59. # see accompanying file Copyright.txt for details.
  60. #
  61. # This software is distributed WITHOUT ANY WARRANTY; without even the
  62. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  63. # See the License for more information.
  64. #=============================================================================
  65. # (To distribute this file outside of CMake, substitute the full
  66. # License text for the above reference.)
  67. # Version 1.3 (11/9/2010) (CMake 2.8.4)
  68. # * 11429: Add support for detecting GTK2 built with Visual Studio 10.
  69. # Thanks to Vincent Levesque for the patch.
  70. # Version 1.2 (8/30/2010) (CMake 2.8.3)
  71. # * Merge patch for detecting gdk-pixbuf library (split off
  72. # from core GTK in 2.21). Thanks to Vincent Untz for the patch
  73. # and Ricardo Cruz for the heads up.
  74. # Version 1.1 (8/19/2010) (CMake 2.8.3)
  75. # * Add support for detecting GTK2 under macports (thanks to Gary Kramlich)
  76. # Version 1.0 (8/12/2010) (CMake 2.8.3)
  77. # * Add support for detecting new pangommconfig.h header file
  78. # (Thanks to Sune Vuorela & the Debian Project for the patch)
  79. # * Add support for detecting fontconfig.h header
  80. # * Call find_package(Freetype) since it's required
  81. # * Add support for allowing users to add additional library directories
  82. # via the GTK2_ADDITIONAL_SUFFIXES variable (kind of a future-kludge in
  83. # case the GTK developers change versions on any of the directories in the
  84. # future).
  85. # Version 0.8 (1/4/2010)
  86. # * Get module working under MacOSX fink by adding /sw/include, /sw/lib
  87. # to PATHS and the gobject library
  88. # Version 0.7 (3/22/09)
  89. # * Checked into CMake CVS
  90. # * Added versioning support
  91. # * Module now defaults to searching for GTK if COMPONENTS not specified.
  92. # * Added HKCU prior to HKLM registry key and GTKMM specific environment
  93. # variable as per mailing list discussion.
  94. # * Added lib64 to include search path and a few other search paths where GTK
  95. # may be installed on Unix systems.
  96. # * Switched to lowercase CMake commands
  97. # * Prefaced internal variables with _GTK2 to prevent collision
  98. # * Changed internal macros to functions
  99. # * Enhanced documentation
  100. # Version 0.6 (1/8/08)
  101. # Added GTK2_SKIP_MARK_AS_ADVANCED option
  102. # Version 0.5 (12/19/08)
  103. # Second release to cmake mailing list
  104. #=============================================================
  105. # _GTK2_GET_VERSION
  106. # Internal function to parse the version number in gtkversion.h
  107. # _OUT_major = Major version number
  108. # _OUT_minor = Minor version number
  109. # _OUT_micro = Micro version number
  110. # _gtkversion_hdr = Header file to parse
  111. #=============================================================
  112. function(_GTK2_GET_VERSION _OUT_major _OUT_minor _OUT_micro _gtkversion_hdr)
  113. file(READ ${_gtkversion_hdr} _contents)
  114. if(_contents)
  115. string(REGEX REPLACE ".*#define GTK_MAJOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_major} "${_contents}")
  116. string(REGEX REPLACE ".*#define GTK_MINOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_minor} "${_contents}")
  117. string(REGEX REPLACE ".*#define GTK_MICRO_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_micro} "${_contents}")
  118. if(NOT ${_OUT_major} MATCHES "[0-9]+")
  119. message(FATAL_ERROR "Version parsing failed for GTK2_MAJOR_VERSION!")
  120. endif()
  121. if(NOT ${_OUT_minor} MATCHES "[0-9]+")
  122. message(FATAL_ERROR "Version parsing failed for GTK2_MINOR_VERSION!")
  123. endif()
  124. if(NOT ${_OUT_micro} MATCHES "[0-9]+")
  125. message(FATAL_ERROR "Version parsing failed for GTK2_MICRO_VERSION!")
  126. endif()
  127. set(${_OUT_major} ${${_OUT_major}} PARENT_SCOPE)
  128. set(${_OUT_minor} ${${_OUT_minor}} PARENT_SCOPE)
  129. set(${_OUT_micro} ${${_OUT_micro}} PARENT_SCOPE)
  130. else()
  131. message(FATAL_ERROR "Include file ${_gtkversion_hdr} does not exist")
  132. endif()
  133. endfunction()
  134. #=============================================================
  135. # _GTK2_FIND_INCLUDE_DIR
  136. # Internal function to find the GTK include directories
  137. # _var = variable to set
  138. # _hdr = header file to look for
  139. #=============================================================
  140. function(_GTK2_FIND_INCLUDE_DIR _var _hdr)
  141. if(GTK2_DEBUG)
  142. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  143. "_GTK2_FIND_INCLUDE_DIR( ${_var} ${_hdr} )")
  144. endif()
  145. set(_relatives
  146. # If these ever change, things will break.
  147. ${GTK2_ADDITIONAL_SUFFIXES}
  148. glibmm-2.4
  149. glib-2.0
  150. atk-1.0
  151. atkmm-1.6
  152. cairo
  153. cairomm-1.0
  154. gdk-pixbuf-2.0
  155. gdkmm-2.4
  156. giomm-2.4
  157. gtk-2.0
  158. gtkmm-2.4
  159. libglade-2.0
  160. libglademm-2.4
  161. pango-1.0
  162. pangomm-1.4
  163. sigc++-2.0
  164. )
  165. set(_suffixes)
  166. foreach(_d ${_relatives})
  167. list(APPEND _suffixes ${_d})
  168. list(APPEND _suffixes ${_d}/include) # for /usr/lib/gtk-2.0/include
  169. endforeach()
  170. if(GTK2_DEBUG)
  171. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  172. "include suffixes = ${_suffixes}")
  173. endif()
  174. find_path(${_var} ${_hdr}
  175. PATHS
  176. /usr/local/lib64
  177. /usr/local/lib
  178. /usr/lib64
  179. /usr/lib
  180. /opt/gnome/include
  181. /opt/gnome/lib
  182. /opt/openwin/include
  183. /usr/openwin/lib
  184. /sw/include
  185. /sw/lib
  186. /opt/local/include
  187. /opt/local/lib
  188. $ENV{GTKMM_BASEPATH}/include
  189. $ENV{GTKMM_BASEPATH}/lib
  190. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/include
  191. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
  192. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/include
  193. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
  194. PATH_SUFFIXES
  195. ${_suffixes}
  196. )
  197. if(${_var})
  198. set(GTK2_INCLUDE_DIRS ${GTK2_INCLUDE_DIRS} ${${_var}} PARENT_SCOPE)
  199. if(NOT GTK2_SKIP_MARK_AS_ADVANCED)
  200. mark_as_advanced(${_var})
  201. endif()
  202. endif()
  203. endfunction(_GTK2_FIND_INCLUDE_DIR)
  204. #=============================================================
  205. # _GTK2_FIND_LIBRARY
  206. # Internal function to find libraries packaged with GTK2
  207. # _var = library variable to create
  208. #=============================================================
  209. function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version)
  210. if(GTK2_DEBUG)
  211. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  212. "_GTK2_FIND_LIBRARY( ${_var} ${_lib} ${_expand_vc} ${_append_version} )")
  213. endif()
  214. # Not GTK versions per se but the versions encoded into Windows
  215. # import libraries (GtkMM 2.14.1 has a gtkmm-vc80-2_4.lib for example)
  216. # Also the MSVC libraries use _ for . (this is handled below)
  217. set(_versions 2.20 2.18 2.16 2.14 2.12
  218. 2.10 2.8 2.6 2.4 2.2 2.0
  219. 1.20 1.18 1.16 1.14 1.12
  220. 1.10 1.8 1.6 1.4 1.2 1.0)
  221. set(_library)
  222. set(_library_d)
  223. set(_library ${_lib})
  224. if(_expand_vc AND MSVC)
  225. # Add vc80/vc90/vc100 midfixes
  226. if(MSVC80)
  227. set(_library ${_library}-vc80)
  228. elseif(MSVC90)
  229. set(_library ${_library}-vc90)
  230. elseif(MSVC10)
  231. set(_library ${_library}-vc100)
  232. endif()
  233. set(_library_d ${_library}-d)
  234. endif()
  235. if(GTK2_DEBUG)
  236. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  237. "After midfix addition = ${_library} and ${_library_d}")
  238. endif()
  239. set(_lib_list)
  240. set(_libd_list)
  241. if(_append_version)
  242. foreach(_ver ${_versions})
  243. list(APPEND _lib_list "${_library}-${_ver}")
  244. list(APPEND _libd_list "${_library_d}-${_ver}")
  245. endforeach()
  246. else()
  247. set(_lib_list ${_library})
  248. set(_libd_list ${_library_d})
  249. endif()
  250. if(GTK2_DEBUG)
  251. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  252. "library list = ${_lib_list} and library debug list = ${_libd_list}")
  253. endif()
  254. # For some silly reason the MSVC libraries use _ instead of .
  255. # in the version fields
  256. if(_expand_vc AND MSVC)
  257. set(_no_dots_lib_list)
  258. set(_no_dots_libd_list)
  259. foreach(_l ${_lib_list})
  260. string(REPLACE "." "_" _no_dots_library ${_l})
  261. list(APPEND _no_dots_lib_list ${_no_dots_library})
  262. endforeach()
  263. # And for debug
  264. set(_no_dots_libsd_list)
  265. foreach(_l ${_libd_list})
  266. string(REPLACE "." "_" _no_dots_libraryd ${_l})
  267. list(APPEND _no_dots_libd_list ${_no_dots_libraryd})
  268. endforeach()
  269. # Copy list back to original names
  270. set(_lib_list ${_no_dots_lib_list})
  271. set(_libd_list ${_no_dots_libd_list})
  272. endif()
  273. if(GTK2_DEBUG)
  274. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  275. "While searching for ${_var}, our proposed library list is ${_lib_list}")
  276. endif()
  277. find_library(${_var}
  278. NAMES ${_lib_list}
  279. PATHS
  280. /opt/gnome/lib
  281. /opt/gnome/lib64
  282. /usr/openwin/lib
  283. /usr/openwin/lib64
  284. /sw/lib
  285. $ENV{GTKMM_BASEPATH}/lib
  286. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
  287. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
  288. )
  289. if(_expand_vc AND MSVC)
  290. if(GTK2_DEBUG)
  291. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  292. "While searching for ${_var}_DEBUG our proposed library list is ${_libd_list}")
  293. endif()
  294. find_library(${_var}_DEBUG
  295. NAMES ${_libd_list}
  296. PATHS
  297. $ENV{GTKMM_BASEPATH}/lib
  298. [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
  299. [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
  300. )
  301. if(${_var} AND ${_var}_DEBUG)
  302. if(NOT GTK2_SKIP_MARK_AS_ADVANCED)
  303. mark_as_advanced(${_var}_DEBUG)
  304. endif()
  305. set(GTK2_LIBRARIES ${GTK2_LIBRARIES} optimized ${${_var}} debug ${${_var}_DEBUG})
  306. set(GTK2_LIBRARIES ${GTK2_LIBRARIES} PARENT_SCOPE)
  307. endif()
  308. else()
  309. if(NOT GTK2_SKIP_MARK_AS_ADVANCED)
  310. mark_as_advanced(${_var})
  311. endif()
  312. set(GTK2_LIBRARIES ${GTK2_LIBRARIES} ${${_var}})
  313. set(GTK2_LIBRARIES ${GTK2_LIBRARIES} PARENT_SCOPE)
  314. # Set debug to release
  315. set(${_var}_DEBUG ${${_var}})
  316. set(${_var}_DEBUG ${${_var}} PARENT_SCOPE)
  317. endif()
  318. endfunction(_GTK2_FIND_LIBRARY)
  319. #=============================================================
  320. #
  321. # main()
  322. #
  323. set(GTK2_FOUND)
  324. set(GTK2_INCLUDE_DIRS)
  325. set(GTK2_LIBRARIES)
  326. if(NOT GTK2_FIND_COMPONENTS)
  327. # Assume they only want GTK
  328. set(GTK2_FIND_COMPONENTS gtk)
  329. endif()
  330. #
  331. # If specified, enforce version number
  332. #
  333. if(GTK2_FIND_VERSION)
  334. cmake_minimum_required(VERSION 2.6.2)
  335. set(GTK2_FAILED_VERSION_CHECK true)
  336. if(GTK2_DEBUG)
  337. message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
  338. "Searching for version ${GTK2_FIND_VERSION}")
  339. endif()
  340. _GTK2_FIND_INCLUDE_DIR(GTK2_GTK_INCLUDE_DIR gtk/gtk.h)
  341. if(GTK2_GTK_INCLUDE_DIR)
  342. _GTK2_GET_VERSION(GTK2_MAJOR_VERSION
  343. GTK2_MINOR_VERSION
  344. GTK2_PATCH_VERSION
  345. ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h)
  346. set(GTK2_VERSION
  347. ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION})
  348. if(GTK2_FIND_VERSION_EXACT)
  349. if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION)
  350. set(GTK2_FAILED_VERSION_CHECK false)
  351. endif()
  352. else()
  353. if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION OR
  354. GTK2_VERSION VERSION_GREATER GTK2_FIND_VERSION)
  355. set(GTK2_FAILED_VERSION_CHECK false)
  356. endif()
  357. endif()
  358. else()
  359. # If we can't find the GTK include dir, we can't do version checking
  360. if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY)
  361. message(FATAL_ERROR "Could not find GTK2 include directory")
  362. endif()
  363. return()
  364. endif()
  365. if(GTK2_FAILED_VERSION_CHECK)
  366. if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY)
  367. if(GTK2_FIND_VERSION_EXACT)
  368. message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, version ${GTK2_FIND_VERSION} is needed exactly.")
  369. else()
  370. message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, at least version ${GTK2_FIND_VERSION} is required")
  371. endif()
  372. endif()
  373. # If the version check fails, exit out of the module here
  374. return()
  375. endif()
  376. endif()
  377. #
  378. # Find all components
  379. #
  380. find_package(Freetype)
  381. list(APPEND GTK2_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
  382. list(APPEND GTK2_LIBRARIES ${FREETYPE_LIBRARIES})
  383. foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
  384. if(_GTK2_component STREQUAL "gtk")
  385. _GTK2_FIND_INCLUDE_DIR(GTK2_GLIB_INCLUDE_DIR glib.h)
  386. _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBCONFIG_INCLUDE_DIR glibconfig.h)
  387. _GTK2_FIND_LIBRARY (GTK2_GLIB_LIBRARY glib false true)
  388. _GTK2_FIND_INCLUDE_DIR(GTK2_GOBJECT_INCLUDE_DIR gobject/gobject.h)
  389. _GTK2_FIND_LIBRARY (GTK2_GOBJECT_LIBRARY gobject false true)
  390. _GTK2_FIND_INCLUDE_DIR(GTK2_GDK_PIXBUF_INCLUDE_DIR gdk-pixbuf/gdk-pixbuf.h)
  391. _GTK2_FIND_LIBRARY (GTK2_GDK_PIXBUF_LIBRARY gdk_pixbuf false true)
  392. _GTK2_FIND_INCLUDE_DIR(GTK2_GDK_INCLUDE_DIR gdk/gdk.h)
  393. _GTK2_FIND_INCLUDE_DIR(GTK2_GDKCONFIG_INCLUDE_DIR gdkconfig.h)
  394. _GTK2_FIND_INCLUDE_DIR(GTK2_GTK_INCLUDE_DIR gtk/gtk.h)
  395. if(UNIX)
  396. _GTK2_FIND_LIBRARY (GTK2_GDK_LIBRARY gdk-x11 false true)
  397. _GTK2_FIND_LIBRARY (GTK2_GTK_LIBRARY gtk-x11 false true)
  398. else()
  399. _GTK2_FIND_LIBRARY (GTK2_GDK_LIBRARY gdk-win32 false true)
  400. _GTK2_FIND_LIBRARY (GTK2_GTK_LIBRARY gtk-win32 false true)
  401. endif()
  402. _GTK2_FIND_INCLUDE_DIR(GTK2_CAIRO_INCLUDE_DIR cairo.h)
  403. _GTK2_FIND_LIBRARY (GTK2_CAIRO_LIBRARY cairo false false)
  404. _GTK2_FIND_INCLUDE_DIR(GTK2_FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)
  405. _GTK2_FIND_INCLUDE_DIR(GTK2_PANGO_INCLUDE_DIR pango/pango.h)
  406. _GTK2_FIND_LIBRARY (GTK2_PANGO_LIBRARY pango false true)
  407. _GTK2_FIND_INCLUDE_DIR(GTK2_ATK_INCLUDE_DIR atk/atk.h)
  408. _GTK2_FIND_LIBRARY (GTK2_ATK_LIBRARY atk false true)
  409. elseif(_GTK2_component STREQUAL "gtkmm")
  410. _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBMM_INCLUDE_DIR glibmm.h)
  411. _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBMMCONFIG_INCLUDE_DIR glibmmconfig.h)
  412. _GTK2_FIND_LIBRARY (GTK2_GLIBMM_LIBRARY glibmm true true)
  413. _GTK2_FIND_INCLUDE_DIR(GTK2_GDKMM_INCLUDE_DIR gdkmm.h)
  414. _GTK2_FIND_INCLUDE_DIR(GTK2_GDKMMCONFIG_INCLUDE_DIR gdkmmconfig.h)
  415. _GTK2_FIND_LIBRARY (GTK2_GDKMM_LIBRARY gdkmm true true)
  416. _GTK2_FIND_INCLUDE_DIR(GTK2_GTKMM_INCLUDE_DIR gtkmm.h)
  417. _GTK2_FIND_INCLUDE_DIR(GTK2_GTKMMCONFIG_INCLUDE_DIR gtkmmconfig.h)
  418. _GTK2_FIND_LIBRARY (GTK2_GTKMM_LIBRARY gtkmm true true)
  419. _GTK2_FIND_INCLUDE_DIR(GTK2_CAIROMM_INCLUDE_DIR cairomm/cairomm.h)
  420. _GTK2_FIND_LIBRARY (GTK2_CAIROMM_LIBRARY cairomm true true)
  421. _GTK2_FIND_INCLUDE_DIR(GTK2_PANGOMM_INCLUDE_DIR pangomm.h)
  422. _GTK2_FIND_INCLUDE_DIR(GTK2_PANGOMMCONFIG_INCLUDE_DIR pangommconfig.h)
  423. _GTK2_FIND_LIBRARY (GTK2_PANGOMM_LIBRARY pangomm true true)
  424. _GTK2_FIND_INCLUDE_DIR(GTK2_SIGC++_INCLUDE_DIR sigc++/sigc++.h)
  425. _GTK2_FIND_INCLUDE_DIR(GTK2_SIGC++CONFIG_INCLUDE_DIR sigc++config.h)
  426. _GTK2_FIND_LIBRARY (GTK2_SIGC++_LIBRARY sigc true true)
  427. _GTK2_FIND_INCLUDE_DIR(GTK2_GIOMM_INCLUDE_DIR giomm.h)
  428. _GTK2_FIND_INCLUDE_DIR(GTK2_GIOMMCONFIG_INCLUDE_DIR giommconfig.h)
  429. _GTK2_FIND_LIBRARY (GTK2_GIOMM_LIBRARY giomm true true)
  430. _GTK2_FIND_INCLUDE_DIR(GTK2_ATKMM_INCLUDE_DIR atkmm.h)
  431. _GTK2_FIND_LIBRARY (GTK2_ATKMM_LIBRARY atkmm true true)
  432. elseif(_GTK2_component STREQUAL "glade")
  433. _GTK2_FIND_INCLUDE_DIR(GTK2_GLADE_INCLUDE_DIR glade/glade.h)
  434. _GTK2_FIND_LIBRARY (GTK2_GLADE_LIBRARY glade false true)
  435. elseif(_GTK2_component STREQUAL "glademm")
  436. _GTK2_FIND_INCLUDE_DIR(GTK2_GLADEMM_INCLUDE_DIR libglademm.h)
  437. _GTK2_FIND_INCLUDE_DIR(GTK2_GLADEMMCONFIG_INCLUDE_DIR libglademmconfig.h)
  438. _GTK2_FIND_LIBRARY (GTK2_GLADEMM_LIBRARY glademm true true)
  439. else()
  440. message(FATAL_ERROR "Unknown GTK2 component ${_component}")
  441. endif()
  442. endforeach()
  443. #
  444. # Solve for the GTK2 version if we haven't already
  445. #
  446. if(NOT GTK2_FIND_VERSION AND GTK2_GTK_INCLUDE_DIR)
  447. _GTK2_GET_VERSION(GTK2_MAJOR_VERSION
  448. GTK2_MINOR_VERSION
  449. GTK2_PATCH_VERSION
  450. ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h)
  451. set(GTK2_VERSION ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION})
  452. endif()
  453. #
  454. # Try to enforce components
  455. #
  456. set(_GTK2_did_we_find_everything true) # This gets set to GTK2_FOUND
  457. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  458. foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
  459. string(TOUPPER ${_GTK2_component} _COMPONENT_UPPER)
  460. if(_GTK2_component STREQUAL "gtk")
  461. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtk libraries were not found."
  462. GTK2_GTK_LIBRARY
  463. GTK2_GTK_INCLUDE_DIR
  464. GTK2_GLIB_INCLUDE_DIR
  465. GTK2_GLIBCONFIG_INCLUDE_DIR
  466. GTK2_GLIB_LIBRARY
  467. GTK2_GDK_INCLUDE_DIR
  468. GTK2_GDKCONFIG_INCLUDE_DIR
  469. GTK2_GDK_LIBRARY
  470. )
  471. elseif(_GTK2_component STREQUAL "gtkmm")
  472. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtkmm libraries were not found."
  473. GTK2_GTKMM_LIBRARY
  474. GTK2_GTKMM_INCLUDE_DIR
  475. GTK2_GTKMMCONFIG_INCLUDE_DIR
  476. GTK2_GLIBMM_INCLUDE_DIR
  477. GTK2_GLIBMMCONFIG_INCLUDE_DIR
  478. GTK2_GLIBMM_LIBRARY
  479. GTK2_GDKMM_INCLUDE_DIR
  480. GTK2_GDKMMCONFIG_INCLUDE_DIR
  481. GTK2_GDKMM_LIBRARY
  482. )
  483. elseif(_GTK2_component STREQUAL "glade")
  484. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glade library was not found."
  485. GTK2_GLADE_LIBRARY
  486. GTK2_GLADE_INCLUDE_DIR
  487. )
  488. elseif(_GTK2_component STREQUAL "glademm")
  489. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glademm library was not found."
  490. GTK2_GLADEMM_LIBRARY
  491. GTK2_GLADEMM_INCLUDE_DIR
  492. GTK2_GLADEMMCONFIG_INCLUDE_DIR
  493. )
  494. endif()
  495. if(NOT GTK2_${_COMPONENT_UPPER}_FOUND)
  496. set(_GTK2_did_we_find_everything false)
  497. endif()
  498. endforeach()
  499. if(_GTK2_did_we_find_everything AND NOT GTK2_VERSION_CHECK_FAILED)
  500. set(GTK2_FOUND true)
  501. else()
  502. # Unset our variables.
  503. set(GTK2_FOUND false)
  504. set(GTK2_VERSION)
  505. set(GTK2_VERSION_MAJOR)
  506. set(GTK2_VERSION_MINOR)
  507. set(GTK2_VERSION_PATCH)
  508. set(GTK2_INCLUDE_DIRS)
  509. set(GTK2_LIBRARIES)
  510. endif()
  511. if(GTK2_INCLUDE_DIRS)
  512. list(REMOVE_DUPLICATES GTK2_INCLUDE_DIRS)
  513. endif()