2 # - Try to find the GLIB2 libraries
3 # Once done this will define
5 # GLIB2_FOUND - system has glib2
6 # GLIB2_INCLUDE_DIRS - the glib2 include directory
7 # GLIB2_LIBRARIES - glib2 library
8 # GLIB2_DLL_DIR_DEBUG - (Windows) Path to required GLib2 DLLs in debug build.
9 # GLIB2_DLL_DIR_RELEASE - (Windows) Path to required GLib2 DLLs in release builds.
10 # GLIB2_DLLS_DEBUG - (Windows) List of required GLib2 DLLs in debug builds.
11 # GLIB2_DLLS_RELEASE - (Windows) List of required GLib2 DLLs in release builds.
13 # Copyright (c) 2008 Laurent Montel, <montel@kde.org>
15 # Redistribution and use is allowed according to the terms of the BSD license.
16 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
19 if( GLIB2_MAIN_INCLUDE_DIR AND GLIB2_LIBRARIES )
20 # Already in cache, be silent
21 set( GLIB2_FIND_QUIETLY TRUE )
24 include( FindWSWinLibs )
25 FindWSWinLibs( "vcpkg-export-*" "GLIB2_HINTS" )
27 if (NOT USE_REPOSITORY)
28 find_package(PkgConfig)
29 pkg_search_module( PC_GLIB2 glib-2.0 )
32 find_path( GLIB2_MAIN_INCLUDE_DIR
36 "${PC_GLIB2_INCLUDEDIR}"
37 "${GLIB2_HINTS}/include"
49 include(FindWSLibrary)
50 FindWSLibrary( GLIB2_LIBRARY
69 # In the Windows vcpkg port glibconfig.h is in
70 # installed/$ARCH-windows/lib/glib-2.0/include.
71 set( glib2LibDir "${GLIB2_HINTS}/lib" )
73 # On UNIX and UNIX-like platforms, the glibconfig.h include dir
74 # should be in glib-2.0/include in the library directory.
75 get_filename_component( glib2LibDir "${GLIB2_LIBRARY}" PATH)
78 find_path( GLIB2_INTERNAL_INCLUDE_DIR
85 ${CMAKE_SYSTEM_LIBRARY_PATH}
91 set(GLIB2_VERSION ${PC_GLIB2_VERSION})
92 elseif(GLIB2_INTERNAL_INCLUDE_DIR)
93 # On systems without pkg-config (e.g. Windows), search its header
94 # (available since the initial commit of GLib).
95 file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MAJOR_VERSION
96 REGEX "#define[ ]+GLIB_MAJOR_VERSION[ ]+[0-9]+")
97 string(REGEX MATCH "[0-9]+" GLIB_MAJOR_VERSION ${GLIB_MAJOR_VERSION})
98 file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MINOR_VERSION
99 REGEX "#define[ ]+GLIB_MINOR_VERSION[ ]+[0-9]+")
100 string(REGEX MATCH "[0-9]+" GLIB_MINOR_VERSION ${GLIB_MINOR_VERSION})
101 file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MICRO_VERSION
102 REGEX "#define[ ]+GLIB_MICRO_VERSION[ ]+[0-9]+")
103 string(REGEX MATCH "[0-9]+" GLIB_MICRO_VERSION ${GLIB_MICRO_VERSION})
104 set(GLIB2_VERSION ${GLIB_MAJOR_VERSION}.${GLIB_MINOR_VERSION}.${GLIB_MICRO_VERSION})
106 # When using VERSION_VAR it must be set to a valid value or undefined to
107 # mean "not found". It's not enough to use the empty string or any other CMake false boolean.
111 include( FindPackageHandleStandardArgs )
112 find_package_handle_standard_args( GLIB2
113 REQUIRED_VARS GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR
114 VERSION_VAR GLIB2_VERSION
118 set( GLIB2_LIBRARIES ${GLIB2_LIBRARY} )
119 # Include transitive dependencies for static linking.
120 if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a")
121 find_library(PCRE_LIBRARY pcre)
122 list(APPEND GLIB2_LIBRARIES -pthread ${PCRE_LIBRARY})
124 set( GLIB2_INCLUDE_DIRS ${GLIB2_MAIN_INCLUDE_DIR} ${GLIB2_INTERNAL_INCLUDE_DIR} )
125 if ( USE_REPOSITORY AND GLIB2_FOUND )
126 set ( GLIB2_DLL_DIR_RELEASE "${GLIB2_HINTS}/bin"
127 CACHE PATH "Path to GLib2 release DLLs"
129 set ( GLIB2_DLL_DIR_DEBUG "${GLIB2_HINTS}/debug/bin"
130 CACHE PATH "Path to GLib2 debug DLLs"
133 # GTK+ required GObject and GIO. We probably don't.
134 file( GLOB _glib2_dlls_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
135 # "${GLIB2_DLL_DIR_RELEASE}/gio-2.0-0.dll"
136 "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.dll"
137 "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.dll"
138 # "${GLIB2_DLL_DIR_RELEASE}/gobject-2.0-0.dll"
139 "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.dll"
140 "${GLIB2_DLL_DIR_RELEASE}/charset-1.dll"
141 # gnutls-3.6.3-1-win64ws ships with libffi-6.dll
142 # "${GLIB2_DLL_DIR_RELEASE}/libffi.dll"
143 "${GLIB2_DLL_DIR_RELEASE}/iconv-2.dll"
144 "${GLIB2_DLL_DIR_RELEASE}/intl-8.dll"
146 set ( GLIB2_DLLS_RELEASE ${_glib2_dlls_release}
147 # We're storing filenames only. Should we use STRING instead?
148 CACHE FILEPATH "GLib 2 release DLL list"
150 file( GLOB _glib2_dlls_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
151 # "${GLIB2_DLL_DIR_DEBUG}/gio-2.0-0.dll"
152 "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.dll"
153 "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.dll"
154 # "${GLIB2_DLL_DIR_DEBUG}/gobject-2.0-0.dll"
155 "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.dll"
156 "${GLIB2_DLL_DIR_DEBUG}/charset-1.dll"
157 # gnutls-3.6.3-1-win64ws ships with libffi-6.dll
158 # "${GLIB2_DLL_DIR_DEBUG}/libffi.dll"
159 "${GLIB2_DLL_DIR_DEBUG}/iconv-2.dll"
160 "${GLIB2_DLL_DIR_DEBUG}/intl-8.dll"
162 set ( GLIB2_DLLS_DEBUG ${_glib2_dlls_debug}
163 # We're storing filenames only. Should we use STRING instead?
164 CACHE FILEPATH "GLib 2 debug DLL list"
167 file( GLOB _glib2_pdbs_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
168 "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.pdb"
169 "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.pdb"
170 "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.pdb"
171 # "${GLIB2_DLL_DIR_RELEASE}/libcharset.pdb"
172 # "${GLIB2_DLL_DIR_RELEASE}/libiconv.pdb"
173 # "${GLIB2_DLL_DIR_RELEASE}/libintl.pdb"
175 set ( GLIB2_PDBS_RELEASE ${_glib2_pdbs_release}
176 CACHE FILEPATH "GLib2 debug release PDB list"
178 file( GLOB _glib2_pdbs_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
179 "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.pdb"
180 "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.pdb"
181 "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.pdb"
182 # "${GLIB2_DLL_DIR_DEBUG}/libcharset.pdb"
183 # "${GLIB2_DLL_DIR_DEBUG}/libiconv.pdb"
184 # "${GLIB2_DLL_DIR_DEBUG}/libintl.pdb"
186 set ( GLIB2_PDBS_DEBUG ${_glib2_pdbs_debug}
187 CACHE FILEPATH "GLib2 debug debug PDB list"
190 mark_as_advanced( GLIB2_DLL_DIR_RELEASE GLIB2_DLLS_RELEASE GLIB2_PDBS_RELEASE )
191 mark_as_advanced( GLIB2_DLL_DIR_DEBUG GLIB2_DLLS_DEBUG GLIB2_PDBS_DEBUG )
193 elseif( GLIB2_FIND_REQUIRED )
194 message( SEND_ERROR "Package required but not found" )
196 set( GLIB2_LIBRARIES )
197 set( GLIB2_MAIN_INCLUDE_DIRS )
198 set( GLIB2_DLL_DIR_RELEASE )
199 set( GLIB2_DLL_DIR_DEBUG )
200 set( GLIB2_PDBS_RELEASE )
201 set( GLIB2_PDBS_DEBUG )
205 mark_as_advanced( GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES )