tools/pidl/lib/Parse/Pidl/Wireshark/NDR.pm subcontext 32 bits
[wireshark-sm.git] / cmake / modules / FindGLIB2.cmake
blobae38d2cda168701c0b475be0fa9a5244dfe07297
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 )
22 endif()
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 )
30 endif()
32 find_path( GLIB2_MAIN_INCLUDE_DIR
33         NAMES
34                 glib.h
35         HINTS
36                 "${PC_GLIB2_INCLUDEDIR}"
37                 "${GLIB2_HINTS}/include"
38         PATH_SUFFIXES
39                 glib-2.0
40                 glib-2.0/include
41         PATHS
42                 /opt/gnome/include
43                 /opt/local/include
44                 /sw/include
45                 /usr/include
46                 /usr/local/include
49 include(FindWSLibrary)
50 FindWSLibrary( GLIB2_LIBRARY
51         NAMES
52                 glib-2.0
53                 libglib-2.0
54         HINTS
55                 "${PC_GLIB2_LIBDIR}"
56         WIN32_HINTS
57             ${GLIB2_HINTS}
58         PATHS
59                 /opt/gnome/lib64
60                 /opt/gnome/lib
61                 /opt/lib/
62                 /opt/local/lib
63                 /sw/lib/
64                 /usr/lib64
65                 /usr/lib
68 if (USE_REPOSITORY)
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" )
72 else()
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)
76 endif()
78 find_path( GLIB2_INTERNAL_INCLUDE_DIR
79         NAMES
80                 glibconfig.h
81         HINTS
82                 "${PC_GLIB2_LIBDIR}"
83                 "${glib2LibDir}"
84                 "${GLIB2_INCLUDEDIR}"
85                 ${CMAKE_SYSTEM_LIBRARY_PATH}
86         PATH_SUFFIXES
87                 glib-2.0/include
90 if(PC_GLIB2_VERSION)
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})
105 else()
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.
108         unset(GLIB2_VERSION)
109 endif()
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
117 if( GLIB2_FOUND )
118         set( GLIB2_LIBRARIES ${GLIB2_LIBRARY} )
119         # Include transitive dependencies for static linking.
120         if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a")
121                 if(PC_GLIB2_FOUND)
122                         set(GLIB2_LIBRARIES ${PC_GLIB2_STATIC_LIBRARIES})
123                         # -pthread appears in LDFLAGS_OTHER
124                         list(APPEND GLIB2_LIBRARIES ${PC_GLIB2_STATIC_LDFLAGS_OTHER})
125                 elseif(GLIB2_VERSION VERSION_GREATER_EQUAL "2.73.2")
126                         find_library(PCRE2_LIBRARY pcre2-8)
127                         list(APPEND GLIB2_LIBRARIES -pthread ${PCRE2_LIBRARY})
128                 else()
129                         find_library(PCRE_LIBRARY pcre)
130                         list(APPEND GLIB2_LIBRARIES -pthread ${PCRE_LIBRARY})
131                 endif()
132         endif()
133         set( GLIB2_INCLUDE_DIRS ${GLIB2_MAIN_INCLUDE_DIR} ${GLIB2_INTERNAL_INCLUDE_DIR} )
134         if ( USE_REPOSITORY AND GLIB2_FOUND )
135                 set ( GLIB2_DLL_DIR_RELEASE "${GLIB2_HINTS}/bin"
136                         CACHE PATH "Path to GLib2 release DLLs"
137                 )
138                 set ( GLIB2_DLL_DIR_DEBUG "${GLIB2_HINTS}/debug/bin"
139                         CACHE PATH "Path to GLib2 debug DLLs"
140                 )
142                 # GTK+ required GObject and GIO. We probably don't.
143                 file( GLOB _glib2_dlls_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
144                         # "${GLIB2_DLL_DIR_RELEASE}/gio-2.0-0.dll"
145                         "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.dll"
146                         "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.dll"
147                         # "${GLIB2_DLL_DIR_RELEASE}/gobject-2.0-0.dll"
148                         "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.dll"
149                         "${GLIB2_DLL_DIR_RELEASE}/charset-1.dll"
150                         # gnutls-3.6.3-1-win64ws ships with libffi-6.dll
151                         # "${GLIB2_DLL_DIR_RELEASE}/libffi.dll"
152                         "${GLIB2_DLL_DIR_RELEASE}/iconv-2.dll"
153                         "${GLIB2_DLL_DIR_RELEASE}/intl-8.dll"
154                 )
155                 set ( GLIB2_DLLS_RELEASE ${_glib2_dlls_release}
156                         # We're storing filenames only. Should we use STRING instead?
157                         CACHE FILEPATH "GLib 2 release DLL list"
158                 )
159                 file( GLOB _glib2_dlls_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
160                         # "${GLIB2_DLL_DIR_DEBUG}/gio-2.0-0.dll"
161                         "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.dll"
162                         "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.dll"
163                         # "${GLIB2_DLL_DIR_DEBUG}/gobject-2.0-0.dll"
164                         "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.dll"
165                         "${GLIB2_DLL_DIR_DEBUG}/charset-1.dll"
166                         # gnutls-3.6.3-1-win64ws ships with libffi-6.dll
167                         # "${GLIB2_DLL_DIR_DEBUG}/libffi.dll"
168                         "${GLIB2_DLL_DIR_DEBUG}/iconv-2.dll"
169                         "${GLIB2_DLL_DIR_DEBUG}/intl-8.dll"
170                 )
171                 set ( GLIB2_DLLS_DEBUG ${_glib2_dlls_debug}
172                         # We're storing filenames only. Should we use STRING instead?
173                         CACHE FILEPATH "GLib 2 debug DLL list"
174                 )
176                 file( GLOB _glib2_pdbs_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
177                         "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.pdb"
178                         "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.pdb"
179                         "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.pdb"
180                         # "${GLIB2_DLL_DIR_RELEASE}/libcharset.pdb"
181                         # "${GLIB2_DLL_DIR_RELEASE}/libiconv.pdb"
182                         # "${GLIB2_DLL_DIR_RELEASE}/libintl.pdb"
183                 )
184                 set ( GLIB2_PDBS_RELEASE ${_glib2_pdbs_release}
185                         CACHE FILEPATH "GLib2 debug release PDB list"
186                 )
187                 file( GLOB _glib2_pdbs_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
188                         "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.pdb"
189                         "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.pdb"
190                         "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.pdb"
191                         # "${GLIB2_DLL_DIR_DEBUG}/libcharset.pdb"
192                         # "${GLIB2_DLL_DIR_DEBUG}/libiconv.pdb"
193                         # "${GLIB2_DLL_DIR_DEBUG}/libintl.pdb"
194                 )
195                 set ( GLIB2_PDBS_DEBUG ${_glib2_pdbs_debug}
196                         CACHE FILEPATH "GLib2 debug debug PDB list"
197                 )
199                 mark_as_advanced( GLIB2_DLL_DIR_RELEASE GLIB2_DLLS_RELEASE GLIB2_PDBS_RELEASE )
200                 mark_as_advanced( GLIB2_DLL_DIR_DEBUG GLIB2_DLLS_DEBUG GLIB2_PDBS_DEBUG )
201         endif()
202 elseif( GLIB2_FIND_REQUIRED )
203         message( SEND_ERROR "Package required but not found" )
204 else()
205         set( GLIB2_LIBRARIES )
206         set( GLIB2_MAIN_INCLUDE_DIRS )
207         set( GLIB2_DLL_DIR_RELEASE )
208         set( GLIB2_DLL_DIR_DEBUG )
209         set( GLIB2_PDBS_RELEASE )
210         set( GLIB2_PDBS_DEBUG )
211         set( GLIB2_DLLS )
212 endif()
214 mark_as_advanced( GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES )