summaryrefslogtreecommitdiffstats
path: root/cmake/FindGObject.cmake
blob: 19a8a678deb2920bb88caac4c742594fb01dc4ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# FindGObject
# ---------
#
# Try to locate the gobject-2.0 library.
# If found, this will define the following variables:
#
# ``GObject_FOUND``
#     True if the gobject-2.0 library is available
#
# If ``GObject_FOUND`` is TRUE, it will also define the following
# imported target:
#
# ``GObject::GObject``
#     The gobject-2.0 library

include(CMakeFindDependencyMacro)
find_dependency(GLIB2)
qt_internal_disable_find_package_global_promotion(GLIB2::GLIB2)

if(NOT TARGET GObject::GObject)
    find_package(PkgConfig QUIET)
    pkg_check_modules(PC_GOBJECT gobject-2.0 IMPORTED_TARGET)
    if (TARGET PkgConfig::PC_GOBJECT)
        add_library(GObject::GObject INTERFACE IMPORTED)
        target_link_libraries(GObject::GObject INTERFACE
                            PkgConfig::PC_GOBJECT
                            GLIB2::GLIB2
        )
    else()
        find_path(GObject_INCLUDE_DIR
            NAMES gobject.h
            PATH_SUFFIXES glib-2.0/gobject/
        )
        find_library(GObject_LIBRARY NAMES gobject-2.0)
        if (GObject_LIBRARY AND GObject_INCLUDE_DIR)
            add_library(GObject::GObject INTERFACE IMPORTED)
            target_include_directories(GObject::GObject INTERFACE
                                    ${GObject_INCLUDE_DIR}
            )
            target_link_libraries(GObject::GObject INTERFACE
                                ${GObject_LIBRARY}
                                GLIB2::GLIB2
            )
        endif()
        include(FindPackageHandleStandardArgs)
        find_package_handle_standard_args(GObject REQUIRED_VARS
                                        GObject_LIBRARY
                                        GObject_INCLUDE_DIR
    )
    endif()
endif()

if(TARGET GObject::GObject)
    set(GObject_FOUND TRUE)
endif()