1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find the GTK2 widget libraries and several of its other optional components
9 like ``gtkmm``, ``glade``, and ``glademm``.
11 Specify one or more of the following components as you call this find
12 module. See example below.
22 This module defines the following :prop_tgt:`IMPORTED` targets (subject to
25 ``GTK2::atk``, ``GTK2::atkmm``, ``GTK2::cairo``, ``GTK2::cairomm``,
26 ``GTK2::gdk_pixbuf``, ``GTK2::gdk``, ``GTK2::gdkmm``, ``GTK2::gio``,
27 ``GTK2::giomm``, ``GTK2::glade``, ``GTK2::glademm``, ``GTK2::glib``,
28 ``GTK2::glibmm``, ``GTK2::gmodule``, ``GTK2::gobject``, ``GTK2::gthread``,
29 ``GTK2::gtk``, ``GTK2::gtkmm``, ``GTK2::harfbuzz``, ``GTK2::pango``,
30 ``GTK2::pangocairo``, ``GTK2::pangoft2``, ``GTK2::pangomm``,
31 ``GTK2::pangoxft``, ``GTK2::sigc``.
33 .. versionadded:: 3.16.7
34 Added the ``GTK2::harfbuzz`` target.
39 The following variables will be defined for your use
42 Were all of your specified components found?
44 All include directories
51 Additional compiler flags
53 The version of GTK2 found (x.y.z)
54 ``GTK2_MAJOR_VERSION``
55 The major version of GTK2
56 ``GTK2_MINOR_VERSION``
57 The minor version of GTK2
58 ``GTK2_PATCH_VERSION``
59 The patch version of GTK2
62 When ``GTK2_USE_IMPORTED_TARGETS`` is set to ``TRUE``, ``GTK2_LIBRARIES``
63 will list imported targets instead of library paths.
68 Optional variables you can define prior to calling this module:
71 Enables verbose debugging of the module
72 ``GTK2_ADDITIONAL_SUFFIXES``
73 Allows defining additional directories to search for include files
78 Call :command:`find_package` once. Here are some examples to pick from:
80 Require GTK 2.6 or later:
84 find_package(GTK2 2.6 REQUIRED gtk)
86 Require GTK 2.10 or later and Glade:
90 find_package(GTK2 2.10 REQUIRED gtk glade)
92 Search for GTK/GTKMM 2.8 or later:
96 find_package(GTK2 2.8 COMPONENTS gtk gtkmm)
100 .. code-block:: cmake
103 include_directories(${GTK2_INCLUDE_DIRS})
104 add_executable(mygui mygui.cc)
105 target_link_libraries(mygui ${GTK2_LIBRARIES})
107 #]=======================================================================]
109 # Version 1.6 (CMake 3.0)
110 # * Create targets for each library
111 # * Do not link libfreetype
112 # Version 1.5 (CMake 2.8.12)
113 # * 14236: Detect gthread library
114 # Detect pangocairo on windows
115 # Detect pangocairo with gtk module instead of with gtkmm
116 # * 14259: Use vc100 libraries with VS 11
117 # * 14260: Export a GTK2_DEFINITIONS variable to set /vd2 when appropriate
119 # * Use the optimized/debug syntax for _LIBRARY and _LIBRARIES variables when
120 # appropriate. A new set of _RELEASE variables was also added.
121 # * Remove GTK2_SKIP_MARK_AS_ADVANCED option, as now the variables are
122 # marked as advanced by SelectLibraryConfigurations
123 # * Detect gmodule, pangoft2 and pangoxft libraries
124 # Version 1.4 (10/4/2012) (CMake 2.8.10)
125 # * 12596: Missing paths for FindGTK2 on NetBSD
126 # * 12049: Fixed detection of GTK include files in the lib folder on
128 # Version 1.3 (11/9/2010) (CMake 2.8.4)
129 # * 11429: Add support for detecting GTK2 built with Visual Studio 10.
130 # Thanks to Vincent Levesque for the patch.
131 # Version 1.2 (8/30/2010) (CMake 2.8.3)
132 # * Merge patch for detecting gdk-pixbuf library (split off
133 # from core GTK in 2.21). Thanks to Vincent Untz for the patch
134 # and Ricardo Cruz for the heads up.
135 # Version 1.1 (8/19/2010) (CMake 2.8.3)
136 # * Add support for detecting GTK2 under macports (thanks to Gary Kramlich)
137 # Version 1.0 (8/12/2010) (CMake 2.8.3)
138 # * Add support for detecting new pangommconfig.h header file
139 # (Thanks to Sune Vuorela & the Debian Project for the patch)
140 # * Add support for detecting fontconfig.h header
141 # * Call find_package(Freetype) since it's required
142 # * Add support for allowing users to add additional library directories
143 # via the GTK2_ADDITIONAL_SUFFIXES variable (kind of a future-kludge in
144 # case the GTK developers change versions on any of the directories in the
146 # Version 0.8 (1/4/2010)
147 # * Get module working under MacOSX fink by adding /sw/include, /sw/lib
148 # to PATHS and the gobject library
149 # Version 0.7 (3/22/09)
150 # * Checked into CMake CVS
151 # * Added versioning support
152 # * Module now defaults to searching for GTK if COMPONENTS not specified.
153 # * Added HKCU prior to HKLM registry key and GTKMM specific environment
154 # variable as per mailing list discussion.
155 # * Added lib64 to include search path and a few other search paths where GTK
156 # may be installed on Unix systems.
157 # * Switched to lowercase CMake commands
158 # * Prefaced internal variables with _GTK2 to prevent collision
159 # * Changed internal macros to functions
160 # * Enhanced documentation
161 # Version 0.6 (1/8/08)
162 # Added GTK2_SKIP_MARK_AS_ADVANCED option
163 # Version 0.5 (12/19/08)
164 # Second release to cmake mailing list
166 #=============================================================
168 # Internal function to parse the version number in gtkversion.h
169 # _OUT_major = Major version number
170 # _OUT_minor = Minor version number
171 # _OUT_micro = Micro version number
172 # _gtkversion_hdr = Header file to parse
173 #=============================================================
175 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
177 function(_GTK2_GET_VERSION _OUT_major _OUT_minor _OUT_micro _gtkversion_hdr)
179 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
180 file(STRINGS ${_gtkversion_hdr} _contents REGEX "#define GTK_M[A-Z]+_VERSION[ \t]+")
183 string(REGEX REPLACE ".*#define GTK_MAJOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_major} "${_contents}")
184 string(REGEX REPLACE ".*#define GTK_MINOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_minor} "${_contents}")
185 string(REGEX REPLACE ".*#define GTK_MICRO_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_micro} "${_contents}")
187 if(NOT ${_OUT_major} MATCHES "[0-9]+")
188 message(FATAL_ERROR "Version parsing failed for GTK2_MAJOR_VERSION!")
190 if(NOT ${_OUT_minor} MATCHES "[0-9]+")
191 message(FATAL_ERROR "Version parsing failed for GTK2_MINOR_VERSION!")
193 if(NOT ${_OUT_micro} MATCHES "[0-9]+")
194 message(FATAL_ERROR "Version parsing failed for GTK2_MICRO_VERSION!")
197 set(${_OUT_major} ${${_OUT_major}} PARENT_SCOPE)
198 set(${_OUT_minor} ${${_OUT_minor}} PARENT_SCOPE)
199 set(${_OUT_micro} ${${_OUT_micro}} PARENT_SCOPE)
201 message(FATAL_ERROR "Include file ${_gtkversion_hdr} does not exist")
206 #=============================================================
207 # _GTK2_SIGCXX_GET_VERSION
208 # Internal function to parse the version number in
210 # _OUT_major = Major version number
211 # _OUT_minor = Minor version number
212 # _OUT_micro = Micro version number
213 # _sigcxxversion_hdr = Header file to parse
214 #=============================================================
216 function(_GTK2_SIGCXX_GET_VERSION _OUT_major _OUT_minor _OUT_micro _sigcxxversion_hdr)
218 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
219 file(STRINGS ${_sigcxxversion_hdr} _contents REGEX "#define SIGCXX_M[A-Z]+_VERSION[ \t]+")
222 string(REGEX REPLACE ".*#define SIGCXX_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" ${_OUT_major} "${_contents}")
223 string(REGEX REPLACE ".*#define SIGCXX_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" ${_OUT_minor} "${_contents}")
224 string(REGEX REPLACE ".*#define SIGCXX_MICRO_VERSION[ \t]+([0-9]+).*" "\\1" ${_OUT_micro} "${_contents}")
226 if(NOT ${_OUT_major} MATCHES "[0-9]+")
227 message(FATAL_ERROR "Version parsing failed for SIGCXX_MAJOR_VERSION!")
229 if(NOT ${_OUT_minor} MATCHES "[0-9]+")
230 message(FATAL_ERROR "Version parsing failed for SIGCXX_MINOR_VERSION!")
232 if(NOT ${_OUT_micro} MATCHES "[0-9]+")
233 message(FATAL_ERROR "Version parsing failed for SIGCXX_MICRO_VERSION!")
236 set(${_OUT_major} ${${_OUT_major}} PARENT_SCOPE)
237 set(${_OUT_minor} ${${_OUT_minor}} PARENT_SCOPE)
238 set(${_OUT_micro} ${${_OUT_micro}} PARENT_SCOPE)
240 # The header does not have the version macros; assume it is ``0.0.0``.
248 #=============================================================
249 # _GTK2_FIND_INCLUDE_DIR
250 # Internal function to find the GTK include directories
251 # _var = variable to set (_INCLUDE_DIR is appended)
252 # _hdr = header file to look for
253 #=============================================================
254 function(_GTK2_FIND_INCLUDE_DIR _var _hdr)
257 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
258 "_GTK2_FIND_INCLUDE_DIR( ${_var} ${_hdr} )")
262 # If these ever change, things will break.
263 ${GTK2_ADDITIONAL_SUFFIXES}
284 # NOTE: The following suffixes cause searching for header files in both of
287 # /usr/lib/<pkg>/include
291 foreach(_d ${_gtk_packages})
292 list(APPEND _suffixes ${_d})
293 list(APPEND _suffixes ${_d}/include) # for /usr/lib/gtk-2.0/include
297 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
298 "include suffixes = ${_suffixes}")
301 if(CMAKE_LIBRARY_ARCHITECTURE)
302 set(_gtk2_arch_dir /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE})
304 message(STATUS "Adding ${_gtk2_arch_dir} to search path for multiarch support")
307 find_path(GTK2_${_var}_INCLUDE_DIR ${_hdr}
324 /usr/pkg/include/glib
325 $ENV{GTKMM_BASEPATH}/include
326 $ENV{GTKMM_BASEPATH}/lib
327 [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/include
328 [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
329 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/include
330 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
334 mark_as_advanced(GTK2_${_var}_INCLUDE_DIR)
336 if(GTK2_${_var}_INCLUDE_DIR)
337 set(GTK2_INCLUDE_DIRS ${GTK2_INCLUDE_DIRS} ${GTK2_${_var}_INCLUDE_DIR} PARENT_SCOPE)
342 #=============================================================
344 # Internal function to find libraries packaged with GTK2
345 # _var = library variable to create (_LIBRARY is appended)
346 #=============================================================
347 function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version)
350 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
351 "_GTK2_FIND_LIBRARY( ${_var} ${_lib} ${_expand_vc} ${_append_version} )")
354 # Not GTK versions per se but the versions encoded into Windows
355 # import libraries (GtkMM 2.14.1 has a gtkmm-vc80-2_4.lib for example)
356 # Also the MSVC libraries use _ for . (this is handled below)
357 set(_versions 2.20 2.18 2.16 2.14 2.12
358 2.10 2.8 2.6 2.4 2.2 2.0
359 1.20 1.18 1.16 1.14 1.12
360 1.10 1.8 1.6 1.4 1.2 1.0)
365 set(_library ${_lib})
367 if(_expand_vc AND MSVC)
368 # Add vc80/vc90/vc100 midfixes
369 if(MSVC_TOOLSET_VERSION LESS 110)
370 set(_library ${_library}-vc${MSVC_TOOLSET_VERSION})
372 # Up to gtkmm-win 2.22.0-2 there are no vc110 libraries but vc100 can be used
373 set(_library ${_library}-vc100)
375 set(_library_d ${_library}-d)
379 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
380 "After midfix addition = ${_library} and ${_library_d}")
386 foreach(_ver ${_versions})
387 list(APPEND _lib_list "${_library}-${_ver}")
388 list(APPEND _libd_list "${_library_d}-${_ver}")
391 set(_lib_list ${_library})
392 set(_libd_list ${_library_d})
396 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
397 "library list = ${_lib_list} and library debug list = ${_libd_list}")
400 # For some silly reason the MSVC libraries use _ instead of .
401 # in the version fields
402 if(_expand_vc AND MSVC)
403 set(_no_dots_lib_list)
404 set(_no_dots_libd_list)
405 foreach(_l ${_lib_list})
406 string(REPLACE "." "_" _no_dots_library ${_l})
407 list(APPEND _no_dots_lib_list ${_no_dots_library})
410 set(_no_dots_libsd_list)
411 foreach(_l ${_libd_list})
412 string(REPLACE "." "_" _no_dots_libraryd ${_l})
413 list(APPEND _no_dots_libd_list ${_no_dots_libraryd})
416 # Copy list back to original names
417 set(_lib_list ${_no_dots_lib_list})
418 set(_libd_list ${_no_dots_libd_list})
422 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
423 "While searching for GTK2_${_var}_LIBRARY, our proposed library list is ${_lib_list}")
426 find_library(GTK2_${_var}_LIBRARY_RELEASE
431 $ENV{GTKMM_BASEPATH}/lib
432 [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
433 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
436 if(_expand_vc AND MSVC)
438 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
439 "While searching for GTK2_${_var}_LIBRARY_DEBUG our proposed library list is ${_libd_list}")
442 find_library(GTK2_${_var}_LIBRARY_DEBUG
445 $ENV{GTKMM_BASEPATH}/lib
446 [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib
447 [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib
451 select_library_configurations(GTK2_${_var})
453 set(GTK2_${_var}_LIBRARY ${GTK2_${_var}_LIBRARY} PARENT_SCOPE)
454 set(GTK2_${_var}_FOUND ${GTK2_${_var}_FOUND} PARENT_SCOPE)
456 if(GTK2_${_var}_FOUND)
457 set(GTK2_LIBRARIES ${GTK2_LIBRARIES} ${GTK2_${_var}_LIBRARY})
458 set(GTK2_LIBRARIES ${GTK2_LIBRARIES} PARENT_SCOPE)
462 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
463 "GTK2_${_var}_LIBRARY_RELEASE = \"${GTK2_${_var}_LIBRARY_RELEASE}\"")
464 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
465 "GTK2_${_var}_LIBRARY_DEBUG = \"${GTK2_${_var}_LIBRARY_DEBUG}\"")
466 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
467 "GTK2_${_var}_LIBRARY = \"${GTK2_${_var}_LIBRARY}\"")
468 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
469 "GTK2_${_var}_FOUND = \"${GTK2_${_var}_FOUND}\"")
475 function(_GTK2_ADD_TARGET_DEPENDS_INTERNAL _var _property)
477 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
478 "_GTK2_ADD_TARGET_DEPENDS_INTERNAL( ${_var} ${_property} )")
481 string(TOLOWER "${_var}" _basename)
483 if (TARGET GTK2::${_basename})
484 foreach(_depend ${ARGN})
486 if (TARGET GTK2::${_depend})
487 list(APPEND _valid_depends GTK2::${_depend})
490 set_property(TARGET GTK2::${_basename} APPEND PROPERTY ${_property} "${_valid_depends}")
497 function(_GTK2_ADD_TARGET_DEPENDS _var)
499 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
500 "_GTK2_ADD_TARGET_DEPENDS( ${_var} )")
503 string(TOLOWER "${_var}" _basename)
505 if(TARGET GTK2::${_basename})
506 get_target_property(_configs GTK2::${_basename} IMPORTED_CONFIGURATIONS)
507 _GTK2_ADD_TARGET_DEPENDS_INTERNAL(${_var} INTERFACE_LINK_LIBRARIES ${ARGN})
508 foreach(_config ${_configs})
509 _GTK2_ADD_TARGET_DEPENDS_INTERNAL(${_var} IMPORTED_LINK_INTERFACE_LIBRARIES_${_config} ${ARGN})
514 function(_GTK2_ADD_TARGET_INCLUDE_DIRS _var)
516 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
517 "_GTK2_ADD_TARGET_INCLUDE_DIRS( ${_var} )")
520 string(TOLOWER "${_var}" _basename)
522 if(TARGET GTK2::${_basename})
523 foreach(_include ${ARGN})
524 set_property(TARGET GTK2::${_basename} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${_include}")
529 #=============================================================
531 # Internal function to create targets for GTK2
532 # _var = target to create
533 #=============================================================
534 function(_GTK2_ADD_TARGET _var)
536 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
537 "_GTK2_ADD_TARGET( ${_var} )")
540 string(TOLOWER "${_var}" _basename)
542 cmake_parse_arguments(_${_var} "" "" "GTK2_DEPENDS;GTK2_OPTIONAL_DEPENDS;OPTIONAL_INCLUDES" ${ARGN})
544 if(GTK2_${_var}_FOUND)
545 if(NOT TARGET GTK2::${_basename})
546 # Do not create the target if dependencies are missing
547 foreach(_dep ${_${_var}_GTK2_DEPENDS})
548 if(NOT TARGET GTK2::${_dep})
553 add_library(GTK2::${_basename} UNKNOWN IMPORTED)
555 if(GTK2_${_var}_LIBRARY_RELEASE)
556 set_property(TARGET GTK2::${_basename} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
557 set_property(TARGET GTK2::${_basename} PROPERTY IMPORTED_LOCATION_RELEASE "${GTK2_${_var}_LIBRARY_RELEASE}" )
560 if(GTK2_${_var}_LIBRARY_DEBUG)
561 set_property(TARGET GTK2::${_basename} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
562 set_property(TARGET GTK2::${_basename} PROPERTY IMPORTED_LOCATION_DEBUG "${GTK2_${_var}_LIBRARY_DEBUG}" )
565 if(GTK2_${_var}_INCLUDE_DIR)
566 set_property(TARGET GTK2::${_basename} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GTK2_${_var}_INCLUDE_DIR}")
569 if(GTK2_${_var}CONFIG_INCLUDE_DIR AND NOT "x${GTK2_${_var}CONFIG_INCLUDE_DIR}" STREQUAL "x${GTK2_${_var}_INCLUDE_DIR}")
570 set_property(TARGET GTK2::${_basename} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${GTK2_${_var}CONFIG_INCLUDE_DIR}")
574 set_property(TARGET GTK2::${_basename} PROPERTY INTERFACE_COMPILE_DEFINITIONS "${GTK2_DEFINITIONS}")
577 if(_${_var}_GTK2_DEPENDS)
578 _GTK2_ADD_TARGET_DEPENDS(${_var} ${_${_var}_GTK2_DEPENDS} ${_${_var}_GTK2_OPTIONAL_DEPENDS})
581 if(_${_var}_OPTIONAL_INCLUDES)
582 foreach(_D ${_${_var}_OPTIONAL_INCLUDES})
584 _GTK2_ADD_TARGET_INCLUDE_DIRS(${_var} ${_D})
590 set(GTK2_TARGETS ${GTK2_TARGETS} GTK2::${_basename})
591 set(GTK2_TARGETS ${GTK2_TARGETS} PARENT_SCOPE)
593 if(GTK2_USE_IMPORTED_TARGETS)
594 set(GTK2_${_var}_LIBRARY GTK2::${_basename} PARENT_SCOPE)
602 #=============================================================
609 set(GTK2_INCLUDE_DIRS)
612 set(GTK2_DEFINITIONS)
614 if(NOT GTK2_FIND_COMPONENTS)
615 # Assume they only want GTK
616 set(GTK2_FIND_COMPONENTS gtk)
620 # If specified, enforce version number
622 if(GTK2_FIND_VERSION)
623 set(GTK2_FAILED_VERSION_CHECK true)
625 message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] "
626 "Searching for version ${GTK2_FIND_VERSION}")
628 _GTK2_FIND_INCLUDE_DIR(GTK gtk/gtk.h)
629 if(GTK2_GTK_INCLUDE_DIR)
630 _GTK2_GET_VERSION(GTK2_MAJOR_VERSION
633 ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h)
635 ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION})
636 if(GTK2_FIND_VERSION_EXACT)
637 if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION)
638 set(GTK2_FAILED_VERSION_CHECK false)
641 if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION OR
642 GTK2_VERSION VERSION_GREATER GTK2_FIND_VERSION)
643 set(GTK2_FAILED_VERSION_CHECK false)
647 # If we can't find the GTK include dir, we can't do version checking
648 if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY)
649 message(FATAL_ERROR "Could not find GTK2 include directory")
654 if(GTK2_FAILED_VERSION_CHECK)
655 if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY)
656 if(GTK2_FIND_VERSION_EXACT)
657 message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, version ${GTK2_FIND_VERSION} is needed exactly.")
659 message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, at least version ${GTK2_FIND_VERSION} is required")
663 # If the version check fails, exit out of the module here
669 # On MSVC, according to https://wiki.gnome.org/gtkmm/MSWindows, the /vd2 flag needs to be
670 # passed to the compiler in order to use gtkmm
673 foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
674 if(_GTK2_component STREQUAL "gtkmm")
675 set(GTK2_DEFINITIONS "/vd2")
676 elseif(_GTK2_component STREQUAL "glademm")
677 set(GTK2_DEFINITIONS "/vd2")
683 # Find all components
686 find_package(Freetype QUIET)
687 if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2)
688 list(APPEND GTK2_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2})
691 foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
692 if(_GTK2_component STREQUAL "gtk")
693 # Left for compatibility with previous versions.
694 _GTK2_FIND_INCLUDE_DIR(FONTCONFIG fontconfig/fontconfig.h)
695 _GTK2_FIND_INCLUDE_DIR(X11 X11/Xlib.h)
697 _GTK2_FIND_INCLUDE_DIR(GLIB glib.h)
698 _GTK2_FIND_INCLUDE_DIR(GLIBCONFIG glibconfig.h)
699 _GTK2_FIND_LIBRARY (GLIB glib false true)
700 _GTK2_ADD_TARGET (GLIB)
702 _GTK2_FIND_INCLUDE_DIR(GOBJECT glib-object.h)
703 _GTK2_FIND_LIBRARY (GOBJECT gobject false true)
704 _GTK2_ADD_TARGET (GOBJECT GTK2_DEPENDS glib)
706 _GTK2_FIND_INCLUDE_DIR(ATK atk/atk.h)
707 _GTK2_FIND_LIBRARY (ATK atk false true)
708 _GTK2_ADD_TARGET (ATK GTK2_DEPENDS gobject glib)
710 _GTK2_FIND_LIBRARY (GIO gio false true)
711 _GTK2_ADD_TARGET (GIO GTK2_DEPENDS gobject glib)
713 _GTK2_FIND_LIBRARY (GTHREAD gthread false true)
714 _GTK2_ADD_TARGET (GTHREAD GTK2_DEPENDS glib)
716 _GTK2_FIND_LIBRARY (GMODULE gmodule false true)
717 _GTK2_ADD_TARGET (GMODULE GTK2_DEPENDS glib)
719 _GTK2_FIND_INCLUDE_DIR(GDK_PIXBUF gdk-pixbuf/gdk-pixbuf.h)
720 _GTK2_FIND_LIBRARY (GDK_PIXBUF gdk_pixbuf false true)
721 _GTK2_ADD_TARGET (GDK_PIXBUF GTK2_DEPENDS gobject glib)
723 _GTK2_FIND_INCLUDE_DIR(CAIRO cairo.h)
724 _GTK2_FIND_LIBRARY (CAIRO cairo false false)
725 _GTK2_ADD_TARGET (CAIRO)
727 _GTK2_FIND_INCLUDE_DIR(HARFBUZZ hb.h)
728 _GTK2_FIND_LIBRARY (HARFBUZZ harfbuzz false false)
729 _GTK2_ADD_TARGET (HARFBUZZ)
731 _GTK2_FIND_INCLUDE_DIR(PANGO pango/pango.h)
732 _GTK2_FIND_LIBRARY (PANGO pango false true)
733 _GTK2_ADD_TARGET (PANGO GTK2_DEPENDS gobject glib
734 GTK2_OPTIONAL_DEPENDS harfbuzz)
736 _GTK2_FIND_LIBRARY (PANGOCAIRO pangocairo false true)
737 _GTK2_ADD_TARGET (PANGOCAIRO GTK2_DEPENDS pango cairo gobject glib)
739 _GTK2_FIND_LIBRARY (PANGOFT2 pangoft2 false true)
740 _GTK2_ADD_TARGET (PANGOFT2 GTK2_DEPENDS pango gobject glib
741 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
742 ${GTK2_FONTCONFIG_INCLUDE_DIR}
743 ${GTK2_X11_INCLUDE_DIR})
745 _GTK2_FIND_LIBRARY (PANGOXFT pangoxft false true)
746 _GTK2_ADD_TARGET (PANGOXFT GTK2_DEPENDS pangoft2 pango gobject glib
747 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
748 ${GTK2_FONTCONFIG_INCLUDE_DIR}
749 ${GTK2_X11_INCLUDE_DIR})
751 _GTK2_FIND_INCLUDE_DIR(GDK gdk/gdk.h)
752 _GTK2_FIND_INCLUDE_DIR(GDKCONFIG gdkconfig.h)
755 _GTK2_FIND_LIBRARY (GDK gdk-quartz false true)
757 _GTK2_FIND_LIBRARY (GDK gdk-x11 false true)
759 _GTK2_FIND_LIBRARY (GDK gdk-win32 false true)
761 _GTK2_ADD_TARGET (GDK GTK2_DEPENDS pango gdk_pixbuf gobject glib
762 GTK2_OPTIONAL_DEPENDS pangocairo cairo)
764 _GTK2_FIND_INCLUDE_DIR(GTK gtk/gtk.h)
767 _GTK2_FIND_LIBRARY (GTK gtk-quartz false true)
769 _GTK2_FIND_LIBRARY (GTK gtk-x11 false true)
771 _GTK2_FIND_LIBRARY (GTK gtk-win32 false true)
773 _GTK2_ADD_TARGET (GTK GTK2_DEPENDS gdk atk pangoft2 pango gdk_pixbuf gthread gobject glib
774 GTK2_OPTIONAL_DEPENDS gio pangocairo cairo)
776 elseif(_GTK2_component STREQUAL "gtkmm")
778 _GTK2_FIND_INCLUDE_DIR(SIGC++ sigc++/sigc++.h)
779 _GTK2_FIND_INCLUDE_DIR(SIGC++CONFIG sigc++config.h)
780 _GTK2_FIND_LIBRARY (SIGC++ sigc true true)
781 _GTK2_ADD_TARGET (SIGC++)
782 # Since sigc++ 2.5.1 c++11 support is required
783 if(GTK2_SIGC++CONFIG_INCLUDE_DIR)
784 _GTK2_SIGCXX_GET_VERSION(GTK2_SIGC++_VERSION_MAJOR
785 GTK2_SIGC++_VERSION_MINOR
786 GTK2_SIGC++_VERSION_MICRO
787 ${GTK2_SIGC++CONFIG_INCLUDE_DIR}/sigc++config.h)
788 if(NOT ${GTK2_SIGC++_VERSION_MAJOR}.${GTK2_SIGC++_VERSION_MINOR}.${GTK2_SIGC++_VERSION_MICRO} VERSION_LESS 2.5.1)
789 # These are the features needed by clients in order to include the
791 set_property(TARGET GTK2::sigc++
792 PROPERTY INTERFACE_COMPILE_FEATURES cxx_alias_templates
795 cxx_deleted_functions
798 cxx_right_angle_brackets
799 cxx_rvalue_references
800 cxx_variadic_templates)
804 _GTK2_FIND_INCLUDE_DIR(GLIBMM glibmm.h)
805 _GTK2_FIND_INCLUDE_DIR(GLIBMMCONFIG glibmmconfig.h)
806 _GTK2_FIND_LIBRARY (GLIBMM glibmm true true)
807 _GTK2_ADD_TARGET (GLIBMM GTK2_DEPENDS gobject sigc++ glib)
809 _GTK2_FIND_INCLUDE_DIR(GIOMM giomm.h)
810 _GTK2_FIND_INCLUDE_DIR(GIOMMCONFIG giommconfig.h)
811 _GTK2_FIND_LIBRARY (GIOMM giomm true true)
812 _GTK2_ADD_TARGET (GIOMM GTK2_DEPENDS gio glibmm gobject sigc++ glib)
814 _GTK2_FIND_INCLUDE_DIR(ATKMM atkmm.h)
815 _GTK2_FIND_INCLUDE_DIR(ATKMMCONFIG atkmmconfig.h)
816 _GTK2_FIND_LIBRARY (ATKMM atkmm true true)
817 _GTK2_ADD_TARGET (ATKMM GTK2_DEPENDS atk glibmm gobject sigc++ glib)
819 _GTK2_FIND_INCLUDE_DIR(CAIROMM cairomm/cairomm.h)
820 _GTK2_FIND_INCLUDE_DIR(CAIROMMCONFIG cairommconfig.h)
821 _GTK2_FIND_LIBRARY (CAIROMM cairomm true true)
822 _GTK2_ADD_TARGET (CAIROMM GTK2_DEPENDS cairo sigc++
823 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
824 ${GTK2_FONTCONFIG_INCLUDE_DIR}
825 ${GTK2_X11_INCLUDE_DIR})
827 _GTK2_FIND_INCLUDE_DIR(PANGOMM pangomm.h)
828 _GTK2_FIND_INCLUDE_DIR(PANGOMMCONFIG pangommconfig.h)
829 _GTK2_FIND_LIBRARY (PANGOMM pangomm true true)
830 _GTK2_ADD_TARGET (PANGOMM GTK2_DEPENDS glibmm sigc++ pango gobject glib
831 GTK2_OPTIONAL_DEPENDS cairomm pangocairo cairo
832 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
833 ${GTK2_FONTCONFIG_INCLUDE_DIR}
834 ${GTK2_X11_INCLUDE_DIR})
836 _GTK2_FIND_INCLUDE_DIR(GDKMM gdkmm.h)
837 _GTK2_FIND_INCLUDE_DIR(GDKMMCONFIG gdkmmconfig.h)
838 _GTK2_FIND_LIBRARY (GDKMM gdkmm true true)
839 _GTK2_ADD_TARGET (GDKMM GTK2_DEPENDS pangomm gtk glibmm sigc++ gdk atk pangoft2 gdk_pixbuf pango gobject glib
840 GTK2_OPTIONAL_DEPENDS giomm cairomm gio pangocairo cairo
841 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
842 ${GTK2_FONTCONFIG_INCLUDE_DIR}
843 ${GTK2_X11_INCLUDE_DIR})
845 _GTK2_FIND_INCLUDE_DIR(GTKMM gtkmm.h)
846 _GTK2_FIND_INCLUDE_DIR(GTKMMCONFIG gtkmmconfig.h)
847 _GTK2_FIND_LIBRARY (GTKMM gtkmm true true)
848 _GTK2_ADD_TARGET (GTKMM GTK2_DEPENDS atkmm gdkmm pangomm gtk glibmm sigc++ gdk atk pangoft2 gdk_pixbuf pango gthread gobject glib
849 GTK2_OPTIONAL_DEPENDS giomm cairomm gio pangocairo cairo
850 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
851 ${GTK2_FONTCONFIG_INCLUDE_DIR}
852 ${GTK2_X11_INCLUDE_DIR})
854 elseif(_GTK2_component STREQUAL "glade")
856 _GTK2_FIND_INCLUDE_DIR(GLADE glade/glade.h)
857 _GTK2_FIND_LIBRARY (GLADE glade false true)
858 _GTK2_ADD_TARGET (GLADE GTK2_DEPENDS gtk gdk atk gio pangoft2 gdk_pixbuf pango gobject glib
859 GTK2_OPTIONAL_DEPENDS pangocairo cairo
860 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
861 ${GTK2_FONTCONFIG_INCLUDE_DIR}
862 ${GTK2_X11_INCLUDE_DIR})
864 elseif(_GTK2_component STREQUAL "glademm")
866 _GTK2_FIND_INCLUDE_DIR(GLADEMM libglademm.h)
867 _GTK2_FIND_INCLUDE_DIR(GLADEMMCONFIG libglademmconfig.h)
868 _GTK2_FIND_LIBRARY (GLADEMM glademm true true)
869 _GTK2_ADD_TARGET (GLADEMM GTK2_DEPENDS gtkmm glade atkmm gdkmm giomm pangomm glibmm sigc++ gtk gdk atk pangoft2 gdk_pixbuf pango gthread gobject glib
870 GTK2_OPTIONAL_DEPENDS giomm cairomm gio pangocairo cairo
871 OPTIONAL_INCLUDES ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}
872 ${GTK2_FONTCONFIG_INCLUDE_DIR}
873 ${GTK2_X11_INCLUDE_DIR})
876 message(FATAL_ERROR "Unknown GTK2 component ${_component}")
881 # Solve for the GTK2 version if we haven't already
883 if(NOT GTK2_FIND_VERSION AND GTK2_GTK_INCLUDE_DIR)
884 _GTK2_GET_VERSION(GTK2_MAJOR_VERSION
887 ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h)
888 set(GTK2_VERSION ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION})
892 # Try to enforce components
895 set(_GTK2_did_we_find_everything true) # This gets set to GTK2_FOUND
897 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
899 foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
900 string(TOUPPER ${_GTK2_component} _COMPONENT_UPPER)
902 set(GTK2_${_COMPONENT_UPPER}_FIND_QUIETLY ${GTK2_FIND_QUIETLY})
904 set(FPHSA_NAME_MISMATCHED 1)
905 if(_GTK2_component STREQUAL "gtk")
906 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtk libraries were not found."
911 GTK2_GDKCONFIG_INCLUDE_DIR
914 GTK2_GLIB_INCLUDE_DIR
915 GTK2_GLIBCONFIG_INCLUDE_DIR
918 elseif(_GTK2_component STREQUAL "gtkmm")
919 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtkmm libraries were not found."
921 GTK2_GTKMM_INCLUDE_DIR
922 GTK2_GTKMMCONFIG_INCLUDE_DIR
924 GTK2_GDKMM_INCLUDE_DIR
925 GTK2_GDKMMCONFIG_INCLUDE_DIR
928 GTK2_GLIBMM_INCLUDE_DIR
929 GTK2_GLIBMMCONFIG_INCLUDE_DIR
932 FREETYPE_INCLUDE_DIR_ft2build
933 FREETYPE_INCLUDE_DIR_freetype2
935 elseif(_GTK2_component STREQUAL "glade")
936 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glade library was not found."
938 GTK2_GLADE_INCLUDE_DIR
940 elseif(_GTK2_component STREQUAL "glademm")
941 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glademm library was not found."
943 GTK2_GLADEMM_INCLUDE_DIR
944 GTK2_GLADEMMCONFIG_INCLUDE_DIR
947 unset(FPHSA_NAME_MISMATCHED)
949 if(NOT GTK2_${_COMPONENT_UPPER}_FOUND)
950 set(_GTK2_did_we_find_everything false)
954 if(GTK2_USE_IMPORTED_TARGETS)
955 set(GTK2_LIBRARIES ${GTK2_TARGETS})
959 if(_GTK2_did_we_find_everything AND NOT GTK2_VERSION_CHECK_FAILED)
962 # Unset our variables.
963 set(GTK2_FOUND false)
965 set(GTK2_VERSION_MAJOR)
966 set(GTK2_VERSION_MINOR)
967 set(GTK2_VERSION_PATCH)
968 set(GTK2_INCLUDE_DIRS)
971 set(GTK2_DEFINITIONS)
974 if(GTK2_INCLUDE_DIRS)
975 list(REMOVE_DUPLICATES GTK2_INCLUDE_DIRS)