1 # - Try to find Glib and its components (gio, gobject etc)
2 # Once done, this will define
4 # GLIB_FOUND - system has Glib
5 # GLIB_INCLUDE_DIRS - the Glib include directories
6 # GLIB_LIBRARIES - link these to use Glib
8 # Optionally, the COMPONENTS keyword can be passed to FIND_PACKAGE()
9 # and Glib components can be looked for. Currently, the following
10 # components can be used, and they define the following variables if
13 # gio: GLIB_GIO_LIBRARIES
14 # gobject: GLIB_GOBJECT_LIBRARIES
15 # gmodule: GLIB_GMODULE_LIBRARIES
16 # gthread: GLIB_GTHREAD_LIBRARIES
18 # Note that the respective _INCLUDE_DIR variables are not set, since
19 # all headers are in the same directory as GLIB_INCLUDE_DIRS.
21 # Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
23 # Redistribution and use in source and binary forms, with or without
24 # modification, are permitted provided that the following conditions
26 # 1. Redistributions of source code must retain the above copyright
27 # notice, this list of conditions and the following disclaimer.
28 # 2. Redistributions in binary form must reproduce the above copyright
29 # notice, this list of conditions and the following disclaimer in the
30 # documentation and/or other materials provided with the distribution.
32 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
33 # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
34 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
36 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
39 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
41 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
42 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 FIND_PACKAGE(PkgConfig)
45 PKG_CHECK_MODULES(PC_GLIB QUIET glib-2.0)
47 FIND_LIBRARY(GLIB_LIBRARIES
49 HINTS ${PC_GLIB_LIBDIR}
50 ${PC_GLIB_LIBRARY_DIRS}
53 # Files in glib's main include path may include glibconfig.h, which,
54 # for some odd reason, is normally in $LIBDIR/glib-2.0/include.
55 GET_FILENAME_COMPONENT(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH)
56 FIND_PATH(GLIBCONFIG_INCLUDE_DIR
58 HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR}
59 PATH_SUFFIXES glib-2.0/include
62 FIND_PATH(GLIB_INCLUDE_DIR
64 HINTS ${PC_GLIB_INCLUDEDIR}
65 ${PC_GLIB_INCLUDE_DIRS}
66 PATH_SUFFIXES glib-2.0
69 SET(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR})
72 FILE(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS)
73 STRING(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
74 SET(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}")
75 STRING(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
76 SET(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}")
77 STRING(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
78 SET(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}")
79 SET(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}")
81 # Additional Glib components. We only look for libraries, as not all of them
82 # have corresponding headers and all headers are installed alongside the main
84 FOREACH (_component ${GLIB_FIND_COMPONENTS})
85 IF (${_component} STREQUAL "gio")
86 FIND_LIBRARY(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR})
87 SET(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES)
88 ELSEIF (${_component} STREQUAL "gobject")
89 FIND_LIBRARY(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR})
90 SET(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES)
91 ELSEIF (${_component} STREQUAL "gmodule")
92 FIND_LIBRARY(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR})
93 SET(ADDITIONAL_REQUIRED_VARS "${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES")
94 ELSEIF (${_component} STREQUAL "gthread")
95 FIND_LIBRARY(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR})
96 SET(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES)
100 INCLUDE(FindPackageHandleStandardArgs)
101 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS}
102 VERSION_VAR GLIB_VERSION)