FindGTK2
Note
This module is intended specifically for GTK version 2.x, which is obsolete and no longer maintained. Use the latest supported GTK version and FindPkgConfig module to find GTK in CMake instead of this module. For example:
find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk4>=4.14) target_link_libraries(example PRIVATE PkgConfig::GTK)
Finds the GTK widget libraries and several of its other optional components:
find_package(GTK2 [<version>] [COMPONENTS <components>...] [...])
GTK is a multi-platform toolkit for creating graphical user interfaces.
Components
This module supports optional components, which can be specified with the find_package() command:
find_package(GTK2 [COMPONENTS <components>...])
Supported components include:
|
|
-
Added in version 3.16.7:
harfbuzz
If no components are specified, module by default searches for the gtk component.
Imported Targets
This module provides the following Imported Targets (subject to component selection):
-
GTK2::<component> -
Target encapsulating the specified GTK component usage requirements, available if GTK and this component are found. The
<component>should be written in the same case, as listed above. For example, useGTK2::gtkfor thegtkcomponent, orGTK2::gdk_pixbuffor thegdk_pixbufcomponent, etc. -
GTK2::sigc++ -
Added in version 3.5.
Target encapsulating the usage requirements to enable c++11 on its dependents when using sigc++ 2.5.1 or higher. This target is automatically applied to dependent targets as needed.
Result Variables
This module defines the following variables:
-
GTK2_FOUND -
Boolean indicating whether (the requested version of) GTK 2 and all specified components were found.
-
GTK2_VERSION -
The version of GTK found (x.y.z).
-
GTK2_MAJOR_VERSION -
The major version of GTK found.
-
GTK2_MINOR_VERSION -
The minor version of GTK found.
-
GTK2_PATCH_VERSION -
The patch version of GTK found.
-
GTK2_INCLUDE_DIRS -
Include directories containing headers needed to use GTK.
-
GTK2_LIBRARIES -
Libraries needed to link against to use GTK.
-
GTK2_TARGETS -
Added in version 3.5.
A list of all defined imported targets.
-
GTK2_DEFINITIONS -
Additional compiler flags needed to use GTK.
Input Variables
This module accepts the following optional variables before calling the find_package(GTK2):
-
GTK2_DEBUG -
Boolean variable that enables verbose debugging output of this module.
-
GTK2_ADDITIONAL_SUFFIXES -
A list of additional path suffixes to search for include files.
-
GTK2_USE_IMPORTED_TARGETS -
Added in version 3.5.
When this variable is set to boolean true,
GTK2_LIBRARIESvariable will contain a list imported targets instead of library paths.
Examples
Examples: Finding GTK version 2
Call find_package() once. Here are some examples to pick from.
Require GTK 2.6 or later:
find_package(GTK2 2.6 REQUIRED COMPONENTS gtk)
Require GTK 2.10 or later and its Glade component:
find_package(GTK2 2.10 REQUIRED COMPONENTS gtk glade)
Search for GTK/GTKMM 2.8 or later:
find_package(GTK2 2.8 COMPONENTS gtk gtkmm)
Finding GTK 2 and linking it to a project target:
find_package(GTK2) add_executable(mygui mygui.cc) target_link_libraries(mygui PRIVATE GTK2::gtk)
Examples: Finding GTK version 3 or later
Finding GTK 3 with FindPkgConfig instead of this module:
find_package(PkgConfig REQUIRED) pkg_check_modules(GTK3 REQUIRED IMPORTED_TARGET gtk+-3.0>=3.14) target_link_libraries(example PRIVATE PkgConfig::GTK3)
Or similarly to find GTK 4:
find_package(PkgConfig REQUIRED) pkg_check_modules(GTK4 REQUIRED IMPORTED_TARGET gtk4>=4.14) target_link_libraries(example PRIVATE PkgConfig::GTK4)
© 2000–2026 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/latest/module/FindGTK2.html