aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindGLIB2.cmake
blob: 46bede9ec5f8ff14bd37a58af6f219b8a43c4e9d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#
# - Try to find the GLIB2 libraries
# Once done this will define
#
#  GLIB2_FOUND           - system has glib2
#  GLIB2_INCLUDE_DIRS    - the glib2 include directory
#  GLIB2_LIBRARIES       - glib2 library
#  GLIB2_DLL_DIR_DEBUG   - (Windows) Path to required GLib2 DLLs in debug build.
#  GLIB2_DLL_DIR_RELEASE - (Windows) Path to required GLib2 DLLs in release builds.
#  GLIB2_DLLS_DEBUG      - (Windows) List of required GLib2 DLLs in debug builds.
#  GLIB2_DLLS_RELEASE    - (Windows) List of required GLib2 DLLs in release builds.

# Copyright (c) 2008 Laurent Montel, <montel@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.


if( GLIB2_MAIN_INCLUDE_DIR AND GLIB2_LIBRARIES )
	# Already in cache, be silent
	set( GLIB2_FIND_QUIETLY TRUE )
endif()

include( FindWSWinLibs )
FindWSWinLibs( "vcpkg-export-*" "GLIB2_HINTS" )

if (NOT WIN32)
	find_package(PkgConfig)
	pkg_search_module( PC_GLIB2 glib-2.0 )
endif()

find_path( GLIB2_MAIN_INCLUDE_DIR
	NAMES
		glib.h
	HINTS
		"${PC_GLIB2_INCLUDEDIR}"
		"${GLIB2_HINTS}/include"
	PATH_SUFFIXES
		glib-2.0
		glib-2.0/include
	PATHS
		/opt/gnome/include
		/opt/local/include
		/sw/include
		/usr/include
		/usr/local/include
)

include(FindWSLibrary)
FindWSLibrary( GLIB2_LIBRARY
	NAMES
		glib-2.0
		libglib-2.0
	HINTS
		"${PC_GLIB2_LIBDIR}"
	WIN32_HINTS
	    ${GLIB2_HINTS}
	PATHS
		/opt/gnome/lib64
		/opt/gnome/lib
		/opt/lib/
		/opt/local/lib
		/sw/lib/
		/usr/lib64
		/usr/lib
)

# search the glibconfig.h include dir under the same root where the library is found
get_filename_component( glib2LibDir "${GLIB2_LIBRARY}" PATH)

find_path( GLIB2_INTERNAL_INCLUDE_DIR
	NAMES
		glibconfig.h
	HINTS
		"${GLIB2_INCLUDEDIR}"
		"${GLIB2_HINTS}/include"
		"${glib2LibDir}"
		${CMAKE_SYSTEM_LIBRARY_PATH}
	PATH_SUFFIXES
		glib-2.0/include
	PATHS
		${GLIB2_LIBRARY}

)

if(PC_GLIB2_VERSION)
	set(GLIB2_VERSION ${PC_GLIB2_VERSION})
elseif(GLIB2_INTERNAL_INCLUDE_DIR)
	# On systems without pkg-config (e.g. Windows), search its header
	# (available since the initial commit of GLib).
	file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MAJOR_VERSION
		REGEX "#define[ ]+GLIB_MAJOR_VERSION[ ]+[0-9]+")
	string(REGEX MATCH "[0-9]+" GLIB_MAJOR_VERSION ${GLIB_MAJOR_VERSION})
	file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MINOR_VERSION
		REGEX "#define[ ]+GLIB_MINOR_VERSION[ ]+[0-9]+")
	string(REGEX MATCH "[0-9]+" GLIB_MINOR_VERSION ${GLIB_MINOR_VERSION})
	file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MICRO_VERSION
		REGEX "#define[ ]+GLIB_MICRO_VERSION[ ]+[0-9]+")
	string(REGEX MATCH "[0-9]+" GLIB_MICRO_VERSION ${GLIB_MICRO_VERSION})
	set(GLIB2_VERSION ${GLIB_MAJOR_VERSION}.${GLIB_MINOR_VERSION}.${GLIB_MICRO_VERSION})
else()
	set(GLIB2_VERSION "")
endif()

include( FindPackageHandleStandardArgs )
find_package_handle_standard_args( GLIB2
	REQUIRED_VARS   GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR
	VERSION_VAR     GLIB2_VERSION
)

if( GLIB2_FOUND )
	set( GLIB2_LIBRARIES ${GLIB2_LIBRARY} )
	# Include transitive dependencies for static linking.
	if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a")
		find_library(PCRE_LIBRARY pcre)
		list(APPEND GLIB2_LIBRARIES -pthread ${PCRE_LIBRARY})
	endif()
	set( GLIB2_INCLUDE_DIRS ${GLIB2_MAIN_INCLUDE_DIR} ${GLIB2_INTERNAL_INCLUDE_DIR} )
	if ( WIN32 AND GLIB2_FOUND )
		set ( GLIB2_DLL_DIR_RELEASE "${GLIB2_HINTS}/bin"
			CACHE PATH "Path to GLib2 release DLLs"
		)
		set ( GLIB2_DLL_DIR_DEBUG "${GLIB2_HINTS}/debug/bin"
			CACHE PATH "Path to GLib2 debug DLLs"
		)

		# GTK+ required GObject and GIO. We probably don't.
		file( GLOB _glib2_dlls_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
			# "${GLIB2_DLL_DIR_RELEASE}/gio-2.dll"
			"${GLIB2_DLL_DIR_RELEASE}/glib-2.dll"
			"${GLIB2_DLL_DIR_RELEASE}/gmodule-2.dll"
			# "${GLIB2_DLL_DIR_RELEASE}/gobject-2.dll"
			"${GLIB2_DLL_DIR_RELEASE}/gthread-2.dll"
			"${GLIB2_DLL_DIR_RELEASE}/libcharset.dll"
			# gnutls-3.6.3-1-win64ws ships with libffi-6.dll
			# "${GLIB2_DLL_DIR_RELEASE}/libffi.dll"
			"${GLIB2_DLL_DIR_RELEASE}/libiconv.dll"
			"${GLIB2_DLL_DIR_RELEASE}/libintl.dll"
			"${GLIB2_DLL_DIR_RELEASE}/pcre.dll"
			# "${GLIB2_DLL_DIR_RELEASE}/pcre16.dll"
			# "${GLIB2_DLL_DIR_RELEASE}/pcre32.dll"
			# "${GLIB2_DLL_DIR_RELEASE}/pcrecpp.dll"
			# "${GLIB2_DLL_DIR_RELEASE}/pcreposix.dll"
		)
		set ( GLIB2_DLLS_RELEASE ${_glib2_dlls_release}
			# We're storing filenames only. Should we use STRING instead?
			CACHE FILEPATH "GLib 2 release DLL list"
		)
		file( GLOB _glib2_dlls_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
			# "${GLIB2_DLL_DIR_DEBUG}/gio-2.dll"
			"${GLIB2_DLL_DIR_DEBUG}/glib-2.dll"
			"${GLIB2_DLL_DIR_DEBUG}/gmodule-2.dll"
			# "${GLIB2_DLL_DIR_DEBUG}/gobject-2.dll"
			"${GLIB2_DLL_DIR_DEBUG}/gthread-2.dll"
			"${GLIB2_DLL_DIR_DEBUG}/libcharset.dll"
			# gnutls-3.6.3-1-win64ws ships with libffi-6.dll
			# "${GLIB2_DLL_DIR_DEBUG}/libffi.dll"
			"${GLIB2_DLL_DIR_DEBUG}/libiconv.dll"
			"${GLIB2_DLL_DIR_DEBUG}/libintl.dll"
			"${GLIB2_DLL_DIR_DEBUG}/pcred.dll"
			# "${GLIB2_DLL_DIR_DEBUG}/pcre16d.dll"
			# "${GLIB2_DLL_DIR_DEBUG}/pcre32d.dll"
			# "${GLIB2_DLL_DIR_DEBUG}/pcrecppd.dll"
			# "${GLIB2_DLL_DIR_DEBUG}/pcreposixd.dll"
		)
		set ( GLIB2_DLLS_DEBUG ${_glib2_dlls_debug}
			# We're storing filenames only. Should we use STRING instead?
			CACHE FILEPATH "GLib 2 debug DLL list"
		)

		file( GLOB _glib2_pdbs_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
			"${GLIB2_DLL_DIR_RELEASE}/glib-2.pdb"
			"${GLIB2_DLL_DIR_RELEASE}/gmodule-2.pdb"
			"${GLIB2_DLL_DIR_RELEASE}/gthread-2.pdb"
			"${GLIB2_DLL_DIR_RELEASE}/libcharset.pdb"
			"${GLIB2_DLL_DIR_RELEASE}/libiconv.pdb"
			"${GLIB2_DLL_DIR_RELEASE}/libintl.pdb"
			"${GLIB2_DLL_DIR_RELEASE}/pcre.pdb"
		)
		set ( GLIB2_PDBS_RELEASE ${_glib2_pdbs_release}
			CACHE FILEPATH "GLib2 debug release PDB list"
		)
		file( GLOB _glib2_pdbs_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
			"${GLIB2_DLL_DIR_DEBUG}/glib-2.pdb"
			"${GLIB2_DLL_DIR_DEBUG}/gmodule-2.pdb"
			"${GLIB2_DLL_DIR_DEBUG}/gthread-2.pdb"
			"${GLIB2_DLL_DIR_DEBUG}/libcharset.pdb"
			"${GLIB2_DLL_DIR_DEBUG}/libiconv.pdb"
			"${GLIB2_DLL_DIR_DEBUG}/libintl.pdb"
			"${GLIB2_DLL_DIR_DEBUG}/pcred.pdb"
		)
		set ( GLIB2_PDBS_DEBUG ${_glib2_pdbs_debug}
			CACHE FILEPATH "GLib2 debug debug PDB list"
		)

		mark_as_advanced( GLIB2_DLL_DIR_RELEASE GLIB2_DLLS_RELEASE GLIB2_PDBS_RELEASE )
		mark_as_advanced( GLIB2_DLL_DIR_DEBUG GLIB2_DLLS_DEBUG GLIB2_PDBS_DEBUG )
	endif()
elseif( GLIB2_FIND_REQUIRED )
	message( SEND_ERROR "Package required but not found" )
else()
	set( GLIB2_LIBRARIES )
	set( GLIB2_MAIN_INCLUDE_DIRS )
	set( GLIB2_DLL_DIR_RELEASE )
	set( GLIB2_DLL_DIR_DEBUG )
	set( GLIB2_PDBS_RELEASE )
	set( GLIB2_PDBS_DEBUG )
	set( GLIB2_DLLS )
endif()

mark_as_advanced( GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES )